Skip to content

Commit

Permalink
separate out manual memories
Browse files Browse the repository at this point in the history
  • Loading branch information
SiteRelEnby authored and SiteRelEnby committed May 28, 2023
1 parent 8ac4307 commit a0e0db6
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 29 deletions.
2 changes: 1 addition & 1 deletion spaghetti-monster/anduril/anduril.c
Expand Up @@ -226,7 +226,7 @@ void setup() {
#if defined(USE_MANUAL_MEMORY) && defined(USE_MANUAL_MEMORY_TIMER)
// without this, initial boot-up brightness is wrong
// when manual mem is enabled with a non-zero timer
if (cfg.manual_memory) manual_memory_restore();
if (cfg.manual_memory_simple) manual_memory_restore();
#endif

#if defined(USE_CHANNEL_MODES)
Expand Down
4 changes: 2 additions & 2 deletions spaghetti-monster/anduril/build-all.sh
Expand Up @@ -33,8 +33,8 @@ for TARGET in cfg-*.h ; do
if [ -z "$ATTINY" ]; then ATTINY=85 ; fi

# try to compile
echo ../../../bin/build.sh $ATTINY "$UI" "-DCFG_H=${TARGET}"
../../../bin/build.sh $ATTINY "$UI" "-DCFG_H=${TARGET}"
echo ../../bin/build.sh $ATTINY "$UI" "-DCFG_H=${TARGET}"
../../bin/build.sh $ATTINY "$UI" "-DCFG_H=${TARGET}"

# track result, and rename compiled files
if [ 0 = $? ] ; then
Expand Down
8 changes: 6 additions & 2 deletions spaghetti-monster/anduril/load-save-config-fsm.h
Expand Up @@ -39,7 +39,9 @@ typedef struct Config {
uint8_t dont_ramp_after_moon;
#endif
#ifdef USE_MANUAL_MEMORY
uint8_t manual_memory;
uint8_t manual_memory_simple;
uint8_t manual_memory_stepped;
uint8_t manual_memory_smooth;
#ifdef USE_MANUAL_MEMORY_TIMER
uint8_t manual_memory_timer;
#endif
Expand All @@ -50,7 +52,9 @@ typedef struct Config {
uint8_t channel_mode;
uint8_t channel_modes_enabled;
#ifdef USE_MANUAL_MEMORY
uint8_t manual_memory_channel_mode;
uint8_t manual_memory_channel_mode_simple;
uint8_t manual_memory_channel_mode_smooth;
uint8_t manual_memory_channel_mode_stepped;
#endif
#ifdef DEFAULT_BLINK_CHANNEL
uint8_t blink_channel;
Expand Down
8 changes: 6 additions & 2 deletions spaghetti-monster/anduril/load-save-config.h
Expand Up @@ -60,7 +60,9 @@ Config cfg = {
.dont_ramp_after_moon = DEFAULT_DONT_RAMP_AFTER_MOON,

#ifdef USE_MANUAL_MEMORY
.manual_memory = DEFAULT_MANUAL_MEMORY,
.manual_memory_simple = DEFAULT_MANUAL_MEMORY,
.manual_memory_smooth = DEFAULT_MANUAL_MEMORY,
.manual_memory_stepped = DEFAULT_MANUAL_MEMORY,
#ifdef USE_MANUAL_MEMORY_TIMER
.manual_memory_timer = DEFAULT_MANUAL_MEMORY_TIMER,
#endif
Expand All @@ -75,7 +77,9 @@ Config cfg = {
.channel_modes_enabled = CHANNEL_MODES_ENABLED,
#ifdef USE_MANUAL_MEMORY
// reset w/ manual memory
.manual_memory_channel_mode = DEFAULT_CHANNEL_MODE,
.manual_memory_channel_mode_simple = DEFAULT_CHANNEL_MODE,
.manual_memory_channel_mode_stepped = DEFAULT_CHANNEL_MODE,
.manual_memory_channel_mode_smooth = DEFAULT_CHANNEL_MODE,
#endif
#ifdef DEFAULT_BLINK_CHANNEL
// blink numbers in a specific channel (user configurable)
Expand Down
25 changes: 21 additions & 4 deletions spaghetti-monster/anduril/lockout-mode.c
Expand Up @@ -23,7 +23,8 @@ uint8_t lockout_state(Event event, uint16_t arg) {
} else { // 2nd click or later
if (cfg.ramp_floors[1] > lvl) lvl = cfg.ramp_floors[1];
#ifdef USE_MANUAL_MEMORY
if (cfg.manual_memory) lvl = cfg.manual_memory;
uint8_t manual_mem = (get_manual_mem_level());
if (manual_mem) { lvl = manual_mem; }
#endif
}
set_level(lvl);
Expand Down Expand Up @@ -67,7 +68,9 @@ uint8_t lockout_state(Event event, uint16_t arg) {
if (ticks_since_on < 255) ticks_since_on ++;
#ifdef USE_MANUAL_MEMORY_TIMER
// reset to manual memory level when timer expires
if (cfg.manual_memory &&
uint8_t manual_mem = (get_manual_mem_level());

if (manual_mem &&
(arg >= (cfg.manual_memory_timer * SLEEP_TICKS_PER_MINUTE))) {
manual_memory_restore();
}
Expand All @@ -93,8 +96,9 @@ uint8_t lockout_state(Event event, uint16_t arg) {
#if defined(USE_MANUAL_MEMORY) && !defined(USE_MANUAL_MEMORY_TIMER)
// this clause probably isn't used by any configs any more
// but is included just in case someone configures it this way
if (cfg.manual_memory)
set_state(steady_state, cfg.manual_memory);
uint8_t manual_mem = get_manual_mem_level();
if (manual_mem)
set_state(steady_state, manual_mem);
else
#endif
set_state(steady_state, memorized_level);
Expand Down Expand Up @@ -206,6 +210,19 @@ uint8_t lockout_state(Event event, uint16_t arg) {
return EVENT_NOT_HANDLED;
}

#ifdef USE_MANUAL_MEMORY
uint8_t get_manual_mem_level(){
if (cfg.simple_ui_active){
if (cfg.manual_memory_simple) { return cfg.manual_memory_simple; }
} else
if (cfg.ramp_style){
if (cfg.manual_memory_stepped) { return cfg.manual_memory_stepped; }
} else
if (cfg.manual_memory_smooth) { return cfg.manual_memory_smooth; }
return 0;
}
#endif

#ifdef USE_AUTOLOCK
// set the auto-lock timer to N minutes, where N is the number of clicks
void autolock_config_save(uint8_t step, uint8_t value) {
Expand Down
4 changes: 4 additions & 0 deletions spaghetti-monster/anduril/lockout-mode.h
Expand Up @@ -4,6 +4,10 @@

#pragma once

#ifdef USE_MANUAL_MEMORY
uint8_t get_manual_mem_level();
#endif

// soft lockout
uint8_t lockout_state(Event event, uint16_t arg);

Expand Down
9 changes: 7 additions & 2 deletions spaghetti-monster/anduril/off-mode.c
Expand Up @@ -51,7 +51,9 @@ uint8_t off_state(Event event, uint16_t arg) {
if (ticks_since_on < 255) ticks_since_on ++;
#ifdef USE_MANUAL_MEMORY_TIMER
// reset to manual memory level when timer expires
if (cfg.manual_memory &&
//if (cfg.manual_memory &&
uint8_t manual_mem = get_manual_mem_level();
if (manual_mem &&
(arg >= (cfg.manual_memory_timer * SLEEP_TICKS_PER_MINUTE))) {
manual_memory_restore();
}
Expand Down Expand Up @@ -119,7 +121,8 @@ uint8_t off_state(Event event, uint16_t arg) {
#if defined(USE_MANUAL_MEMORY) && !defined(USE_MANUAL_MEMORY_TIMER)
// this clause probably isn't used by any configs any more
// but is included just in case someone configures it this way
if (cfg.manual_memory) {
uint8_t manual_mem = get_manual_mem_level();
if (manual_mem) {
manual_memory_restore();
}
#endif
Expand Down Expand Up @@ -225,6 +228,7 @@ uint8_t off_state(Event event, uint16_t arg) {
if (cfg.simple_ui_active) { // turn off simple UI
blink_once();
cfg.simple_ui_active = 0;
manual_memory_restore(); //necessary as otherwise the first use of manual mem when switching in/out of simple is wrong
save_config();
}
else { // configure simple UI ramp
Expand Down Expand Up @@ -316,6 +320,7 @@ uint8_t off_state(Event event, uint16_t arg) {
else if (event == EV_10clicks) {
blink_once();
cfg.simple_ui_active = 1;
manual_memory_restore(); //necessary as otherwise the first use of manual mem when switching in/out of simple is wrong
save_config();
return TRANS_RIGHTS_ARE_HUMAN_RIGHTS;
}
Expand Down
39 changes: 27 additions & 12 deletions spaghetti-monster/anduril/ramp-mode.c
Expand Up @@ -357,6 +357,16 @@ uint8_t steady_state(Event event, uint16_t arg) {
#endif // ifdef USE_SET_LEVEL_GRADUALLY
#endif // ifdef USE_THERMAL_REGULATION

#ifdef USE_MANUAL_MEMORY
else if (((cfg.simple_ui_active) && (event == EV_8clicks)) || (event == EV_10clicks)) {
// turn on manual memory and save current brightness
manual_memory_save();
save_config();
blink_once();
return TRANS_RIGHTS_ARE_HUMAN_RIGHTS;
}
#endif

////////// Every action below here is blocked in the simple UI //////////
// That is, unless we specifically want to enable 3C for smooth/stepped selection in Simple UI
#if defined(USE_SIMPLE_UI) && !defined(USE_SIMPLE_UI_RAMPING_TOGGLE)
Expand Down Expand Up @@ -463,13 +473,6 @@ uint8_t steady_state(Event event, uint16_t arg) {
#endif

#ifdef USE_MANUAL_MEMORY
else if (event == EV_10clicks) {
// turn on manual memory and save current brightness
manual_memory_save();
save_config();
blink_once();
return TRANS_RIGHTS_ARE_HUMAN_RIGHTS;
}
else if (event == EV_click10_hold) {
#ifdef USE_RAMP_EXTRAS_CONFIG
// let user configure a bunch of extra ramp options
Expand Down Expand Up @@ -550,7 +553,11 @@ uint8_t simple_ui_config_state(Event event, uint16_t arg) {
#ifdef USE_RAMP_EXTRAS_CONFIG
void ramp_extras_config_save(uint8_t step, uint8_t value) {
// item 1: disable manual memory, go back to automatic
if (1 == step) { cfg.manual_memory = 0; }
if (1 == step) {
if (cfg.simple_ui_active){ cfg.manual_memory_simple = 0;} else
if (cfg.ramp_style){ cfg.manual_memory_stepped = 0;} else {
cfg.manual_memory_smooth = 0; }
}

#ifdef USE_MANUAL_MEMORY_TIMER
// item 2: set manual memory timer duration
Expand Down Expand Up @@ -663,9 +670,12 @@ void set_level_and_therm_target(uint8_t level) {
#endif

void manual_memory_restore() {
memorized_level = cfg.manual_memory;
memorized_level = get_manual_mem_level();
#if NUM_CHANNEL_MODES > 1
cfg.channel_mode = cfg.manual_memory_channel_mode;
if (cfg.simple_ui_active){ cfg.channel_mode = cfg.manual_memory_channel_mode_simple; } else
if (cfg.ramp_style) { cfg.channel_mode = cfg.manual_memory_channel_mode_stepped; } else
{ cfg.channel_mode = cfg.manual_memory_channel_mode_smooth; }
//cfg.channel_mode = cfg.manual_memory_channel_mode;
#endif
#ifdef USE_CHANNEL_MODE_ARGS
for (uint8_t i=0; i<NUM_CHANNEL_MODES; i++)
Expand All @@ -674,9 +684,14 @@ void manual_memory_restore() {
}

void manual_memory_save() {
cfg.manual_memory = actual_level;
if (cfg.simple_ui_active){ cfg.manual_memory_simple = actual_level; } else
if (cfg.ramp_style) { cfg.manual_memory_stepped = actual_level; } else
{ cfg.manual_memory_smooth = actual_level; }

#if NUM_CHANNEL_MODES > 1
cfg.manual_memory_channel_mode = cfg.channel_mode;
if (cfg.simple_ui_active){ cfg.manual_memory_channel_mode_simple = cfg.channel_mode; } else
if (cfg.ramp_style) { cfg.manual_memory_channel_mode_stepped = cfg.channel_mode; } else
{ cfg.manual_memory_channel_mode_smooth = cfg.channel_mode; }
#endif
#ifdef USE_CHANNEL_MODE_ARGS
for (uint8_t i=0; i<NUM_CHANNEL_MODES; i++)
Expand Down
5 changes: 1 addition & 4 deletions spaghetti-monster/anduril/version.h
@@ -1,4 +1 @@
// this file is replaced automatically by the build script
// set your own date here if you're not using the build script
// otherwise, default to first human contact with the moon
#define VERSION_NUMBER "19690720"
#define VERSION_NUMBER "20230528"

0 comments on commit a0e0db6

Please sign in to comment.