aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
Diffstat (limited to 'spaghetti-monster')
-rw-r--r--spaghetti-monster/anduril/anduril.c114
-rw-r--r--spaghetti-monster/fsm-misc.c28
-rw-r--r--spaghetti-monster/fsm-misc.h5
-rw-r--r--spaghetti-monster/fsm-ramping.c7
4 files changed, 79 insertions, 75 deletions
diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c
index 330f107..3559235 100644
--- a/spaghetti-monster/anduril/anduril.c
+++ b/spaghetti-monster/anduril/anduril.c
@@ -20,14 +20,15 @@
/********* User-configurable options *********/
// Physical driver type
-#define FSM_EMISAR_D4_DRIVER
+//#define FSM_EMISAR_D4_DRIVER
+#define FSM_BLF_Q8_DRIVER
//#define FSM_FW3A_DRIVER
#define USE_LVP
#define USE_THERMAL_REGULATION
#define DEFAULT_THERM_CEIL 50
#define USE_SET_LEVEL_GRADUALLY
-#define BLINK_AT_CHANNEL_BOUNDARIES
+//#define BLINK_AT_CHANNEL_BOUNDARIES
//#define BLINK_AT_RAMP_FLOOR
#define BLINK_AT_RAMP_CEILING
#define BATTCHECK_VpT
@@ -36,7 +37,6 @@
#define GOODNIGHT_LEVEL 24 // ~11 lm
#define USE_REVERSING
//#define START_AT_MEMORIZED_LEVEL
-#define USE_INDICATOR_LED
/********* Configure SpaghettiMonster *********/
#define USE_DELAY_ZERO
@@ -45,6 +45,18 @@
#define MAX_BIKING_LEVEL 120 // should be 127 or less
#define USE_BATTCHECK
#define MAX_CLICKS 5
+#define USE_IDLE_MODE
+#define USE_DYNAMIC_UNDERCLOCKING // cut clock speed at very low modes for better efficiency
+
+// specific settings for known driver types
+#ifdef FSM_BLF_Q8_DRIVER
+#define USE_INDICATOR_LED
+#define VOLTAGE_FUDGE_FACTOR 7 // add 0.35V
+#elif defined(FSM_EMISAR_D4_DRIVER)
+#define VOLTAGE_FUDGE_FACTOR 5 // add 0.25V
+#endif
+
+// try to auto-detect how many eeprom bytes
#define USE_EEPROM
#ifdef USE_INDICATOR_LED
#define EEPROM_BYTES 13
@@ -57,8 +69,6 @@
#define USE_EEPROM_WL
#define EEPROM_WL_BYTES 1
#endif
-#define USE_IDLE_MODE
-#define USE_DYNAMIC_UNDERCLOCKING // cut clock speed at very low modes for better efficiency
#include "spaghetti-monster.h"
@@ -99,10 +109,6 @@ volatile uint8_t number_entry_value;
void blink_confirm(uint8_t num);
-#ifdef USE_INDICATOR_LED
-void indicator_led(uint8_t lvl);
-#endif
-
// remember stuff even after battery was changed
void load_config();
void save_config();
@@ -161,7 +167,6 @@ volatile uint8_t beacon_seconds = 2;
uint8_t off_state(EventPtr event, uint16_t arg) {
- static uint8_t ticks_spent_awake = 0;
// turn emitter off when entering state
if (event == EV_enter_state) {
set_level(0);
@@ -170,16 +175,15 @@ uint8_t off_state(EventPtr event, uint16_t arg) {
#endif
// sleep while off (lower power use)
go_to_standby = 1;
- ticks_spent_awake = 0;
return MISCHIEF_MANAGED;
}
// go back to sleep eventually if we got bumped but didn't leave "off" state
- // FIXME: can I just use arg instead of ticks_spent_awake?
else if (event == EV_tick) {
- ticks_spent_awake ++;
- if (ticks_spent_awake > 240) {
- ticks_spent_awake = 0;
+ if (arg > TICKS_PER_SECOND*2) {
go_to_standby = 1;
+ #ifdef USE_INDICATOR_LED
+ indicator_led(indicator_led_mode & 0x03);
+ #endif
}
return MISCHIEF_MANAGED;
}
@@ -188,6 +192,20 @@ uint8_t off_state(EventPtr event, uint16_t arg) {
set_level(nearest_level(1));
return MISCHIEF_MANAGED;
}
+ // hold: go to lowest level
+ else if (event == EV_click1_hold) {
+ // don't start ramping immediately;
+ // give the user time to release at moon level
+ if (arg >= HOLD_TIMEOUT) {
+ set_state(steady_state, 1);
+ }
+ return MISCHIEF_MANAGED;
+ }
+ // hold, release quickly: go to lowest level
+ else if (event == EV_click1_hold_release) {
+ set_state(steady_state, 1);
+ return MISCHIEF_MANAGED;
+ }
// 1 click (before timeout): go to memorized level, but allow abort for double click
else if (event == EV_click1_release) {
set_level(nearest_level(memorized_level));
@@ -203,6 +221,11 @@ uint8_t off_state(EventPtr event, uint16_t arg) {
set_level(0);
return MISCHIEF_MANAGED;
}
+ // click, hold: go to highest level (for ramping down)
+ else if (event == EV_click2_hold) {
+ set_state(steady_state, MAX_LEVEL);
+ return MISCHIEF_MANAGED;
+ }
// 2 clicks: highest mode
else if (event == EV_2clicks) {
set_state(steady_state, nearest_level(MAX_LEVEL));
@@ -232,25 +255,6 @@ uint8_t off_state(EventPtr event, uint16_t arg) {
set_state(momentary_state, 0);
return MISCHIEF_MANAGED;
}
- // hold: go to lowest level
- else if (event == EV_click1_hold) {
- // don't start ramping immediately;
- // give the user time to release at moon level
- if (arg >= HOLD_TIMEOUT) {
- set_state(steady_state, 1);
- }
- return MISCHIEF_MANAGED;
- }
- // hold, release quickly: go to lowest level
- else if (event == EV_click1_hold_release) {
- set_state(steady_state, 1);
- return MISCHIEF_MANAGED;
- }
- // click, hold: go to highest level (for ramping down)
- else if (event == EV_click2_hold) {
- set_state(steady_state, MAX_LEVEL);
- return MISCHIEF_MANAGED;
- }
return EVENT_NOT_HANDLED;
}
@@ -654,8 +658,6 @@ uint8_t goodnight_state(EventPtr event, uint16_t arg) {
uint8_t lockout_state(EventPtr event, uint16_t arg) {
- static uint8_t ticks_spent_awake = 0;
-
#ifdef MOON_DURING_LOCKOUT_MODE
// momentary(ish) moon mode during lockout
// not all presses will be counted;
@@ -668,7 +670,6 @@ uint8_t lockout_state(EventPtr event, uint16_t arg) {
uint8_t lvl = ramp_smooth_floor;
if (ramp_discrete_floor < lvl) lvl = ramp_discrete_floor;
set_level(lvl);
- ticks_spent_awake = 0;
}
else if ((last == A_RELEASE) || (last == A_RELEASE_TIMEOUT)) {
set_level(0);
@@ -686,9 +687,7 @@ uint8_t lockout_state(EventPtr event, uint16_t arg) {
} else
#endif
if (event == EV_tick) {
- ticks_spent_awake ++;
- if (ticks_spent_awake > 180) {
- ticks_spent_awake = 0;
+ if (arg > TICKS_PER_SECOND*2) {
go_to_standby = 1;
#ifdef USE_INDICATOR_LED
indicator_led(indicator_led_mode >> 2);
@@ -1021,32 +1020,6 @@ uint8_t pseudo_rand() {
#endif
-#ifdef USE_INDICATOR_LED
-void indicator_led(uint8_t lvl) {
- switch (lvl) {
- case 0: // indicator off
- DDRB &= 0xff ^ (1 << AUXLED_PIN);
- PORTB &= 0xff ^ (1 << AUXLED_PIN);
- break;
- case 1: // indicator low
- DDRB &= 0xff ^ (1 << AUXLED_PIN);
- PORTB |= (1 << AUXLED_PIN);
- break;
- default: // indicator high
- DDRB |= (1 << AUXLED_PIN);
- PORTB |= (1 << AUXLED_PIN);
- break;
- }
-}
-
-void indicator_led_auto() {
- if (actual_level > MAX_1x7135) indicator_led(2);
- else if (actual_level > 0) indicator_led(1);
- else indicator_led(0);
-}
-#endif // USE_INDICATOR_LED
-
-
void load_config() {
if (load_eeprom()) {
ramp_style = eeprom[0];
@@ -1199,9 +1172,6 @@ void loop() {
brightness += pseudo_rand() % brightness; // 2 to 159 now (w/ low bias)
if (brightness > MAX_LEVEL) brightness = MAX_LEVEL;
set_level(brightness);
- #ifdef USE_INDICATOR_LED
- indicator_led_auto();
- #endif
if (! nice_delay_ms(rand_time)) return;
// decrease the brightness somewhat more gradually, like lightning
@@ -1212,9 +1182,6 @@ void loop() {
brightness -= stepdown;
if (brightness < 0) brightness = 0;
set_level(brightness);
- #ifdef USE_INDICATOR_LED
- indicator_led_auto();
- #endif
/*
if ((brightness < MAX_LEVEL/2) && (! (pseudo_rand() & 15))) {
brightness <<= 1;
@@ -1233,9 +1200,6 @@ void loop() {
rand_time = 1<<(pseudo_rand()%13);
rand_time += pseudo_rand()%rand_time;
set_level(0);
- #ifdef USE_INDICATOR_LED
- indicator_led_auto();
- #endif
nice_delay_ms(rand_time);
}
diff --git a/spaghetti-monster/fsm-misc.c b/spaghetti-monster/fsm-misc.c
index 1b8f864..acef28c 100644
--- a/spaghetti-monster/fsm-misc.c
+++ b/spaghetti-monster/fsm-misc.c
@@ -109,4 +109,32 @@ uint8_t blink_num(uint8_t num) {
}
#endif
+#ifdef USE_INDICATOR_LED
+void indicator_led(uint8_t lvl) {
+ switch (lvl) {
+ case 0: // indicator off
+ DDRB &= 0xff ^ (1 << AUXLED_PIN);
+ PORTB &= 0xff ^ (1 << AUXLED_PIN);
+ break;
+ case 1: // indicator low
+ DDRB &= 0xff ^ (1 << AUXLED_PIN);
+ PORTB |= (1 << AUXLED_PIN);
+ break;
+ default: // indicator high
+ DDRB |= (1 << AUXLED_PIN);
+ PORTB |= (1 << AUXLED_PIN);
+ break;
+ }
+}
+
+/*
+void indicator_led_auto() {
+ if (actual_level > MAX_1x7135) indicator_led(2);
+ else if (actual_level > 0) indicator_led(1);
+ else indicator_led(0);
+}
+*/
+#endif // USE_INDICATOR_LED
+
+
#endif
diff --git a/spaghetti-monster/fsm-misc.h b/spaghetti-monster/fsm-misc.h
index 5e4f3d6..4e0eb4f 100644
--- a/spaghetti-monster/fsm-misc.h
+++ b/spaghetti-monster/fsm-misc.h
@@ -42,4 +42,9 @@ uint8_t blink(uint8_t num, uint8_t speed);
#endif
*/
+#ifdef USE_INDICATOR_LED
+void indicator_led(uint8_t lvl);
+#endif
+
+
#endif
diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c
index 11e56a5..ec132ae 100644
--- a/spaghetti-monster/fsm-ramping.c
+++ b/spaghetti-monster/fsm-ramping.c
@@ -28,6 +28,13 @@ void set_level(uint8_t level) {
#ifdef USE_SET_LEVEL_GRADUALLY
gradual_target = level;
#endif
+ #ifdef USE_INDICATOR_LED
+ if (! go_to_standby)
+ indicator_led((level > 0) + (level > MAX_1x7135));
+ //if (level > MAX_1x7135) indicator_led(2);
+ //else if (level > 0) indicator_led(1);
+ //else if (! go_to_standby) indicator_led(0);
+ #endif
//TCCR0A = PHASE;
if (level == 0) {
#if PWM_CHANNELS >= 1
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.