aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/baton.c
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/baton.c
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 '')
-rw-r--r--spaghetti-monster/baton.c17
1 files changed, 11 insertions, 6 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