Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ezWindow: no default font #9

Open
vkichline opened this issue Nov 10, 2020 · 0 comments
Open

ezWindow: no default font #9

vkichline opened this issue Nov 10, 2020 · 0 comments

Comments

@vkichline
Copy link

Haven't dug deep yet, but it's clear you have to be careful to set certain values before using windows.
I have a window w/ spriteBuffer. When I receive a key from a CardKB board attached to PortA, I update the window.
If I did not set the window's font in setup, I get a crash when I process a keystroke.
Ideally, there should be safe, reasonable defaults for required values (or return an error rather than crashing.)

Probably not necessary, but the full program is below. Note the line containing // Comment out this line, you will crash when a key arrives

/*
    A small editor using the CardKB I2C expansion card w/ Core2
*/
#include <M5Core2.h>
#include <Core2ez.h>

#define CARDKB_ADDR 0x5F

String    input;
ezWindow  display(20, 60, 280, 64);


void update_display() {
  display.fillScreen(BLACK);
  display.drawString(input, 0, 0);
  display.push();
}


void process_key(char c) {
  switch(c) {
    // TBD: Handle CR, BS, etc. as special cases
    default:
      input += c;
      update_display();
  }
}


void setup() {
  ez.begin();
  Wire1.begin(32, 33);
  display.spriteBuffer();
  ez.Screen.add(display);
  ez.Screen.focus();

  ez.Screen.fillScreen(BLACK);
  ez.Screen.setTextColor(YELLOW, BLACK);
  ez.Screen.setTextSize(1);
  ez.Screen.drawCentreString("Input text with CardKB", 160, 4, 4);
  display.setTextDatum(TL_DATUM);
  display.setTextPadding(0);
  display.ezFont(FSSB12);       // Comment out this line, you will crash when a key arrives
  display.setTextColor(YELLOW);
  display.fillScreen(BLACK);
  display.push();
}


void loop() {
  Wire1.requestFrom(CARDKB_ADDR, 1);
  while(Wire1.available()) {
    char c = Wire1.read(); // receive a byte as character
    if (c != 0) process_key(c);
  }
  delay(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant