aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/rampingios
diff options
context:
space:
mode:
authorSelene ToyKeeper2019-04-08 12:11:41 -0600
committerSelene ToyKeeper2019-04-08 12:11:41 -0600
commit43a206cd59ad4da6fa8cfc4ac15aea6085651cab (patch)
tree79d8a31a545859884485cd7836c6d1ba3e5b9b0e /spaghetti-monster/rampingios
parentmerged trunk (diff)
parentfixed bug: hold-from-off then release and hold failed in stepped ramp (diff)
downloadanduril-43a206cd59ad4da6fa8cfc4ac15aea6085651cab.tar.gz
anduril-43a206cd59ad4da6fa8cfc4ac15aea6085651cab.tar.bz2
anduril-43a206cd59ad4da6fa8cfc4ac15aea6085651cab.zip
merged fsm branch, resolved conflicts in anduril.c, did some quick testing
Diffstat (limited to 'spaghetti-monster/rampingios')
-rw-r--r--spaghetti-monster/rampingios/rampingiosv3.c131
1 files changed, 107 insertions, 24 deletions
diff --git a/spaghetti-monster/rampingios/rampingiosv3.c b/spaghetti-monster/rampingios/rampingiosv3.c
index 399bcf0..e4eb2fa 100644
--- a/spaghetti-monster/rampingios/rampingiosv3.c
+++ b/spaghetti-monster/rampingios/rampingiosv3.c
@@ -1,7 +1,7 @@
/*
* RampingIOS V3: FSM-based version of RampingIOS V2 UI, with upgrades.
*
- * Copyright (C) 2018 Selene ToyKeeper
+ * Copyright (C) 2018-2019 Selene ToyKeeper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,13 +26,14 @@
// parameters for this defined below or per-driver
#define USE_THERMAL_REGULATION
#define DEFAULT_THERM_CEIL 45 // try not to get hotter than this
+#define USE_TENCLICK_THERMAL_CONFIG // ten clicks from off -> thermal config mode
// short blip when crossing from "click" to "hold" from off
// (helps the user hit moon mode exactly, instead of holding too long
// or too short)
#define MOON_TIMING_HINT
// short blips while ramping
-#define BLINK_AT_CHANNEL_BOUNDARIES
+#define BLINK_AT_RAMP_MIDDLE
//#define BLINK_AT_RAMP_FLOOR
#define BLINK_AT_RAMP_CEILING
//#define BLINK_AT_STEPS // whenever a discrete ramp mode is passed in smooth mode
@@ -46,6 +47,12 @@
//#define BATTCHECK_8bars // FIXME: breaks build
//#define BATTCHECK_4bars // FIXME: breaks build
+// enable beacon mode
+#define USE_BEACON_MODE
+
+// make the ramps configurable by the user
+#define USE_RAMP_CONFIG
+
/***** specific settings for known driver types *****/
#include "tk.h"
#include incfile(CONFIGFILE)
@@ -109,7 +116,9 @@ uint8_t config_state_base(Event event, uint16_t arg,
uint8_t config_state_values[MAX_CONFIG_VALUES];
// ramping mode and its related config mode
uint8_t steady_state(Event event, uint16_t arg);
+#ifdef USE_RAMP_CONFIG
uint8_t ramp_config_state(Event event, uint16_t arg);
+#endif
#ifdef USE_BATTCHECK
uint8_t battcheck_state(Event event, uint16_t arg);
#endif
@@ -117,11 +126,15 @@ uint8_t battcheck_state(Event event, uint16_t arg);
uint8_t tempcheck_state(Event event, uint16_t arg);
uint8_t thermal_config_state(Event event, uint16_t arg);
#endif
+#ifdef USE_BEACON_MODE
// beacon mode and its related config mode
uint8_t beacon_state(Event event, uint16_t arg);
uint8_t beacon_config_state(Event event, uint16_t arg);
+#endif
// soft lockout
#define MOON_DURING_LOCKOUT_MODE
+// if enabled, 2nd lockout click goes to the other ramp's floor level
+//#define LOCKOUT_MOON_FANCY
uint8_t lockout_state(Event event, uint16_t arg);
// momentary / signalling mode
uint8_t momentary_state(Event event, uint16_t arg);
@@ -164,8 +177,28 @@ void save_config();
#define RAMP_DISCRETE_STEPS 7
#endif
+// mile marker(s) partway up the ramp
+// default: blink only at border between regulated and FET
+#ifdef BLINK_AT_RAMP_MIDDLE
+ #if PWM_CHANNELS >= 3
+ #ifndef BLINK_AT_RAMP_MIDDLE_1
+ #define BLINK_AT_RAMP_MIDDLE_1 MAX_Nx7135
+ #ifndef BLINK_AT_RAMP_MIDDLE_2
+ #define BLINK_AT_RAMP_MIDDLE_2 MAX_1x7135
+ #endif
+ #endif
+ #else
+ #ifndef BLINK_AT_RAMP_MIDDLE_1
+ #define BLINK_AT_RAMP_MIDDLE_1 MAX_1x7135
+ #endif
+ #endif
+#endif
+
// brightness control
-uint8_t memorized_level = MAX_1x7135;
+#ifndef DEFAULT_LEVEL
+#define DEFAULT_LEVEL MAX_1x7135
+#endif
+uint8_t memorized_level = DEFAULT_LEVEL;
// smooth vs discrete ramping
volatile uint8_t ramp_style = 0; // 0 = smooth, 1 = discrete
volatile uint8_t ramp_smooth_floor = RAMP_SMOOTH_FLOOR;
@@ -201,8 +234,10 @@ uint8_t nearest_level(int16_t target);
uint8_t target_level = 0;
#endif
+#ifdef USE_BEACON_MODE
// beacon timing
volatile uint8_t beacon_seconds = 2;
+#endif
uint8_t off_state(Event event, uint16_t arg) {
@@ -247,7 +282,7 @@ uint8_t off_state(Event event, uint16_t arg) {
// let the user know they can let go now to stay at moon
uint8_t temp = actual_level;
set_level(0);
- delay_4ms(2);
+ delay_4ms(3);
set_level(temp);
} else
#endif
@@ -321,11 +356,13 @@ uint8_t off_state(Event event, uint16_t arg) {
set_state(beacon_state, 0);
return MISCHIEF_MANAGED;
}
+ #ifdef USE_TENCLICK_THERMAL_CONFIG
// 10 clicks: thermal config mode
else if (event == EV_10clicks) {
push_state(thermal_config_state, 0);
return MISCHIEF_MANAGED;
}
+ #endif
return EVENT_NOT_HANDLED;
}
@@ -401,11 +438,13 @@ uint8_t steady_state(Event event, uint16_t arg) {
set_level(memorized_level);
return MISCHIEF_MANAGED;
}
+ #ifdef USE_RAMP_CONFIG
// 4 clicks: configure this ramp mode
else if (event == EV_4clicks) {
push_state(ramp_config_state, 0);
return MISCHIEF_MANAGED;
}
+ #endif
// hold: change brightness (brighter)
else if (event == EV_click1_hold) {
// ramp slower in discrete mode
@@ -425,15 +464,15 @@ uint8_t steady_state(Event event, uint16_t arg) {
#ifdef USE_THERMAL_REGULATION
target_level = memorized_level;
#endif
- #if defined(BLINK_AT_RAMP_CEILING) || defined(BLINK_AT_CHANNEL_BOUNDARIES)
+ #if defined(BLINK_AT_RAMP_CEILING) || defined(BLINK_AT_RAMP_MIDDLE)
// only blink once for each threshold
if ((memorized_level != actual_level) && (
0 // for easier syntax below
- #ifdef BLINK_AT_CHANNEL_BOUNDARIES
- || (memorized_level == MAX_1x7135)
- #if PWM_CHANNELS >= 3
- || (memorized_level == MAX_Nx7135)
+ #ifdef BLINK_AT_RAMP_MIDDLE_1
+ || (memorized_level == BLINK_AT_RAMP_MIDDLE_1)
#endif
+ #ifdef BLINK_AT_RAMP_MIDDLE_2
+ || (memorized_level == BLINK_AT_RAMP_MIDDLE_2)
#endif
#ifdef BLINK_AT_RAMP_CEILING
|| (memorized_level == mode_max)
@@ -487,15 +526,15 @@ uint8_t steady_state(Event event, uint16_t arg) {
#ifdef USE_THERMAL_REGULATION
target_level = memorized_level;
#endif
- #if defined(BLINK_AT_RAMP_FLOOR) || defined(BLINK_AT_CHANNEL_BOUNDARIES)
+ #if defined(BLINK_AT_RAMP_FLOOR) || defined(BLINK_AT_RAMP_MIDDLE)
// only blink once for each threshold
if ((memorized_level != actual_level) && (
0 // for easier syntax below
- #ifdef BLINK_AT_CHANNEL_BOUNDARIES
- || (memorized_level == MAX_1x7135)
- #if PWM_CHANNELS >= 3
- || (memorized_level == MAX_Nx7135)
+ #ifdef BLINK_AT_RAMP_MIDDLE_1
+ || (memorized_level == BLINK_AT_RAMP_MIDDLE_1)
#endif
+ #ifdef BLINK_AT_RAMP_MIDDLE_2
+ || (memorized_level == BLINK_AT_RAMP_MIDDLE_2)
#endif
#ifdef BLINK_AT_RAMP_FLOOR
|| (memorized_level == mode_min)
@@ -669,6 +708,7 @@ uint8_t tempcheck_state(Event event, uint16_t arg) {
#endif
+#ifdef USE_BEACON_MODE
uint8_t beacon_state(Event event, uint16_t arg) {
// 1 click: off
if (event == EV_1click) {
@@ -684,6 +724,7 @@ uint8_t beacon_state(Event event, uint16_t arg) {
}
return EVENT_NOT_HANDLED;
}
+#endif // #ifdef USE_BEACON_MODE
uint8_t lockout_state(Event event, uint16_t arg) {
@@ -696,6 +737,13 @@ uint8_t lockout_state(Event event, uint16_t arg) {
uint8_t lvl = ramp_smooth_floor;
if (ramp_discrete_floor < lvl) lvl = ramp_discrete_floor;
set_level(lvl);
+ #elif defined(LOCKOUT_MOON_FANCY)
+ uint8_t levels[] = { ramp_smooth_floor, ramp_discrete_floor };
+ if ((event & 0x0f) == 2) {
+ set_level(levels[ramp_style^1]);
+ } else {
+ set_level(levels[ramp_style]);
+ }
#else
// Use moon from current ramp
set_level(nearest_level(1));
@@ -858,6 +906,7 @@ uint8_t config_state_base(Event event, uint16_t arg,
return EVENT_HANDLED;
}
+#ifdef USE_RAMP_CONFIG
void ramp_config_save() {
// parse values
uint8_t val;
@@ -889,6 +938,7 @@ uint8_t ramp_config_state(Event event, uint16_t arg) {
return config_state_base(event, arg,
num_config_steps, ramp_config_save);
}
+#endif // #ifdef USE_RAMP_CONFIG
#ifdef USE_THERMAL_REGULATION
@@ -915,9 +965,10 @@ uint8_t thermal_config_state(Event event, uint16_t arg) {
return config_state_base(event, arg,
2, thermal_config_save);
}
-#endif
+#endif // #ifdef USE_THERMAL_REGULATION
+#ifdef USE_BEACON_MODE
void beacon_config_save() {
// parse values
uint8_t val = config_state_values[0];
@@ -931,6 +982,15 @@ uint8_t beacon_config_state(Event event, uint16_t arg) {
1, beacon_config_save);
}
+inline void beacon_mode_iter() {
+ // one iteration of main loop()
+ set_level(memorized_level);
+ nice_delay_ms(500);
+ set_level(0);
+ nice_delay_ms(((beacon_seconds) * 1000) - 500);
+}
+#endif // #ifdef USE_BEACON_MODE
+
uint8_t number_entry_state(Event event, uint16_t arg) {
static uint8_t value;
@@ -1063,12 +1123,23 @@ void blink_confirm(uint8_t num) {
#if defined(USE_INDICATOR_LED) && defined(TICK_DURING_STANDBY)
// beacon-like mode for the indicator LED
void indicator_blink(uint8_t arg) {
+ #ifdef USE_FANCIER_BLINKING_INDICATOR
+
+ // fancy blink, set off/low/high levels here:
+ uint8_t seq[] = {0, 1, 2, 1, 0, 0, 0, 0,
+ 0, 0, 1, 0, 0, 0, 0, 0};
+ indicator_led(seq[arg & 15]);
+
+ #else // basic blink, 1/8th duty cycle
+
if (! (arg & 7)) {
indicator_led(2);
}
else {
indicator_led(0);
}
+
+ #endif
}
#endif
@@ -1076,12 +1147,16 @@ void indicator_blink(uint8_t arg) {
void load_config() {
if (load_eeprom()) {
ramp_style = eeprom[0];
+ #ifdef USE_RAMP_CONFIG
ramp_smooth_floor = eeprom[1];
ramp_smooth_ceil = eeprom[2];
ramp_discrete_floor = eeprom[3];
ramp_discrete_ceil = eeprom[4];
ramp_discrete_steps = eeprom[5];
+ #endif
+ #ifdef USE_BEACON_MODE
beacon_seconds = eeprom[6];
+ #endif
#ifdef USE_THERMAL_REGULATION
therm_ceil = eeprom[EEPROM_BYTES_BASE];
therm_cal_offset = eeprom[EEPROM_BYTES_BASE+1];
@@ -1094,12 +1169,16 @@ void load_config() {
void save_config() {
eeprom[0] = ramp_style;
+ #ifdef USE_RAMP_CONFIG
eeprom[1] = ramp_smooth_floor;
eeprom[2] = ramp_smooth_ceil;
eeprom[3] = ramp_discrete_floor;
eeprom[4] = ramp_discrete_ceil;
eeprom[5] = ramp_discrete_steps;
+ #endif
+ #ifdef USE_BEACON_MODE
eeprom[6] = beacon_seconds;
+ #endif
#ifdef USE_THERMAL_REGULATION
eeprom[EEPROM_BYTES_BASE ] = therm_ceil;
eeprom[EEPROM_BYTES_BASE+1] = therm_cal_offset;
@@ -1114,8 +1193,12 @@ void save_config() {
void low_voltage() {
StatePtr state = current_state;
+ // TODO: turn off aux LED(s) when power is really low
+
+ if (0) {} // placeholder
+
// in normal mode, step down or turn off
- if (state == steady_state) {
+ else if (state == steady_state) {
if (actual_level > 1) {
uint8_t lvl = (actual_level >> 1) + (actual_level >> 2);
set_level(lvl);
@@ -1161,21 +1244,21 @@ void loop() {
battcheck();
}
#endif
+
+ #ifdef USE_BEACON_MODE
+ else if (state == beacon_state) {
+ beacon_mode_iter();
+ }
+ #endif
+
#ifdef USE_THERMAL_REGULATION
- // TODO: blink out therm_ceil during thermal_config_state
+ // TODO: blink out therm_ceil during thermal_config_state?
else if (state == tempcheck_state) {
blink_num(temperature>>1);
nice_delay_ms(1000);
}
#endif
- else if (state == beacon_state) {
- set_level(memorized_level);
- nice_delay_ms(500);
- set_level(0);
- nice_delay_ms(((beacon_seconds) * 1000) - 500);
- }
-
#ifdef USE_IDLE_MODE
else {
// doze until next clock tick
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.