Skip to content

Commit

Permalink
Changes clash sensitivity and the way how the clash FX works
Browse files Browse the repository at this point in the history
FX-SaberOS.ino:
- reworked clash, on clash, the state machine will change to clash mode and it will flicker for the duration of the clash FX parameter with the clash color
- reset deep sleep mode counter upon exiting config mode
- deleted swing detection conditional statements for BLADE_X and BLADE_Z (no one ever used them...)
- made exit from deep sleep mode more robust, removed delays, still suspect either a bus contention or WD, because in fact the controller wakes up but keeps hanging in an unknown state when the saber cannot be woken up.
- some compiler directive changes due to Stardust V3 board

Config_SW.h:
- increased nearly all supress and fx duration definitions
- increased CLASH_THRESHOLD from 10 to 15 as at 10 it was too sensitive to fast wrist movements with the new int based clash detection

Config_HW.h:
- now can choose between Stardust V3, Stardust V2 and Prime V1 (also for home brew) boards

Light.cpp:
- changes mainly to flicker due to new clash flicker
- compile directive changes due to the new board types

Soundfont.h:
- compile directive changes due to the new board types

Buttons.cpp:
- in single button mode a click will activate blaster-deflect-on-the-move
- if color profiles are used (i.e. not Gravity Color) exit from config mode in single button mode on long PRESS_ACTION

Deleted LICENSE and README.md files, obsolete
  • Loading branch information
Protonerd authored Mar 1, 2018
1 parent d0ad73b commit 89a1afb
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 136 deletions.
6 changes: 5 additions & 1 deletion Buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
21 changes: 11 additions & 10 deletions Config_HW.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ******/

Expand All @@ -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
Expand All @@ -60,8 +61,8 @@
* blocks from compile
*************************************/
//#define LEDSTRINGS
//#define STAR_LED
#define PIXELBLADE
#define STAR_LED
//#define PIXELBLADE
//#define ADF_PIXIE_BLADE

/************************************/
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
/*
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions Config_SW.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
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
115 changes: 18 additions & 97 deletions FX-SaberOS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down
Loading

0 comments on commit 89a1afb

Please sign in to comment.