Skip to content

Commit

Permalink
more robust deep sleep, fix ledstring compilation, blaster deflect on…
Browse files Browse the repository at this point in the history
… single button click
  • Loading branch information
Protonerd authored Feb 20, 2018
1 parent 81af8b9 commit d0ad73b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 29 deletions.
20 changes: 19 additions & 1 deletion Buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ void mainClick() {
Serial.println(F("Main button click."));
#endif
if (SaberState==S_SABERON) {
/*
if (lockuponclash) {
HumRelaunch();
ActionModeSubStates = AS_HUM;
Expand All @@ -208,8 +209,25 @@ void mainClick() {
#if defined LS_BUTTON_DEBUG
Serial.println(F("Start clash triggered lockup (either pre or active phase)"));
#endif
}*/
#if defined LS_BUTTON_DEBUG
Serial.println(F("Start motion triggered blaster bolt deflect"));
#endif
if (ActionModeSubStates!=AS_BLASTERDEFLECTMOTION) { // start motion triggered blaster deflect
ActionModeSubStates=AS_BLASTERDEFLECTMOTION;
#if defined LS_BUTTON_DEBUG
Serial.println(F("Start motion triggered blaster bolt deflect"));
#endif
}
}
else { // stop motion triggered blaster deflect
#if defined LS_BUTTON_DEBUG
Serial.println(F("End motion triggered blaster bolt deflect"));
#endif
HumRelaunch();
ActionModeSubStates=AS_HUM;
accentLEDControl(AL_ON);
}
}
else if (SaberState==S_CONFIG) {
#ifdef DEEP_SLEEP
if (ConfigModeSubStates==CS_SLEEPINIT) {
Expand Down
2 changes: 1 addition & 1 deletion ConfigMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum ActionModeSubStatesEnum {AS_HUM, AS_IGNITION, AS_RETRACTION, AS_BLADELOCKUP
enum ConfigModeSubStatesEnum {CS_SOUNDFONT, CS_FLICKERTYPE, CS_SLEEPINIT, CS_LASTMEMBER, CS_VOLUME, CS_POWERONOFFTYPE, CS_SWINGSENSITIVITY, CS_MAINCOLOR, CS_CLASHCOLOR, CS_BLASTCOLOR, CS_BATTERYLEVEL, CS_STORAGEACCESS, CS_UARTMODE}; // never delete CS_LASTMEMBER!!! Needed to calculate number of elements in the enum type!!!
#endif
#if defined STAR_LED or defined ADF_PIXIE_BLADE
enum ConfigModeSubStatesEnum {CS_SOUNDFONT, CS_FLICKERTYPE, CS_MAINCOLOR, CS_CLASHCOLOR, CS_BLASTCOLOR, CS_SWINGSENSITIVITY, CS_VOLUME, CS_LASTMEMBER, CS_SLEEPINIT, CS_BATTERYLEVEL, CS_POWERONOFFTYPE, CS_STORAGEACCESS, CS_UARTMODE}; // never delete CS_LASTMEMBER!!! Needed to calculate number of elements in the enum type!!!
enum ConfigModeSubStatesEnum {CS_SOUNDFONT, CS_FLICKERTYPE, CS_MAINCOLOR, CS_CLASHCOLOR, CS_BLASTCOLOR, CS_SWINGSENSITIVITY, CS_LASTMEMBER, CS_VOLUME, CS_SLEEPINIT, CS_BATTERYLEVEL, CS_POWERONOFFTYPE, CS_STORAGEACCESS, CS_UARTMODE}; // never delete CS_LASTMEMBER!!! Needed to calculate number of elements in the enum type!!!
#endif
#if defined PIXELBLADE
enum ConfigModeSubStatesEnum {CS_SOUNDFONT, CS_SWINGSENSITIVITY, CS_FLICKERTYPE, CS_MAINCOLOR, CS_CLASHCOLOR, CS_BLASTCOLOR, CS_SLEEPINIT, CS_LASTMEMBER, CS_VOLUME, CS_POWERONOFFTYPE, CS_BATTERYLEVEL, CS_STORAGEACCESS, CS_UARTMODE}; // never delete CS_LASTMEMBER!!! Needed to calculate number of elements in the enum type!!!
Expand Down
4 changes: 2 additions & 2 deletions Config_HW.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
* blocks from compile
*************************************/
//#define LEDSTRINGS
#define STAR_LED
//#define PIXELBLADE
//#define STAR_LED
#define PIXELBLADE
//#define ADF_PIXIE_BLADE

/************************************/
Expand Down
6 changes: 3 additions & 3 deletions Config_SW.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@
* or by polling the INT_STATUS register via I2C and determining the value (-> CLASH_DET_MPU_POLL)
* of bit 6
*/
//#define CLASH_DET_MPU_INT
#define CLASH_DET_MPU_POLL
#define CLASH_DET_MPU_INT
//#define CLASH_DET_MPU_POLL

/* FX DURATIONS AND SUPRESS TIMES
* effects cannot be retriggered for the duration
Expand Down Expand Up @@ -124,7 +124,7 @@
* If you a device with a CPU wich is not
* an Atmega328 : COMMENT THIS
*************************************/
#define DEEP_SLEEP
//#define DEEP_SLEEP
#if defined DEEP_SLEEP
#define SLEEPYTIME 60000 //20 secs, after which the board will automatically go to sleep mode (to be implemented)
#include <avr/sleep.h>
Expand Down
39 changes: 18 additions & 21 deletions FX-SaberOS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ Serial.println(configAdress);
/************ DEEP_SLEEP MODE SETTINGS **********/
pinMode(MP3_PSWITCH, OUTPUT);
pinMode(FTDI_PSWITCH, OUTPUT);
digitalWrite(MP3_PSWITCH, LOW); // enable MP3 player with A0
digitalWrite(FTDI_PSWITCH, LOW); // enable FTDI player with A1
digitalWrite(MP3_PSWITCH, LOW); // enable MP3 player
digitalWrite(FTDI_PSWITCH, LOW); // enable FTDI player
// pin change interrupt masks (see below list)
PCMSK2 |= bit (PCINT20); // pin 4 Aux button
PCMSK0 |= bit (PCINT4); // pin 12 Main button
Expand Down Expand Up @@ -1539,14 +1539,15 @@ void SleepModeEntry() {
// pin change interrupt masks (see below list)
//PCMSK2 |= bit (PCINT20); // pin 4 Aux button
PCMSK0 |= bit (PCINT4); // pin 12 Main button
mpu.setSleepEnabled(true);
Disable_MP3(true);
mpu.setSleepEnabled(true); // included as dummy, for an unknown reason if it's not here and the dfplayer.sleep() is commented out, sound is disabled
//dfplayer.sleep();
// contrain the communication signals to the MP3 player to low, otherwise they will back-supply the module
pinMode(DFPLAYER_RX, OUTPUT);
digitalWrite(DFPLAYER_RX, LOW);
pinMode(DFPLAYER_TX, OUTPUT);
digitalWrite(DFPLAYER_TX, LOW);
mpu.setSleepEnabled(true);
Disable_MP3(true);
//mpu.setSleepEnabled(true); // included as dummy, for an unknown reason if it's not here and the dfplayer.sleep() is commented out, sound is disabled
//dfplayer.sleep();
delay (300);
Disable_FTDI(true);
sleepNow(); // sleep function called here
Expand All @@ -1557,21 +1558,17 @@ void SleepModeExit() {
// cancel sleep as a precaution
sleep_disable();
power_all_enable (); // enable modules again
//digitalWrite(11,HIGH);
Disable_FTDI(false);
mpu.setSleepEnabled(false);
delay (300);
//mpu.setSleepEnabled(false);
//delay (300);
Disable_MP3(false);
//digitalWrite(11,LOW);
pinMode(DFPLAYER_RX, OUTPUT);
pinMode(DFPLAYER_TX, INPUT);
delay (300);
// only wake up the device if the main button is pressed for at least 1 sec
//delay(1000);
//if (digitalRead(MAIN_BUTTON) == LOW) {
setup(); // redo all initializations
//}
//else { // Anti-Wake up Protection triggers, go back to slee mode
// SleepModeEntry();
//}
//delay (300);
//digitalWrite(11,HIGH);
setup(); // redo all initializations
}


Expand All @@ -1581,12 +1578,12 @@ void Disable_FTDI(bool ftdi_off) {

if (ftdi_off) { // disable FTDI
digitalWrite(FTDI_PSWITCH, HIGH); // disable the FTDI chip
delay (800); // cut power to FTDI, this delay is needed, the sleep
//delay (800); // cut power to FTDI, this delay is needed, the sleep
//function will provoke a Serial error otherwise!!
}
else { // enable ftdi
digitalWrite(FTDI_PSWITCH, LOW); // enable the FTDI chip
delay (800);
//delay (800);
}

}
Expand All @@ -1595,11 +1592,11 @@ void Disable_MP3(bool mp3_off) {

if (mp3_off) { // disable MP3
digitalWrite(MP3_PSWITCH, HIGH); // disable the MP3 chip and the audio amp
delay (300);
//delay (300);
}
else { // enable MP3
digitalWrite(MP3_PSWITCH, LOW); // enable the MP3 chip and the audio amp
delay (300);
//delay (300);
}

}
Expand Down
2 changes: 1 addition & 1 deletion Light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ void lightClashEffect(uint8_t ledPins[], cRGB color) {

}

#ifdef COLOR_PROFILE
#if defined COLOR_PROFILE and not defined LEDSTRINGS
void getColorFix(uint8_t colorID) {
switch (colorID) {
case 0:
Expand Down

0 comments on commit d0ad73b

Please sign in to comment.