Skip to content

Commit 71becd2

Browse files
authored
major bug fixes, tag v1.1
FX-SaberOS.ino: [Bug fix]: // according to debug on 3.11.2017, these 2 lines below cause the sporadic disable of sound. For audio tracker they are not strictly needed. //pinMode(SPK1, INPUT); //pinMode(SPK2, INPUT); [Enhancement]: if volume is not configurable, set it as default to max (31) Buttons.cpp: [Bug Fix]: auto increment bug in swing sensitivity and flicker style found and fixed. No auto increment any more. [Enhancement]: in swing sensitivity config item increment/decrement sensitivity by 1/100th of a g (click) or 1/10th of a g (hit) Light.cpp/.h: [Enhancement]: started to implement staggered ignition for crossguard sabers
1 parent b34ac66 commit 71becd2

File tree

8 files changed

+133
-108
lines changed

8 files changed

+133
-108
lines changed

Buttons.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ extern void LoopPlay_Sound(uint8_t track);
5858
extern void Pause_Sound();
5959
extern void Resume_Sound();
6060
extern void Set_Loop_Playback();
61-
extern void Set_Volume(int8_t volumeSet=-1);
61+
extern void Set_Volume(int8_t volumeSet);
6262
extern void Disable_FTDI(bool ftdi_off);
6363
extern void Disable_MP3(bool mp3_off);
6464
extern void confParseValue(uint16_t variable, uint16_t min, uint16_t max,
@@ -91,7 +91,7 @@ void ConfigMenuButtonEventHandler(bool SaturateColor, ButtonActionEnum ButtonAct
9191
confParseValue(storage.volume, 5, 30, 1*incrementSign);
9292
storage.volume = value;
9393
BladeMeter(ledPins, value*100/30);
94-
Set_Volume();
94+
Set_Volume(storage.volume);
9595
#if defined LS_INFO
9696
Serial.println(storage.volume);
9797
#endif
@@ -133,7 +133,7 @@ void ConfigMenuButtonEventHandler(bool SaturateColor, ButtonActionEnum ButtonAct
133133
delay(50);
134134
}
135135
#endif // PIXELBLADE or STAR_LED
136-
else if (ConfigModeSubStates == CS_FLICKERTYPE) {
136+
else if (ConfigModeSubStates == CS_FLICKERTYPE and ButtonActionType==SINGLE_CLICK) {
137137
#ifdef LEDSTRINGS
138138
confParseValue(storage.sndProfile[storage.soundFont].flickerType, 0, 2, 1*incrementSign); // max number of flicker types for LEDSTRINGS currently 3
139139
#endif
@@ -152,14 +152,14 @@ void ConfigMenuButtonEventHandler(bool SaturateColor, ButtonActionEnum ButtonAct
152152
Serial.println(storage.sndProfile[storage.soundFont].flickerType);
153153
#endif
154154
}
155-
else if (ConfigModeSubStates == CS_SWINGSENSITIVITY) {
156-
// 2048LSB/g, -32k to +32k, but usable range is ~16384
157-
confParseValue(storage.sndProfile[storage.soundFont].swingSensitivity, 0, 16000, 100*incrementSign);
155+
else if (ConfigModeSubStates == CS_SWINGSENSITIVITY and ButtonActionType==SINGLE_CLICK) {
156+
// 2048LSB/g, -32k to +32k, but usable range is ~16384(=1g acceleration), increment with 1/100th of a g
157+
confParseValue(storage.sndProfile[storage.soundFont].swingSensitivity, 0, 16000, 160*incrementSign);
158158
storage.sndProfile[storage.soundFont].swingSensitivity = value;
159159
#if defined LS_INFO
160160
Serial.println(storage.sndProfile[storage.soundFont].swingSensitivity);
161161
#endif
162-
BladeMeter(ledPins, (storage.sndProfile[storage.soundFont].swingSensitivity)/160);
162+
BladeMeter(ledPins, (storage.sndProfile[storage.soundFont].swingSensitivity)/100);
163163
}
164164
}
165165

@@ -317,7 +317,7 @@ void mainLongPressStart() {
317317
#ifdef PIXELBLADE
318318
pixelblade_KillKey_Disable();
319319
#endif
320-
Set_Volume();
320+
Set_Volume(storage.volume);
321321
delay(200);
322322
}
323323
#endif
@@ -474,7 +474,7 @@ void lockupLongPressStart() {
474474
#ifdef PIXELBLADE
475475
pixelblade_KillKey_Disable();
476476
#endif
477-
Set_Volume();
477+
Set_Volume(storage.volume);
478478
delay(200); }
479479
} else if (SaberState==S_STANDBY) {
480480
//Entering Config Mode

ConfigMenu.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ void NextConfigState(){
175175
#if defined LS_FSM
176176
Serial.print(F("Swing Sensitivity"));
177177
#endif
178+
BladeMeter(ledPins, (storage.sndProfile[storage.soundFont].swingSensitivity)/100);
178179
SinglePlay_Sound(26);
179180
delay(500);
180181
break;

ConfigMenu.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ enum ActionModeSubStatesEnum {AS_HUM, AS_IGNITION, AS_RETRACTION, AS_BLADELOCKUP
1919

2020
// configure the config menu based on the blade type
2121
#if defined LEDSTRINGS
22-
enum ConfigModeSubStatesEnum {CS_SOUNDFONT, CS_SLEEPINIT, CS_FLICKERTYPE, CS_VOLUME, CS_LASTMEMBER, 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!!!
22+
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!!!
2323
#endif
2424
#if defined STAR_LED
25-
enum ConfigModeSubStatesEnum {CS_BATTERYLEVEL, CS_SOUNDFONT, CS_SLEEPINIT, CS_FLICKERTYPE, CS_MAINCOLOR, CS_CLASHCOLOR, CS_BLASTCOLOR, CS_SWINGSENSITIVITY, CS_VOLUME, CS_LASTMEMBER, CS_POWERONOFFTYPE, CS_STORAGEACCESS, CS_UARTMODE}; // never delete CS_LASTMEMBER!!! Needed to calculate number of elements in the enum type!!!
25+
enum ConfigModeSubStatesEnum {CS_SOUNDFONT, CS_SLEEPINIT, CS_FLICKERTYPE, CS_MAINCOLOR, CS_CLASHCOLOR, CS_BLASTCOLOR, CS_SWINGSENSITIVITY, CS_VOLUME, CS_LASTMEMBER, CS_BATTERYLEVEL, CS_POWERONOFFTYPE, CS_STORAGEACCESS, CS_UARTMODE}; // never delete CS_LASTMEMBER!!! Needed to calculate number of elements in the enum type!!!
2626
#endif
2727
#if defined PIXELBLADE
28-
enum ConfigModeSubStatesEnum {CS_SOUNDFONT, CS_FLICKERTYPE, CS_POWERONOFFTYPE, CS_SLEEPINIT, CS_MAINCOLOR, CS_CLASHCOLOR, CS_BLASTCOLOR, CS_VOLUME, CS_LASTMEMBER, CS_BATTERYLEVEL, CS_SWINGSENSITIVITY, CS_STORAGEACCESS, CS_UARTMODE}; // never delete CS_LASTMEMBER!!! Needed to calculate number of elements in the enum type!!!
28+
enum ConfigModeSubStatesEnum {CS_SOUNDFONT, CS_SLEEPINIT, CS_FLICKERTYPE, CS_MAINCOLOR, CS_CLASHCOLOR, CS_BLASTCOLOR, CS_SWINGSENSITIVITY, 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!!!
2929
#endif
3030

3131
// ====================================================================================

Config_HW.h

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@
6363
//#define STAR_LED
6464
#define PIXELBLADE
6565

66+
/************************************/
67+
/*
68+
* SABER TYPE
69+
* currently in v1.3 only the CROSSGUARDSABER
70+
* will have any effect on the code
71+
* due to the fire blade effect
72+
*************************************/
73+
#define SINGLEBLADE // i.e. Graflex
74+
//#define SABERSTAFF // i.e. Darth Maul saber with dual blades
75+
//#define CROSSGUARDSABER // i.e. Kylo Ren saber
76+
6677
/*
6778
* POWER SAVING CIRCUITRY
6879
* Definition of the power switches (DIYino Prime v1.5 or greater, STARDUST
@@ -112,6 +123,7 @@
112123
// define how many pixels are used for the crossguard and how many for the main blade
113124
#define CG_STRIPE 10 // cross guard stripe length
114125
#define MN_STRIPE 50 // main blade stripe length
126+
#define STAGGERED_IGNITION_DELAY 1000
115127
#endif
116128

117129

@@ -170,21 +182,6 @@
170182
#endif
171183
#endif
172184

173-
174-
/************************************/
175-
/*
176-
* SABER TYPE
177-
* currently in v1.3 only the CROSSGUARDSABER
178-
* will have any effect on the code
179-
* due to the fire blade effect
180-
*************************************/
181-
#define SINGLEBLADE // i.e. Graflex
182-
//#define SABERSTAFF // i.e. Darth Maul saber with dual blades
183-
//#define CROSSGUARDSABER // i.e. Kylo Ren saber
184-
185-
186-
187-
188185
/*!!!!!IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT!!!
189186
*
190187
* MPU6050 device ORIENTATION

Config_SW.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ const long InternalReferenceVoltage = 1062; // Adjust this value to your board'
149149
#define LS_SERIAL //enable serial communication using Wire library
150150
#if defined LS_SERIAL
151151
//#define LS_FSM
152-
//#define LS_INFO
152+
#define LS_INFO
153153
//#define LS_DEBUG
154154
#endif
155155

FX-SaberOS.ino

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/*
2-
FX-SaberOS V1.6.1
2+
FX-SaberOS V1.0
33
4-
Modified from LSOS 1.5 2017 March 3
5-
storage.sndProfile[storage.soundFont].swingSensitivity
6-
released on: 21 Octber 2016
4+
released on: 7 October 2017
75
author: Sebastien CAPOU (neskweek@gmail.com) and Andras Kun (kun.andras@yahoo.de)
86
Source : https://github.com/Protonerd/FX-SaberOS
97
Description: Operating System for Arduino based LightSaber
@@ -53,9 +51,6 @@ bool jukebox_play = false; // indicate whether a song is being played in JukeBox
5351
uint8_t jb_track; // sound file track number in the directory designated for music playback
5452
#endif
5553

56-
// for an unknown reason code fails to compile recently if this function is not pre-defined here
57-
void Set_Volume(int8_t volumeSet=-1);
58-
5954
/***************************************************************************************************
6055
* Saber Finite State Machine Custom Type and State Variable
6156
*/
@@ -184,7 +179,6 @@ void setup() {
184179
// Serial line for debug
185180
Serial.begin(115200);
186181

187-
188182
/***** LOAD CONFIG *****/
189183
// Get config from EEPROM if there is one
190184
// or initialise value with default ones set in StoreStruct
@@ -226,16 +220,24 @@ Serial.println(configAdress);
226220
Serial.println(F("EEPROM LOADED"));
227221
}
228222
#endif
223+
229224
// retreive the sound font ID stored in the EEPROM (last configured)
230225
soundFont.setID(storage.soundFont);
231226
// in case a fireblade flicker type is selected for the active sound font, set the bool variable
232227
if (storage.sndProfile[storage.soundFont].flickerType==2 or storage.sndProfile[storage.soundFont].flickerType==3 or storage.sndProfile[storage.soundFont].flickerType==4) {fireblade=true;}
228+
229+
/* CONFIG ITEMS PRESETS */
230+
/* Set default values to parameters which can be modified in config menu, if the corresponding config menu item is disabled */
233231
// if the config menu does not contain a menu item to define swing sensitivity, default it to 1000 (works very well, mid sensitivity)
234232
if (CS_SWINGSENSITIVITY > CS_LASTMEMBER) {
235233
for (uint8_t i=0; i<SOUNDFONT_QUANTITY;i++){
236234
storage.sndProfile[i].swingSensitivity=1000;
237235
}
238236
}
237+
if (CS_VOLUME > CS_LASTMEMBER) {
238+
storage.volume=31;
239+
}
240+
239241
/***** LOAD CONFIG *****/
240242

241243
/***** MP6050 MOTION DETECTOR INITIALISATION *****/
@@ -314,8 +316,6 @@ Serial.println(configAdress);
314316
mpu.setZGyroOffset(44);
315317
#endif
316318

317-
318-
319319
// make sure it worked (returns 0 if so)
320320
if (devStatus == 0) {
321321
// turn on the DMP, now that it's ready
@@ -447,8 +447,9 @@ Serial.println(configAdress);
447447
InitDFPlayer();
448448

449449
delay(200);
450-
pinMode(SPK1, INPUT);
451-
pinMode(SPK2, INPUT);
450+
// according to debug on 3.11.2017, these 2 lines below cause the sporadic disable of sound. For audio tracker they are not strictly needed.
451+
//pinMode(SPK1, INPUT);
452+
//pinMode(SPK2, INPUT);
452453
SinglePlay_Sound(11);
453454
delay(20);
454455

@@ -480,6 +481,7 @@ Serial.println(configAdress);
480481
PrevSaberState = S_SLEEP;
481482
ActionModeSubStates = AS_HUM;
482483
//Disable_MP3(true); // disable the MP3 in Stand-by mode to enable FTDI communication
484+
483485
}
484486

485487
// ====================================================================================
@@ -537,8 +539,12 @@ void loop() {
537539
SinglePlay_Sound(soundFont.getPowerOn((storage.soundFont)*NR_FILE_SF));
538540
// Light up the blade
539541
pixelblade_KillKey_Disable();
540-
lightIgnition(ledPins, soundFont.getPowerOnTime(), storage.sndProfile[storage.soundFont].poweronoffType, storage.sndProfile[storage.soundFont].mainColor);
541-
542+
#ifdef CROSSGUARDSABER
543+
lightIgnition(ledPins, soundFont.getPowerOnTime(), storage.sndProfile[storage.soundFont].poweronoffType, storage.sndProfile[storage.soundFont].mainColor, 11, 60);
544+
#else // single blade or saber staff
545+
lightIgnition(ledPins, soundFont.getPowerOnTime(), storage.sndProfile[storage.soundFont].poweronoffType, storage.sndProfile[storage.soundFont].mainColor);
546+
#endif
547+
542548
sndSuppress = millis()-soundFont.getPowerOnTime();
543549
sndSuppress2 = millis();
544550

@@ -553,6 +559,13 @@ void loop() {
553559
//digitalWrite(ACCENT_LED, HIGH);
554560
#endif
555561
}
562+
#ifdef CROSSGUARDSABER
563+
if (millis()-sndSuppress2>STAGGERED_IGNITION_DELAY) {
564+
SinglePlay_Sound(soundFont.getClash((storage.soundFont)*NR_FILE_SF));
565+
lightIgnition(ledPins, soundFont.getPowerOnTime(), storage.sndProfile[storage.soundFont].poweronoffType, storage.sndProfile[storage.soundFont].mainColor, 0, 10);
566+
sndSuppress2=millis();
567+
}
568+
#endif
556569

557570
// ************************* blade movement detection ************************************
558571
//Let's get our values !
@@ -596,8 +609,9 @@ void loop() {
596609
*/
597610
ActionModeSubStates = AS_CLASH;
598611
lightClashEffect(ledPins, storage.sndProfile[storage.soundFont].clashColor);
599-
delay(CLASH_FX_DURATION); // clash duration
600-
612+
if (!fireblade) {
613+
delay(CLASH_FX_DURATION); // clash duration
614+
}
601615
}
602616
}
603617
}
@@ -626,7 +640,7 @@ void loop() {
626640
//getColor(storage.sndProfile[storage.soundFont].blasterboltColor);
627641
//lightOn(ledPins, -1, currentColor);
628642
blasterPixel = random(NUMPIXELS / 4, NUMPIXELS - 3); //momentary shut off one led segment
629-
getColor(storage.sndProfile[storage.soundFont].blasterboltColor);
643+
//getColor(storage.sndProfile[storage.soundFont].blasterboltColor);
630644
// lightBlasterEffect(blasterPixel, 3, storage.sndProfile[storage.soundFont].mainColor);
631645
lightBlasterEffect(ledPins, blasterPixel, map(NUMPIXELS, 0, 120, 1, 3), storage.sndProfile[storage.soundFont].blasterboltColor);
632646
}
@@ -639,7 +653,7 @@ void loop() {
639653

640654
} // #endif
641655
#endif
642-
delay(BLASTER_FX_DURATION); // blaster bolt deflect duration
656+
//delay(BLASTER_FX_DURATION); // blaster bolt deflect duration
643657
// Some Soundfont may not have Blaster sounds
644658
if (millis() - sndSuppress > 50) {
645659
//SinglePlay_Sound(soundFont.getBlaster((storage.soundFont)*NR_FILE_SF));
@@ -652,8 +666,8 @@ void loop() {
652666
We detect swings as hilt's orientation change
653667
since IMUs sucks at determining relative position in space
654668
*/
655-
//else if ((not fireblade) and
656-
else if (true and
669+
else if ((not fireblade) and
670+
//else if (true and
657671
(ActionModeSubStates != AS_BLADELOCKUP or lockuponclash)// end lockuponclash event on a swing
658672
#ifndef SWING_QUATERNION
659673
and (abs(curDeltAccel.y) > storage.sndProfile[storage.soundFont].swingSensitivity // and it has suffisent power on a certain axis
@@ -899,7 +913,7 @@ void loop() {
899913
// turn on the volume full
900914
storage.volume = 30; //MAX
901915
BladeMeter(ledPins, storage.volume*100/30);
902-
Set_Volume(); // Too Slow: we'll change volume on exit
916+
Set_Volume(storage.volume); // Too Slow: we'll change volume on exit
903917
delay(50);
904918
#if defined LS_INFO
905919
Serial.println(storage.volume);
@@ -912,9 +926,9 @@ void loop() {
912926
case CS_POWERONOFFTYPE:
913927
break;
914928
case CS_SWINGSENSITIVITY:
915-
// upon clash increase swing sensitivity by 1000
916-
if (storage.sndProfile[storage.soundFont].swingSensitivity < 15000 ) {
917-
storage.sndProfile[storage.soundFont].swingSensitivity=storage.sndProfile[storage.soundFont].swingSensitivity+1000;
929+
// upon clash increase swing sensitivity by 1/10th of a g (1g=16384)
930+
if (storage.sndProfile[storage.soundFont].swingSensitivity <= 14400 ) {
931+
storage.sndProfile[storage.soundFont].swingSensitivity=storage.sndProfile[storage.soundFont].swingSensitivity+1600;
918932
}
919933
else {
920934
storage.sndProfile[storage.soundFont].swingSensitivity=0;
@@ -928,7 +942,7 @@ void loop() {
928942
else { //
929943
storage.sndProfile[storage.soundFont].swingSensitivity=100;
930944
}*/
931-
BladeMeter(ledPins, (storage.sndProfile[storage.soundFont].swingSensitivity)/160);
945+
BladeMeter(ledPins, (storage.sndProfile[storage.soundFont].swingSensitivity)/100);
932946
Serial.println(storage.sndProfile[storage.soundFont].swingSensitivity);
933947
break;
934948
case CS_SLEEPINIT:
@@ -1330,13 +1344,13 @@ void LoopPlay_Sound(uint8_t track) {
13301344
dfplayer.playSingleLoop(track);
13311345
}
13321346

1333-
void Set_Volume(int8_t volumeSet=-1) {
1334-
if (volumeSet == -1) { // as a default retreive volume setting from config storage
1335-
dfplayer.setVolume(storage.volume); // Too Slow: we'll change volume on
1336-
}
1337-
else {
1347+
void Set_Volume(int8_t volumeSet) {
1348+
//if (volumeSet == -1) { // as a default retreive volume setting from config storage
1349+
// dfplayer.setVolume(storage.volume); // Too Slow: we'll change volume on
1350+
//}
1351+
//else {
13381352
dfplayer.setVolume(volumeSet);
1339-
}
1353+
//}
13401354
delay(50);
13411355
}
13421356

@@ -1349,10 +1363,10 @@ void InitDFPlayer() {
13491363
// AK 7.9.2016: if the storage.volume has no or invalid value, it will cause the
13501364
// sketch to repeat setup (reset itself) - up till now no idea why?
13511365
// this can happen if the EEPROM is erased (i.e. reflash of bootloader)
1352-
if (CS_LASTMEMBER < CS_VOLUME) { // if the volume cannot be set from the config menu, set it to the loudest
1353-
storage.volume=30;
1354-
}
1355-
dfplayer.setVolume(storage.volume);
1366+
//if (CS_LASTMEMBER < CS_VOLUME) { // if the volume cannot be set from the config menu, set it to the loudest
1367+
// storage.volume=31;
1368+
//}
1369+
//dfplayer.setVolume(storage.volume);
13561370
//setup finished. Boot ready. We notify !
13571371
}
13581372

0 commit comments

Comments
 (0)