aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorSelene ToyKeeper2017-08-19 15:33:33 -0600
committerSelene ToyKeeper2017-08-19 15:33:33 -0600
commitef05435261fac31790303dbff16bcc194e9e5cb5 (patch)
tree628e02df8e30e1b4068c076ad14df2b4b3bded02 /spaghetti-monster
parentAdded unfinished UI similar to Olight Baton series. (diff)
downloadanduril-ef05435261fac31790303dbff16bcc194e9e5cb5.tar.gz
anduril-ef05435261fac31790303dbff16bcc194e9e5cb5.tar.bz2
anduril-ef05435261fac31790303dbff16bcc194e9e5cb5.zip
Fixed unreliability of short-click detection.
(it was doing stuff like "press, release, release, timeout" so it didn't match "press, release, timeout") (it may have also been missing the exact tick it needed, so I made it use >= instead of ==, but this is theoretical and harmless if I was wrong) Made baton mode memory work a bit better for both regular and strobe modes. Made baton fast strobe pulses shorter for better motion freezing. Added USE_DELAY_ZERO option as an alternate for USE_FINE_DELAY.
Diffstat (limited to 'spaghetti-monster')
-rw-r--r--spaghetti-monster/baton.c17
-rw-r--r--spaghetti-monster/spaghetti-monster.h17
2 files changed, 24 insertions, 10 deletions
diff --git a/spaghetti-monster/baton.c b/spaghetti-monster/baton.c
index de63914..ed2b444 100644
--- a/spaghetti-monster/baton.c
+++ b/spaghetti-monster/baton.c
@@ -21,16 +21,19 @@
#define USE_LVP
#define USE_DEBUG_BLINK
#define USE_DELAY_MS
+#define USE_DELAY_ZERO
#include "spaghetti-monster.h"
// ../../bin/level_calc.py 2 7 7135 3 0.25 150 FET 1 10 1500
uint8_t pwm1_modes[] = { 3, 27, 130, 255, 255, 255, 0, };
uint8_t pwm2_modes[] = { 0, 0, 0, 12, 62, 141, 255, };
+// FSM states
uint8_t off_state(EventPtr event, uint16_t arg);
uint8_t steady_state(EventPtr event, uint16_t arg);
uint8_t party_strobe_state(EventPtr event, uint16_t arg);
+// brightness control
uint8_t current_mode = 0;
void set_mode(uint8_t mode) {
@@ -43,6 +46,7 @@ uint8_t off_state(EventPtr event, uint16_t arg) {
if (event == EV_enter_state) {
PWM1_LVL = 0;
PWM2_LVL = 0;
+ // TODO: standby_mode();
return 0;
}
// 1 click: regular mode
@@ -90,7 +94,7 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
}
// 2 clicks: go to strobe modes
else if (event == EV_2clicks) {
- set_state(party_strobe_state, 2);
+ set_state(party_strobe_state, 0xff);
return 0;
}
// hold: change brightness
@@ -106,18 +110,19 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
uint8_t party_strobe_state(EventPtr event, uint16_t arg) {
static volatile uint8_t frames = 0;
- static volatile uint8_t between = 0;
+ static volatile uint8_t between = 2;
if (event == EV_enter_state) {
- between = arg;
+ if (arg < 64) between = arg;
frames = 0;
return 0;
}
- // strobe the emitter
+ // tick: strobe the emitter
else if (event == EV_tick) {
if (frames == 0) {
PWM1_LVL = 255;
PWM2_LVL = 0;
- delay_ms(1);
+ if (between < 3) delay_zero();
+ else delay_ms(1);
PWM1_LVL = 0;
}
//frames = (frames + 1) % between;
@@ -132,7 +137,7 @@ uint8_t party_strobe_state(EventPtr event, uint16_t arg) {
}
// 2 clicks: go back to regular modes
else if (event == EV_2clicks) {
- set_state(steady_state, 1);
+ set_state(steady_state, current_mode);
return 0;
}
// hold: change speed
diff --git a/spaghetti-monster/spaghetti-monster.h b/spaghetti-monster/spaghetti-monster.h
index e51416a..cfabea8 100644
--- a/spaghetti-monster/spaghetti-monster.h
+++ b/spaghetti-monster/spaghetti-monster.h
@@ -243,8 +243,10 @@ void empty_event_sequence() {
void push_event(uint8_t ev_type) {
ticks_since_last_event = 0; // something happened
uint8_t i;
- for(i=0; current_event[i] && (i<EV_MAX_LEN); i++);
- if (i < EV_MAX_LEN) {
+ uint8_t prev_event = 0; // never push the same event twice in a row
+ for(i=0; current_event[i] && (i<EV_MAX_LEN); i++)
+ prev_event = current_event[i];
+ if ((i < EV_MAX_LEN) && (prev_event != ev_type)) {
current_event[i] = ev_type;
} else {
// TODO: ... something?
@@ -418,6 +420,12 @@ uint8_t button_is_pressed() {
//void button_change_interrupt() {
ISR(PCINT0_vect) {
+ // this interrupt should not be re-entrant
+ //static volatile uint8_t lockout = 0;
+
+ //if (lockout) return;
+ //lockout = 1;
+
//DEBUG_FLASH;
// something happened
@@ -433,6 +441,7 @@ ISR(PCINT0_vect) {
// check if sequence matches any defined sequences
// if so, send event to current state callback
emit_current_event(0);
+ //lockout = 0;
}
// clock tick -- this runs every 16ms (62.5 fps)
@@ -458,7 +467,7 @@ ISR(WDT_vect) {
// user held button long enough to count as a long click?
if (last_event == A_PRESS) {
- if (ticks_since_last_event == HOLD_TIMEOUT) {
+ if (ticks_since_last_event >= HOLD_TIMEOUT) {
push_event(A_HOLD);
emit_current_event(0);
}
@@ -478,7 +487,7 @@ ISR(WDT_vect) {
empty_event_sequence();
}
// end and clear event after release timeout
- else if (ticks_since_last_event == RELEASE_TIMEOUT) {
+ else if (ticks_since_last_event >= RELEASE_TIMEOUT) {
push_event(A_RELEASE_TIMEOUT);
emit_current_event(0);
empty_event_sequence();