aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2017-08-19 15:57:10 -0600
committerSelene ToyKeeper2017-08-19 15:57:10 -0600
commited98882eace49e6482c78c6723fbcda9daca1510 (patch)
tree26caf830178523d8bc0a19d00d9bcee8a5e36ae7
parentFixed unreliability of short-click detection. (diff)
downloadanduril-ed98882eace49e6482c78c6723fbcda9daca1510.tar.gz
anduril-ed98882eace49e6482c78c6723fbcda9daca1510.tar.bz2
anduril-ed98882eace49e6482c78c6723fbcda9daca1510.zip
Improved memory handling in FSM Baton.
Improved brightness ramp. (lower low) Added double-click to/from turbo in steady modes. Moved strobes to triple-click.
-rw-r--r--spaghetti-monster/baton.c58
1 files changed, 36 insertions, 22 deletions
diff --git a/spaghetti-monster/baton.c b/spaghetti-monster/baton.c
index ed2b444..ea8d49f 100644
--- a/spaghetti-monster/baton.c
+++ b/spaghetti-monster/baton.c
@@ -24,9 +24,9 @@
#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, };
+// moon + ../../bin/level_calc.py 2 6 7135 18 10 150 FET 1 10 1500
+uint8_t pwm1_modes[] = { 3, 18, 110, 255, 255, 255, 0, };
+uint8_t pwm2_modes[] = { 0, 0, 0, 9, 58, 138, 255, };
// FSM states
uint8_t off_state(EventPtr event, uint16_t arg);
@@ -34,11 +34,13 @@ 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;
+uint8_t memorized_level = 0;
+uint8_t actual_level = 0;
-void set_mode(uint8_t mode) {
- PWM1_LVL = pwm1_modes[mode];
- PWM2_LVL = pwm2_modes[mode];
+void set_mode(uint8_t lvl) {
+ actual_level = lvl;
+ PWM1_LVL = pwm1_modes[lvl];
+ PWM2_LVL = pwm2_modes[lvl];
}
uint8_t off_state(EventPtr event, uint16_t arg) {
@@ -49,14 +51,18 @@ uint8_t off_state(EventPtr event, uint16_t arg) {
// TODO: standby_mode();
return 0;
}
- // 1 click: regular mode
- else if (event == EV_1click) {
- set_state(steady_state, current_mode);
- return 0;
+ // hold (initially): go to lowest level, but allow abort for regular click
+ else if (event == EV_click1_press) {
+ set_mode(0);
}
// 1 click (before timeout): go to memorized level, but allow abort for double click
else if (event == EV_click1_release) {
- set_mode(current_mode);
+ set_mode(memorized_level);
+ }
+ // 1 click: regular mode
+ else if (event == EV_1click) {
+ set_state(steady_state, memorized_level);
+ return 0;
}
// 2 clicks: highest mode
else if (event == EV_2clicks) {
@@ -68,10 +74,6 @@ uint8_t off_state(EventPtr event, uint16_t arg) {
set_state(party_strobe_state, 0);
return 0;
}
- // hold (initially): go to lowest level, but allow abort for regular click
- else if (event == EV_click1_press) {
- set_mode(0);
- }
// hold: go to lowest level
else if (event == EV_click1_hold) {
set_state(steady_state, 0);
@@ -80,10 +82,12 @@ uint8_t off_state(EventPtr event, uint16_t arg) {
}
uint8_t steady_state(EventPtr event, uint16_t arg) {
- //static volatile uint8_t current_mode = 0;
// turn LED on when we first enter the mode
if (event == EV_enter_state) {
- current_mode = arg;
+ // remember this level, unless it's moon or turbo
+ if ((arg > 0) && (arg < sizeof(pwm1_modes)-1))
+ memorized_level = arg;
+ // use the requested level even if not memorized
set_mode(arg);
return 0;
}
@@ -92,16 +96,26 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
set_state(off_state, 0);
return 0;
}
- // 2 clicks: go to strobe modes
+ // 2 clicks: go to/from highest level
else if (event == EV_2clicks) {
+ if (actual_level < sizeof(pwm1_modes)-1) {
+ memorized_level = actual_level; // in case we're on moon
+ set_mode(sizeof(pwm1_modes)-1);
+ }
+ else
+ set_mode(memorized_level);
+ return 0;
+ }
+ // 3 clicks: go to strobe modes
+ else if (event == EV_3clicks) {
set_state(party_strobe_state, 0xff);
return 0;
}
// hold: change brightness
else if (event == EV_click1_hold) {
if ((arg % HOLD_TIMEOUT) == 0) {
- current_mode = (current_mode+1) % sizeof(pwm1_modes);
- set_mode(current_mode);
+ memorized_level = (memorized_level+1) % sizeof(pwm1_modes);
+ set_mode(memorized_level);
}
return 0;
}
@@ -137,7 +151,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, current_mode);
+ set_state(steady_state, memorized_level);
return 0;
}
// hold: change speed
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.