Add boot up system control

Checks if the "B" button is being held down when begin() is called.
If so, waits for other buttons to be pressed to control system functions.
Functions implemented:
 "UP" button: Set "sound enabled" in EEPROM.
 "DOWN" button: Set "sound disabled" (mute) in EEPROM.
This commit is contained in:
Scott Allen 2016-06-13 14:21:45 -04:00
parent 107cb2befd
commit e2458e6645
3 changed files with 56 additions and 4 deletions

View File

@ -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);

View File

@ -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];
};

View File

@ -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