diff --git a/src/Arduboy2.cpp b/src/Arduboy2.cpp index 6fbb637..84aee16 100644 --- a/src/Arduboy2.cpp +++ b/src/Arduboy2.cpp @@ -31,11 +31,16 @@ void Arduboy2Base::begin() { boot(); // raw hardware + blank(); // blank the display + // utils if(pressed(UP_BUTTON)) { flashlight(); } + // check for and handle buttons held during start up for system control + systemButtons(); + bootLogo(); audio.begin(); @@ -44,7 +49,6 @@ void Arduboy2Base::begin() void Arduboy2Base::flashlight() { // sendLCDCommand(OLED_ALL_PIXELS_ON); // smaller than allPixelsOn() - blank(); setRGBled(255,255,255); while(!pressed(DOWN_BUTTON)) { idle(); @@ -52,6 +56,30 @@ void Arduboy2Base::flashlight() setRGBled(0,0,0); } +void Arduboy2Base::systemButtons() { + while (pressed(B_BUTTON)) { + digitalWrite(BLUE_LED, LOW); // turn on blue LED + sysCtrlSound(UP_BUTTON + B_BUTTON, GREEN_LED, 0xff); + sysCtrlSound(DOWN_BUTTON + B_BUTTON, RED_LED, 0); + delay(200); + } + + digitalWrite(BLUE_LED, HIGH); // turn off blue LED +} + +void Arduboy2Base::sysCtrlSound(uint8_t buttons, uint8_t led, uint8_t eeVal) { + if (pressed(buttons)) { + digitalWrite(BLUE_LED, HIGH); // turn off blue LED + delay(200); + digitalWrite(led, LOW); // turn on "acknowledge" LED + EEPROM.update(EEPROM_AUDIO_ON_OFF, eeVal); + delay(500); + digitalWrite(led, HIGH); // turn off "acknowledge" LED + + while (pressed(buttons)) {} // Wait for button release + } +} + void Arduboy2Base::bootLogo() { // setRGBled(10,0,0); diff --git a/src/Arduboy2.h b/src/Arduboy2.h index 7f51361..747e1cc 100644 --- a/src/Arduboy2.h +++ b/src/Arduboy2.h @@ -72,9 +72,6 @@ public: void begin(); void start() __attribute__((deprecated, warning("use begin() instead"))); - /// Scrolls in the Arduboy logo - void bootLogo(); - /// Flashlight mode /** * Hold up key when booting to enable, press down key to exit @@ -84,6 +81,20 @@ public: */ void flashlight(); + /// Handle buttons held on startup for system control + /** + * Hold the B button when booting to enter system control mode. + * The B button must be held continuously to remain in this mode. + * Pressing other buttons will perform system control functions: + * + * UP: Set "sound enabled" in EEPROM + * DOWN: Set "sound disabled" (mute) in EEPROM + */ + void systemButtons(); + + /// Scrolls in the Arduboy logo + void bootLogo(); + /// Clears display. void clear(); void clearDisplay() __attribute__((deprecated, warning("use clear() instead"))); @@ -200,6 +211,9 @@ public: uint16_t rawADC(byte adc_bits); protected: + // helper function for sound enable/disable system control + void sysCtrlSound(uint8_t buttons, uint8_t led, uint8_t eeVal); + unsigned char sBuffer[(HEIGHT*WIDTH)/8]; }; diff --git a/src/core/core.cpp b/src/core/core.cpp index 56280ce..7380f0b 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -13,6 +13,16 @@ const uint8_t PROGMEM pinBootProgram[] = { PIN_A_BUTTON, INPUT_PULLUP, PIN_B_BUTTON, INPUT_PULLUP, + // RGB LED (or single blue LED on the DevKit) +#ifdef ARDUBOY_10 + RED_LED, INPUT_PULLUP, // set INPUT_PULLUP to make the pin high when + RED_LED, OUTPUT, // set to OUTPUT + GREEN_LED, INPUT_PULLUP, + GREEN_LED, OUTPUT, +#endif + BLUE_LED, INPUT_PULLUP, + BLUE_LED, OUTPUT, + // audio is specifically not included here as those pins are handled // separately by `audio.begin()`, `audio.on()` and `audio.off()` in order // to respect the EEPROM audio settings