mirror of https://github.com/MLXXXp/Arduboy2.git
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:
parent
107cb2befd
commit
e2458e6645
|
@ -31,11 +31,16 @@ void Arduboy2Base::begin()
|
||||||
{
|
{
|
||||||
boot(); // raw hardware
|
boot(); // raw hardware
|
||||||
|
|
||||||
|
blank(); // blank the display
|
||||||
|
|
||||||
// utils
|
// utils
|
||||||
if(pressed(UP_BUTTON)) {
|
if(pressed(UP_BUTTON)) {
|
||||||
flashlight();
|
flashlight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check for and handle buttons held during start up for system control
|
||||||
|
systemButtons();
|
||||||
|
|
||||||
bootLogo();
|
bootLogo();
|
||||||
|
|
||||||
audio.begin();
|
audio.begin();
|
||||||
|
@ -44,7 +49,6 @@ void Arduboy2Base::begin()
|
||||||
void Arduboy2Base::flashlight()
|
void Arduboy2Base::flashlight()
|
||||||
{
|
{
|
||||||
// sendLCDCommand(OLED_ALL_PIXELS_ON); // smaller than allPixelsOn()
|
// sendLCDCommand(OLED_ALL_PIXELS_ON); // smaller than allPixelsOn()
|
||||||
blank();
|
|
||||||
setRGBled(255,255,255);
|
setRGBled(255,255,255);
|
||||||
while(!pressed(DOWN_BUTTON)) {
|
while(!pressed(DOWN_BUTTON)) {
|
||||||
idle();
|
idle();
|
||||||
|
@ -52,6 +56,30 @@ void Arduboy2Base::flashlight()
|
||||||
setRGBled(0,0,0);
|
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()
|
void Arduboy2Base::bootLogo()
|
||||||
{
|
{
|
||||||
// setRGBled(10,0,0);
|
// setRGBled(10,0,0);
|
||||||
|
|
|
@ -72,9 +72,6 @@ public:
|
||||||
void begin();
|
void begin();
|
||||||
void start() __attribute__((deprecated, warning("use begin() instead")));
|
void start() __attribute__((deprecated, warning("use begin() instead")));
|
||||||
|
|
||||||
/// Scrolls in the Arduboy logo
|
|
||||||
void bootLogo();
|
|
||||||
|
|
||||||
/// Flashlight mode
|
/// Flashlight mode
|
||||||
/**
|
/**
|
||||||
* Hold up key when booting to enable, press down key to exit
|
* Hold up key when booting to enable, press down key to exit
|
||||||
|
@ -84,6 +81,20 @@ public:
|
||||||
*/
|
*/
|
||||||
void flashlight();
|
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.
|
/// Clears display.
|
||||||
void clear();
|
void clear();
|
||||||
void clearDisplay() __attribute__((deprecated, warning("use clear() instead")));
|
void clearDisplay() __attribute__((deprecated, warning("use clear() instead")));
|
||||||
|
@ -200,6 +211,9 @@ public:
|
||||||
uint16_t rawADC(byte adc_bits);
|
uint16_t rawADC(byte adc_bits);
|
||||||
|
|
||||||
protected:
|
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];
|
unsigned char sBuffer[(HEIGHT*WIDTH)/8];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,16 @@ const uint8_t PROGMEM pinBootProgram[] = {
|
||||||
PIN_A_BUTTON, INPUT_PULLUP,
|
PIN_A_BUTTON, INPUT_PULLUP,
|
||||||
PIN_B_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
|
// audio is specifically not included here as those pins are handled
|
||||||
// separately by `audio.begin()`, `audio.on()` and `audio.off()` in order
|
// separately by `audio.begin()`, `audio.on()` and `audio.off()` in order
|
||||||
// to respect the EEPROM audio settings
|
// to respect the EEPROM audio settings
|
||||||
|
|
Loading…
Reference in New Issue