diff --git a/Buttons.cpp b/Buttons.cpp index 94ec62c..e846be6 100644 --- a/Buttons.cpp +++ b/Buttons.cpp @@ -355,7 +355,9 @@ void mainLongPressStart() { NextConfigState(); #else // SINGLEBUTTON //Leaving Config Mode +#ifdef GRAVITY_COLOR // only in case of Gravity Color Mix do not allow exit config mode upon long press if (ConfigModeSubStates!=CS_MAINCOLOR and ConfigModeSubStates!=CS_CLASHCOLOR and ConfigModeSubStates!=CS_BLASTCOLOR) { +#endif // GRAVITY_COLOR changeMenu = false; SaberState=S_STANDBY; PrevSaberState=S_CONFIG; @@ -364,8 +366,10 @@ void mainLongPressStart() { #endif Set_Volume(storage.volume); delay(200); +#ifdef GRAVITY_COLOR } -#endif +#endif // GRAVITY_COLOR +#endif // SINGLEBUTTON } #ifdef SINGLEBUTTON #ifdef JUKEBOX diff --git a/Config_HW.h b/Config_HW.h index 4445acb..76da394 100644 --- a/Config_HW.h +++ b/Config_HW.h @@ -21,8 +21,9 @@ * If you have a home-brew solution using the Arduino Nano, choose DIYINO_PRIME below */ -//#define DIYINO_PRIME -#define DIYINO_STARDUST +//#define DIYINO_PRIME // including home-brew +//#define DIYINO_STARDUST_V2 +#define DIYINO_STARDUST_V3 /***** BOARD PINOUT DEFINITIONS ******/ @@ -43,7 +44,7 @@ #ifndef SINGLEBUTTON #define AUX_BUTTON 4 #endif -#else if DIYINO_STARDUST +#else if defined DIYINO_STARDUST_V2 or defined DIYINO_STARDUST_V3 #define MAIN_BUTTON 12 #ifndef SINGLEBUTTON #define AUX_BUTTON 11 // 2 @@ -60,8 +61,8 @@ * blocks from compile *************************************/ //#define LEDSTRINGS -//#define STAR_LED -#define PIXELBLADE +#define STAR_LED +//#define PIXELBLADE //#define ADF_PIXIE_BLADE /************************************/ @@ -86,7 +87,7 @@ #ifdef DIYINO_PRIME #define MP3_PSWITCH 15 // A1 #define FTDI_PSWITCH 16 // A2 -#else if DIYINO_STARDUST +#else if defined DIYINO_STARDUST_V2 or defined DIYINO_STARDUST_V3 #define MP3_PSWITCH 17 // A3 #define FTDI_PSWITCH 16 // A2 #endif @@ -106,7 +107,7 @@ #define LED_RED 3 #define LED_GREEN 5 #define LED_BLUE 6 - #else if DIYINO_STARDUST + #else if defined DIYINO_STARDUST_V2 or defined DIYINO_STARDUST_V3 #define LED_RED 5 #define LED_GREEN 6 #define LED_BLUE 9 @@ -151,7 +152,7 @@ #define LS4 9 #define LS5 10 #define LS6 11 - #else if DIYINO_STARDUST + #else if defined DIYINO_STARDUST_V2 or defined DIYINO_STARDUST_V3 #define LS1 5 #define LS2 6 #define LS3 9 @@ -170,7 +171,7 @@ *************************************/ #ifdef DIYINO_PRIME #define ACCENT_LED 14 //A0 -#else if DIYINO_STARDUST +#else if defined DIYINO_STARDUST_V2 or defined DIYINO_STARDUST_V3 #define ACCENT_LED 14 //A0 is an auxiliary pin on Stardust v2 #endif /* @@ -189,7 +190,7 @@ #ifdef DIYINO_PRIME #define BATTERY_READPIN 17 //A3 - read battery level #endif - #ifdef DIYINO_STARDUST + #if defined DIYINO_STARDUST_V2 or defined DIYINO_STARDUST_V3 #define BATTERY_READPIN 15 #endif #endif diff --git a/Config_SW.h b/Config_SW.h index a3e1f09..76e0cb7 100644 --- a/Config_SW.h +++ b/Config_SW.h @@ -23,7 +23,7 @@ #define VOL 20 #define SOUNDFONT 3 #define SWING 1000 -#define CLASH_THRESHOLD 10 // 10 was the original value in LSOS, Jason's value changed it to 6, but it resulted in false clash trigges at more forceful swings +#define CLASH_THRESHOLD 15 // 10 was the original value in LSOS, Jason's value changed it to 6, but it resulted in false clash trigges at more forceful swings /************************************/ #if defined LEDSTRINGS @@ -74,9 +74,9 @@ * of their respective suppress pareameters */ -#define SWING_SUPPRESS 300 -#define CLASH_SUPRESS 200 // do not modify below 400, otherwise interlocking clash sounds can occur -#define BLASTERBLOCK_SUPRESS 200 +#define SWING_SUPPRESS 500 +#define CLASH_SUPRESS 400 // do not modify below 400, otherwise interlocking clash sounds can occur +#define BLASTERBLOCK_SUPRESS 500 /* * HUM_RELAUNCH will tell the state machine to relaunch @@ -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 diff --git a/FX-SaberOS.ino b/FX-SaberOS.ino index 77c1184..9a70051 100644 --- a/FX-SaberOS.ino +++ b/FX-SaberOS.ino @@ -96,7 +96,7 @@ VectorInt16 prevDeltAccel; #if defined LEDSTRINGS #ifdef DIYINO_PRIME uint8_t ledPins[] = {LS1, LS2, LS3, LS4, LS5, LS6}; - #else if #ifdef DIYINO_STARDUST + #else if defined DIYINO_STARDUST_V2 or defined DIYINO_STARDUST_V3 uint8_t ledPins[] = {LS1, LS2, LS3}; #endif uint8_t blasterPin; @@ -108,7 +108,7 @@ extern bool fireblade; #if defined PIXELBLADE or defined ADF_PIXIE_BLADE #ifdef DIYINO_PRIME uint8_t ledPins[] = {LS1, LS2, LS3, LS4, LS5, LS6}; - #else if #ifdef DIYINO_STARDUST + #else if defined DIYINO_STARDUST_V2 or defined DIYINO_STARDUST_V3 uint8_t ledPins[] = {LS1, LS2, LS3}; #endif WS2812 pixels(NUMPIXELS); @@ -657,6 +657,17 @@ void loop() { } } } + // CLASH state, flicker with clash color/brightness for the duration of CLASH_FX_DURATION + else if (ActionModeSubStates==AS_CLASH){ + // check if duration expired + if (millis()-sndSuppress < CLASH_FX_DURATION) { + lightFlicker(ledPins, storage.sndProfile[storage.soundFont].flickerType, 0, storage.sndProfile[storage.soundFont].mainColor, storage.sndProfile[storage.soundFont].clashColor, ActionModeSubStates); + } + else { + ActionModeSubStates=AS_HUM; + sndSuppress=millis(); + } + } /* SWING DETECTION We detect swings as hilt's orientation change @@ -677,53 +688,6 @@ void loop() { #else // SWING_QUATERNION is defined and abs(curRotation.w * 1000) < 999 // some rotation movement have been initiated and ( - #if defined BLADE_X - - ( - (millis() - sndSuppress > SWING_SUPPRESS) // The movement doesn't follow another to closely - and (abs(curDeltAccel.y) > storage.sndProfile[storage.soundFont].swingSensitivity // and it has suffisent power on a certain axis - or abs(curDeltAccel.z) > storage.sndProfile[storage.soundFont].swingSensitivity - or abs(curDeltAccel.x) > storage.sndProfile[storage.soundFont].swingSensitivity * 10) - ) - or (// A reverse movement follow a first one - (millis() - sndSuppress2 > SWING_SUPPRESS) // The reverse movement doesn't follow another reverse movement to closely - // and it must be a reverse movement on Vertical axis - and ( - abs(curDeltAccel.y) > abs(curDeltAccel.z) - and abs(prevDeltAccel.y) > storage.sndProfile[storage.soundFont].swingSensitivity - and ( - (prevDeltAccel.y > 0 - and curDeltAccel.y < -storage.sndProfile[storage.soundFont].swingSensitivity) - or ( - prevDeltAccel.y < 0 - and curDeltAccel.y > storage.sndProfile[storage.soundFont].swingSensitivity - ) - ) - ) - ) - or (// A reverse movement follow a first one - (millis() - sndSuppress2 > SWING_SUPPRESS) // The reverse movement doesn't follow another reverse movement to closely - and ( // and it must be a reverse movement on Horizontal axis - abs(curDeltAccel.z) > abs(curDeltAccel.y) - and abs(prevDeltAccel.z) > storage.sndProfile[storage.soundFont].swingSensitivity - and ( - (prevDeltAccel.z > 0 - and curDeltAccel.z < -storage.sndProfile[storage.soundFont].swingSensitivity) - or ( - prevDeltAccel.z < 0 - and curDeltAccel.z > storage.sndProfile[storage.soundFont].swingSensitivity - ) - ) - ) - ) - // the movement must not be triggered by pure blade rotation (wrist rotation) - and not ( - abs(prevRotation.x * 1000 - curRotation.x * 1000) > abs(prevRotation.y * 1000 - curRotation.y * 1000) - and - abs(prevRotation.x * 1000 - curRotation.x * 1000) > abs(prevRotation.z * 1000 - curRotation.z * 1000) - ) - - #endif // BLADE_X #if defined BLADE_Y ( (millis() - sndSuppress > SWING_SUPPRESS) // The movement doesn't follow another to closely @@ -769,51 +733,6 @@ void loop() { abs(prevRotation.y * 1000 - curRotation.y * 1000) > abs(prevRotation.z * 1000 - curRotation.z * 1000) ) #endif // BLADE_Y - #if defined BLADE_Z - ( - (millis() - sndSuppress > SWING_SUPPRESS) // The movement doesn't follow another to closely - and (abs(curDeltAccel.y) > storage.sndProfile[storage.soundFont].swingSensitivity // and it has suffisent power on a certain axis - or abs(curDeltAccel.x) > storage.sndProfile[storage.soundFont].swingSensitivity - or abs(curDeltAccel.z) > storage.sndProfile[storage.soundFont].swingSensitivity * 10) - ) - or (// A reverse movement follow a first one - (millis() - sndSuppress2 > SWING_SUPPRESS) // The reverse movement doesn't follow another reverse movement to closely - // and it must be a reverse movement on Vertical axis - and ( - abs(curDeltAccel.y) > abs(curDeltAccel.x) - and abs(prevDeltAccel.y) > storage.sndProfile[storage.soundFont].swingSensitivity - and ( - (prevDeltAccel.y > 0 - and curDeltAccel.y < -storage.sndProfile[storage.soundFont].swingSensitivity) - or ( - prevDeltAccel.y < 0 - and curDeltAccel.y > storage.sndProfile[storage.soundFont].swingSensitivity - ) - ) - ) - ) - or (// A reverse movement follow a first one - (millis() - sndSuppress2 > SWING_SUPPRESS) // The reverse movement doesn't follow another reverse movement to closely - and ( // and it must be a reverse movement on Horizontal axis - abs(curDeltAccel.x) > abs(curDeltAccel.y) - and abs(prevDeltAccel.x) > storage.sndProfile[storage.soundFont].swingSensitivity - and ( - (prevDeltAccel.x > 0 - and curDeltAccel.x < -storage.sndProfile[storage.soundFont].swingSensitivity) - or ( - prevDeltAccel.x < 0 - and curDeltAccel.x > storage.sndProfile[storage.soundFont].swingSensitivity - ) - ) - ) - ) - // the movement must not be triggered by pure blade rotation (wrist rotation) - and not ( - abs(prevRotation.z * 1000 - curRotation.z * 1000) > abs(prevRotation.y * 1000 - curRotation.y * 1000) - and - abs(prevRotation.z * 1000 - curRotation.z * 1000) > abs(prevRotation.x * 1000 - curRotation.x * 1000) - ) - #endif // BLADE_Z ) #endif // SWING_QUATERNION ) @@ -1356,10 +1275,12 @@ void FX_Clash() { THIS IS A CLASH ! */ ActionModeSubStates = AS_CLASH; + // the next function only activates the clash color (and flashes in case of fireblade) lightClashEffect(ledPins, storage.sndProfile[storage.soundFont].clashColor); + if (!fireblade) { //delay(CLASH_FX_DURATION); // clash duration - delayMicroseconds(CLASH_FX_DURATION*1000); + //delayMicroseconds(CLASH_FX_DURATION*1000); } sndSuppress = millis(); sndSuppress2 = millis(); @@ -1635,7 +1556,7 @@ void BatLevel_ConfigEnter() { // int batLevel = 100 * (1 / batCheck() - 1 / LOW_BATTERY) / (1 / FULL_BATTERY - 1 / LOW_BATTERY); int batLevel = 100 * ((batCheck() - LOW_BATTERY) / (FULL_BATTERY - LOW_BATTERY)); #endif - #ifdef DIYINO_STARDUST + #if defined DIYINO_STARDUST_V2 or defined DIYINO_STARDUST_V3 // flush out the ADC getBandgap(); getBandgap(); @@ -1662,7 +1583,7 @@ void MonitorBattery() { #ifdef DIYINO_PRIME //BatteryStatus=analogRead(BATTERY_READPIN); #endif - #ifdef DIYINO_STARDUST + #if defined DIYINO_STARDUST_V2 or defined DIYINO_STARDUST_V3 BladeMeter(ledPins,(getBandgap()/37)*10); Serial.println(getBandgap()); #endif diff --git a/Light.cpp b/Light.cpp index 03009cc..afbe3ae 100644 --- a/Light.cpp +++ b/Light.cpp @@ -1,7 +1,7 @@ /* * Light.cpp * - * author: Sebastien CAPOU (neskweek@gmail.com) and Andras Kun (kun.andras@yahoo.de)lightClashEffect + * author: Sebastien CAPOU (neskweek@gmail.com) and Andras Kun (kun.andras@yahoo.de) * Source : https://github.com/Protonerd/FX-SaberOS */ #include "Light.h" @@ -563,6 +563,11 @@ void lightFlicker(uint8_t ledPins[],uint8_t type, uint8_t value = 0,cRGB maincol analogWrite(LED_BLUE, MAX_BRIGHTNESS); // BLUE } } + else if (AState==AS_CLASH) { + analogWrite(LED_RED, (brightness * clashcolor.r / rgbFactor)); // RED + analogWrite(LED_GREEN, (brightness * clashcolor.g / rgbFactor)); // GREEN + analogWrite(LED_BLUE, (brightness * clashcolor.b / rgbFactor)); // BLUE + } else { analogWrite(LED_RED, (brightness * maincolor.r / rgbFactor)); // RED analogWrite(LED_GREEN, (brightness * maincolor.g / rgbFactor)); // GREEN @@ -572,9 +577,16 @@ void lightFlicker(uint8_t ledPins[],uint8_t type, uint8_t value = 0,cRGB maincol case 1: // pulse flickering if (((millis()-lastFlicker>=PULSEDURATION/PULSEFLICKERDEPTH) and AState != AS_BLADELOCKUP) or ((millis()-lastFlicker>=2) and AState == AS_BLADELOCKUP)) { lastFlicker=millis(); - analogWrite(LED_RED, ((MAX_BRIGHTNESS - pulseflicker_pwm) * maincolor.r / rgbFactor)); // RED - analogWrite(LED_GREEN, ((MAX_BRIGHTNESS - pulseflicker_pwm) * maincolor.g / rgbFactor)); // GREEN - analogWrite(LED_BLUE, ((MAX_BRIGHTNESS - pulseflicker_pwm) * maincolor.b / rgbFactor)); // BLUE + if (AState==AS_CLASH) { + analogWrite(LED_RED, ((MAX_BRIGHTNESS - pulseflicker_pwm) * clashcolor.r / rgbFactor)); // RED + analogWrite(LED_GREEN, ((MAX_BRIGHTNESS - pulseflicker_pwm) * clashcolor.g / rgbFactor)); // GREEN + analogWrite(LED_BLUE, ((MAX_BRIGHTNESS - pulseflicker_pwm) * clashcolor.b / rgbFactor)); // BLUE + } + else { + analogWrite(LED_RED, ((MAX_BRIGHTNESS - pulseflicker_pwm) * maincolor.r / rgbFactor)); // RED + analogWrite(LED_GREEN, ((MAX_BRIGHTNESS - pulseflicker_pwm) * maincolor.g / rgbFactor)); // GREEN + analogWrite(LED_BLUE, ((MAX_BRIGHTNESS - pulseflicker_pwm) * maincolor.b / rgbFactor)); // BLUE + } if (pulsedir) { pulseflicker_pwm++; } @@ -590,9 +602,16 @@ void lightFlicker(uint8_t ledPins[],uint8_t type, uint8_t value = 0,cRGB maincol } break; case 2: // static blade + if (AState==AS_CLASH) { + analogWrite(LED_RED, clashcolor.r ); // RED + analogWrite(LED_GREEN, clashcolor.g); // GREEN + analogWrite(LED_BLUE, clashcolor.b); // BLUE + } + else { analogWrite(LED_RED, maincolor.r ); // RED analogWrite(LED_GREEN, maincolor.g); // GREEN - analogWrite(LED_BLUE, maincolor.b); // BLUE + analogWrite(LED_BLUE, maincolor.b); // BLUE + } break; } #endif @@ -637,7 +656,13 @@ void lightFlicker(uint8_t ledPins[],uint8_t type, uint8_t value = 0,cRGB maincol color.g = MAX_BRIGHTNESS; color.b = MAX_BRIGHTNESS; } - } else { //normal operation + } + else if (AState==AS_CLASH) { + color.r = brightness * clashcolor.r / rgbFactor; + color.g = brightness * clashcolor.g / rgbFactor; + color.b = brightness * clashcolor.b / rgbFactor; + } + else { //normal operation color.r = brightness * maincolor.r / rgbFactor; color.g = brightness * maincolor.g / rgbFactor; color.b = brightness * maincolor.b / rgbFactor; @@ -653,9 +678,16 @@ void lightFlicker(uint8_t ledPins[],uint8_t type, uint8_t value = 0,cRGB maincol // pulse Flickering if (((millis()-lastFlicker>=PULSEDURATION/PULSEFLICKERDEPTH) and AState != AS_BLADELOCKUP) or (AState == AS_BLADELOCKUP)) { lastFlicker=millis(); - color.r = (MAX_BRIGHTNESS - pulseflicker_pwm) * maincolor.r / rgbFactor; - color.g = (MAX_BRIGHTNESS - pulseflicker_pwm) * maincolor.g / rgbFactor; - color.b = (MAX_BRIGHTNESS - pulseflicker_pwm) * maincolor.b / rgbFactor; + if (AState==AS_CLASH) { + color.r = (MAX_BRIGHTNESS - pulseflicker_pwm) * clashcolor.r / rgbFactor; + color.g = (MAX_BRIGHTNESS - pulseflicker_pwm) * clashcolor.g / rgbFactor; + color.b = (MAX_BRIGHTNESS - pulseflicker_pwm) * clashcolor.b / rgbFactor; + } + else { + color.r = (MAX_BRIGHTNESS - pulseflicker_pwm) * maincolor.r / rgbFactor; + color.g = (MAX_BRIGHTNESS - pulseflicker_pwm) * maincolor.g / rgbFactor; + color.b = (MAX_BRIGHTNESS - pulseflicker_pwm) * maincolor.b / rgbFactor; + } if (pulsedir) { pulseflicker_pwm++; } @@ -884,7 +916,7 @@ void lightBlasterEffect(uint8_t ledPins[], uint8_t pixel, uint8_t range, cRGB Sn void pixelblade_KillKey_Enable() { #if defined PIXELBLADE or defined ADF_PIXIE_BLADE // cut power to the neopixels stripes by disconnecting their GND signal using the LS pins - #ifdef DIYINO_STARDUST + #if defined DIYINO_STARDUST_V2 or defined DIYINO_STARDUST_V3 for (uint8_t j = 0; j < 3; j++) { #endif #ifdef DIYINO_PRIME @@ -909,7 +941,7 @@ void pixelblade_KillKey_Enable() { void pixelblade_KillKey_Disable() { #if defined PIXELBLADE or defined ADF_PIXIE_BLADE // cut power to the neopixels stripes by disconnecting their GND signal using the LS pins - #ifdef DIYINO_STARDUST + #if defined DIYINO_STARDUST_V2 or defined DIYINO_STARDUST_V3 for (uint8_t j = 0; j < 3; j++) { #endif #ifdef DIYINO_PRIME @@ -932,19 +964,19 @@ void lightClashEffect(uint8_t ledPins[], cRGB color) { for (uint8_t i = 0; i <= 5; i++) { analogWrite(ledPins[i], 255); } - delay(CLASH_FX_DURATION); // clash duration + //delay(CLASH_FX_DURATION); // clash duration #endif #if defined STAR_LED getColor(color); lightOn(ledPins, -1, currentColor); - delay(CLASH_FX_DURATION); // clash duration + //delay(CLASH_FX_DURATION); // clash duration #endif #ifdef ADF_PIXIE_BLADE - //getColor(storage.sndProfile[storage.soundFont].clashColor); - lightOn(ledPins, -1, color); - delay(CLASH_FX_DURATION); // clash duration + getColor(storage.sndProfile[storage.soundFont].clashColor); + lightOn(ledPins, -1, currentColor); + //delay(CLASH_FX_DURATION); // clash duration #endif #if defined PIXELBLADE @@ -960,7 +992,7 @@ void lightClashEffect(uint8_t ledPins[], cRGB color) { else { // #else getColor(storage.sndProfile[storage.soundFont].clashColor); lightOn(ledPins, -1, currentColor); - delay(CLASH_FX_DURATION); // clash duration + //delay(CLASH_FX_DURATION); // clash duration } // #endif #endif diff --git a/Soundfont.h b/Soundfont.h index ab06959..27ec036 100644 --- a/Soundfont.h +++ b/Soundfont.h @@ -15,12 +15,12 @@ #define SOUNDFONT_H_ -#ifdef DIYINO_PRIME +#if defined DIYINO_PRIME or defined DIYINO_STARDUST_V3 #define SOUNDFONT_QUANTITY 5 #define NR_CONFIGFOLDERFILES 29 #define NR_JUKEBOXSONGS 0 #define NR_FILE_SF 30 -#else if DIYINO_STARDUST +#else if defined DIYINO_STARDUST_V2 #define SOUNDFONT_QUANTITY 3 #define NR_CONFIGFOLDERFILES 29 #define NR_JUKEBOXSONGS 0 @@ -67,7 +67,7 @@ void setID(uint16_t id) { this->ID = id; switch (id) { - #ifdef DIYINO_PRIME + #if defined DIYINO_PRIME or defined DIYINO_STARDUST_V3 case 0: // soundFont directory 01 : this->powerOnTime = 800; @@ -93,7 +93,7 @@ void setID(uint16_t id) { this->powerOnTime = 700; this->powerOffTime = 1500; break; - #else if DIYINO_STARDUST + #else if DIYINO_STARDUST_V2 case 0: // soundFont directory 01 : this->powerOnTime = 1000; @@ -113,7 +113,7 @@ void setID(uint16_t id) { } } - #ifdef DIYINO_PRIME // 30 files per sound font + #if defined DIYINO_PRIME or defined DIYINO_STARDUST_V3 // 30 files per sound font #define SF_BOOT_OFFSET 1 #define SF_POWERON_OFFSET 2 #define SF_POWEROFF_OFFSET 6 @@ -132,7 +132,7 @@ void setID(uint16_t id) { #define SF_BLASTER_NR 4 #define SF_MENU_NR 1 #define SF_HUM_NR 1 - #else if DIYINO_STARDUST // 18 files per sound font + #else if DIYINO_STARDUST_V2 // 18 files per sound font #define SF_BOOT_OFFSET 1 #define SF_POWERON_OFFSET 2 #define SF_POWEROFF_OFFSET 3