aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-04-15 19:11:58 -0600
committerSelene ToyKeeper2023-04-15 19:11:58 -0600
commit3ae85eabf6fc665fb0be9276013f8c603d6a6dc9 (patch)
tree444f4b6a474673fe11fd419a934311197f0f0c57 /spaghetti-monster
parentLT1S Pro: added manual memory with a timer by default, like on SP10 Pro (diff)
downloadanduril-3ae85eabf6fc665fb0be9276013f8c603d6a6dc9.tar.gz
anduril-3ae85eabf6fc665fb0be9276013f8c603d6a6dc9.tar.bz2
anduril-3ae85eabf6fc665fb0be9276013f8c603d6a6dc9.zip
adapted smooth-sunset patch from SammysHP
https://github.com/SammysHP/flashlight-firmware/tree/smooth-sunset https://github.com/SammysHP/flashlight-firmware/compare/anduril2...smooth-sunset (also shortened file headers, as long as I was touching those files)
Diffstat (limited to 'spaghetti-monster')
-rw-r--r--spaghetti-monster/anduril/ramp-mode.c49
-rw-r--r--spaghetti-monster/anduril/ramp-mode.h31
-rw-r--r--spaghetti-monster/anduril/sunset-timer.c30
-rw-r--r--spaghetti-monster/anduril/sunset-timer.h26
4 files changed, 41 insertions, 95 deletions
diff --git a/spaghetti-monster/anduril/ramp-mode.c b/spaghetti-monster/anduril/ramp-mode.c
index e57b68f..a87e9b0 100644
--- a/spaghetti-monster/anduril/ramp-mode.c
+++ b/spaghetti-monster/anduril/ramp-mode.c
@@ -1,24 +1,8 @@
-/*
- * ramp-mode.c: Ramping functions for Anduril.
- *
- * Copyright (C) 2017 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef RAMP_MODE_C
-#define RAMP_MODE_C
+// ramp-mode.c: Ramping functions for Anduril.
+// Copyright (C) 2017-2023 Selene ToyKeeper
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#pragma once
#include "ramp-mode.h"
@@ -85,13 +69,12 @@ uint8_t steady_state(Event event, uint16_t arg) {
#ifdef USE_SUNSET_TIMER
// handle the shutoff timer first
- static uint8_t timer_orig_level = 0;
uint8_t sunset_active = sunset_timer; // save for comparison
// clock tick
sunset_timer_state(event, arg);
// if the timer was just turned on
if (sunset_timer && (! sunset_active)) {
- timer_orig_level = actual_level;
+ sunset_timer_orig_level = actual_level;
}
// if the timer just expired, shut off
else if (sunset_active && (! sunset_timer)) {
@@ -145,7 +128,7 @@ uint8_t steady_state(Event event, uint16_t arg) {
set_level_and_therm_target(memorized_level);
}
#ifdef USE_SUNSET_TIMER
- timer_orig_level = actual_level;
+ reset_sunset_timer();
#endif
return MISCHIEF_MANAGED;
}
@@ -243,7 +226,7 @@ uint8_t steady_state(Event event, uint16_t arg) {
#endif
set_level_and_therm_target(memorized_level);
#ifdef USE_SUNSET_TIMER
- timer_orig_level = actual_level;
+ reset_sunset_timer();
#endif
return MISCHIEF_MANAGED;
}
@@ -264,8 +247,12 @@ uint8_t steady_state(Event event, uint16_t arg) {
#ifdef USE_SUNSET_TIMER
// reduce output if shutoff timer is active
if (sunset_timer) {
- uint8_t dimmed_level = timer_orig_level * (sunset_timer-1) / sunset_timer_peak;
+ uint8_t dimmed_level = sunset_timer_orig_level * sunset_timer / sunset_timer_peak;
+ uint8_t dimmed_level_next = sunset_timer_orig_level * (sunset_timer-1) / sunset_timer_peak;
+ uint8_t dimmed_level_delta = dimmed_level - dimmed_level_next;
+ dimmed_level -= dimmed_level_delta * (sunset_ticks/TICKS_PER_SECOND) / 60;
if (dimmed_level < 1) dimmed_level = 1;
+
#ifdef USE_SET_LEVEL_GRADUALLY
set_level_gradually(dimmed_level);
target_level = dimmed_level;
@@ -408,7 +395,7 @@ uint8_t steady_state(Event event, uint16_t arg) {
memorized_level = nearest_level(actual_level);
set_level_and_therm_target(memorized_level);
#ifdef USE_SUNSET_TIMER
- timer_orig_level = actual_level;
+ reset_sunset_timer();
#endif
return MISCHIEF_MANAGED;
}
@@ -681,5 +668,13 @@ void manual_memory_save() {
#endif
}
+#ifdef USE_SUNSET_TIMER
+void reset_sunset_timer() {
+ if (sunset_timer) {
+ sunset_timer_orig_level = actual_level;
+ sunset_timer_peak = sunset_timer;
+ sunset_ticks = 0;
+ }
+}
#endif
diff --git a/spaghetti-monster/anduril/ramp-mode.h b/spaghetti-monster/anduril/ramp-mode.h
index 969cb6b..6bc3846 100644
--- a/spaghetti-monster/anduril/ramp-mode.h
+++ b/spaghetti-monster/anduril/ramp-mode.h
@@ -1,24 +1,8 @@
-/*
- * ramp-mode.h: Ramping functions for Anduril.
- *
- * Copyright (C) 2017 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
+// ramp-mode.h: Ramping functions for Anduril.
+// Copyright (C) 2017-2023 Selene ToyKeeper
+// SPDX-License-Identifier: GPL-3.0-or-later
-#ifndef RAMP_MODE_H
-#define RAMP_MODE_H
+#pragma once
#ifndef RAMP_LENGTH
#define RAMP_LENGTH 150 // default, if not overridden in a driver cfg file
@@ -239,6 +223,11 @@ uint8_t ramp_stepss[] = {
};
uint8_t ramp_discrete_step_size; // don't set this
+#ifdef USE_SUNSET_TIMER
+uint8_t sunset_timer_orig_level = 0;
+void reset_sunset_timer();
+#endif
+
#ifdef USE_GLOBALS_CONFIG
typedef enum {
#ifdef USE_TINT_RAMPING
@@ -254,5 +243,3 @@ void globals_config_save(uint8_t step, uint8_t value);
uint8_t globals_config_state(Event event, uint16_t arg);
#endif
-
-#endif
diff --git a/spaghetti-monster/anduril/sunset-timer.c b/spaghetti-monster/anduril/sunset-timer.c
index d942eba..eae1831 100644
--- a/spaghetti-monster/anduril/sunset-timer.c
+++ b/spaghetti-monster/anduril/sunset-timer.c
@@ -1,24 +1,8 @@
-/*
- * sunset-timer.c: Sunset / candle auto-shutoff functions for Anduril.
- *
- * Copyright (C) 2017 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
+// sunset-timer.c: Sunset / candle auto-shutoff functions for Anduril.
+// Copyright (C) 2017-2023 Selene ToyKeeper
+// SPDX-License-Identifier: GPL-3.0-or-later
-#ifndef SUNSET_TIMER_C
-#define SUNSET_TIMER_C
+#pragma once
#include "sunset-timer.h"
@@ -39,8 +23,9 @@ uint8_t sunset_timer_state(Event event, uint16_t arg) {
else if (event == EV_hold) {
// ramping up should "bump" the timer to extend the deadline a bit
if ((sunset_timer > 0) && (sunset_timer < 4)) {
- sunset_timer = 3;
+ sunset_timer = 3; // 3 minutes
sunset_timer_peak = 3;
+ sunset_ticks = 0; // re-start current "minute"
}
}
// 5H: add 5m to timer, per second, until released
@@ -73,6 +58,3 @@ uint8_t sunset_timer_state(Event event, uint16_t arg) {
return EVENT_NOT_HANDLED;
}
-
-#endif
-
diff --git a/spaghetti-monster/anduril/sunset-timer.h b/spaghetti-monster/anduril/sunset-timer.h
index 8f7840c..963804e 100644
--- a/spaghetti-monster/anduril/sunset-timer.h
+++ b/spaghetti-monster/anduril/sunset-timer.h
@@ -1,24 +1,8 @@
-/*
- * sunset-timer.h: Sunset / candle auto-shutoff functions for Anduril.
- *
- * Copyright (C) 2017 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
+// sunset-timer.h: Sunset / candle auto-shutoff functions for Anduril.
+// Copyright (C) 2017-2023 Selene ToyKeeper
+// SPDX-License-Identifier: GPL-3.0-or-later
-#ifndef SUNSET_TIMER_H
-#define SUNSET_TIMER_H
+#pragma once
// how many minutes to add each time the user "bumps" the timer?
#define SUNSET_TIMER_UNIT 5
@@ -31,5 +15,3 @@ uint8_t sunset_timer_peak = 0; // total minutes in countdown
uint16_t sunset_ticks = 0; // counts from 0 to TICKS_PER_MINUTE, then repeats
uint8_t sunset_timer_state(Event event, uint16_t arg);
-
-#endif
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.