aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2017-08-25 02:14:31 -0600
committerSelene ToyKeeper2017-08-25 02:14:31 -0600
commit39b30b41f92978a3e05a8de0a416279fb35b35b1 (patch)
treeab349e516b72389820703e8eb7d4dbf4854875e6
parentStarted on some documentation, spaghetti-monster.txt. (diff)
downloadanduril-39b30b41f92978a3e05a8de0a416279fb35b35b1.tar.gz
anduril-39b30b41f92978a3e05a8de0a416279fb35b35b1.tar.bz2
anduril-39b30b41f92978a3e05a8de0a416279fb35b35b1.zip
Added battcheck mode to ramping-ui. It's bigger than I had hoped. :(
Added fsm-misc.*, which currently only has interruptible blink functions in it. (for blinking out numbers and such)
-rw-r--r--spaghetti-monster/fsm-adc.c24
-rw-r--r--spaghetti-monster/fsm-adc.h6
-rw-r--r--spaghetti-monster/fsm-events.c12
-rw-r--r--spaghetti-monster/fsm-events.h2
-rw-r--r--spaghetti-monster/fsm-misc.c91
-rw-r--r--spaghetti-monster/fsm-misc.h35
-rw-r--r--spaghetti-monster/ramping-ui.c40
-rw-r--r--spaghetti-monster/spaghetti-monster.h2
8 files changed, 209 insertions, 3 deletions
diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c
index 9a6e2e7..70e3bb3 100644
--- a/spaghetti-monster/fsm-adc.c
+++ b/spaghetti-monster/fsm-adc.c
@@ -263,4 +263,28 @@ ISR(ADC_vect) {
#endif
}
+#ifdef USE_BATTCHECK
+#ifdef BATTCHECK_4bars
+PROGMEM const uint8_t voltage_blinks[] = {
+ 30, 35, 38, 40, 42, 99,
+};
+#endif
+#ifdef BATTCHECK_8bars
+PROGMEM const uint8_t voltage_blinks[] = {
+ 30, 33, 35, 37, 38, 39 40, 41, 42, 99,
+};
+#endif
+void battcheck() {
+ #ifdef BATTCHECK_VpT
+ blink_num(voltage);
+ #else
+ uint8_t i;
+ for(i=0;
+ voltage >= pgm_read_byte(voltage_blinks + i);
+ i++) {}
+ blink_num(i);
+ #endif
+}
+#endif
+
#endif
diff --git a/spaghetti-monster/fsm-adc.h b/spaghetti-monster/fsm-adc.h
index 43d52a6..f1b4477 100644
--- a/spaghetti-monster/fsm-adc.h
+++ b/spaghetti-monster/fsm-adc.h
@@ -36,6 +36,12 @@
#endif
volatile uint8_t voltage;
void low_voltage();
+#ifdef USE_BATTCHECK
+void battcheck();
+#ifdef BATTCHECK_VpT
+#define USE_BLINK_NUM
+#endif
+#endif
#endif
diff --git a/spaghetti-monster/fsm-events.c b/spaghetti-monster/fsm-events.c
index 4831df6..29ef415 100644
--- a/spaghetti-monster/fsm-events.c
+++ b/spaghetti-monster/fsm-events.c
@@ -122,6 +122,18 @@ uint8_t nice_delay_ms(uint16_t ms) {
return 1;
}
+/*
+uint8_t nice_delay_4ms(uint8_t ms) {
+ return nice_delay_ms((uint16_t)ms << 2);
+}
+*/
+
+/*
+uint8_t nice_delay_s() {
+ return nice_delay_4ms(250);
+}
+*/
+
// Call stacked callbacks for the given event until one handles it.
uint8_t emit_now(EventPtr event, uint16_t arg) {
for(int8_t i=state_stack_len-1; i>=0; i--) {
diff --git a/spaghetti-monster/fsm-events.h b/spaghetti-monster/fsm-events.h
index a3ef130..141a0dc 100644
--- a/spaghetti-monster/fsm-events.h
+++ b/spaghetti-monster/fsm-events.h
@@ -221,5 +221,7 @@ void emit(EventPtr event, uint16_t arg);
void emit_current_event(uint16_t arg);
uint8_t nice_delay_ms(uint16_t ms);
+//uint8_t nice_delay_4ms(uint8_t ms);
+//uint8_t nice_delay_s();
#endif
diff --git a/spaghetti-monster/fsm-misc.c b/spaghetti-monster/fsm-misc.c
new file mode 100644
index 0000000..46325ef
--- /dev/null
+++ b/spaghetti-monster/fsm-misc.c
@@ -0,0 +1,91 @@
+/*
+ * fsm-misc.c: Miscellaneous function for SpaghettiMonster.
+ *
+ * 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 FSM_MISC_C
+#define FSM_MISC_C
+
+#ifdef USE_BLINK_NUM
+uint8_t blink_digit(uint8_t num) {
+ //StatePtr old_state = current_state;
+
+ // "zero" digit gets a single short blink
+ uint8_t ontime = 200;
+ if (!num) { ontime = 8; num ++; }
+
+ for (; num>0; num--) {
+ set_level(BLINK_BRIGHTNESS);
+ if (! nice_delay_ms(ontime)) { set_level(0); return 0; }
+ set_level(0);
+ //if (current_state != old_state) return 0;
+ if (! nice_delay_ms(400)) return 0;
+ //if (current_state != old_state) return 0;
+ }
+ return nice_delay_ms(600);
+}
+
+uint8_t blink_num(uint8_t num) {
+ //StatePtr old_state = current_state;
+ #if 0
+ uint8_t hundreds = num / 100;
+ num = num % 100;
+ uint8_t tens = num / 10;
+ num = num % 10;
+ #else // 8 bytes smaller
+ uint8_t hundreds = 0;
+ uint8_t tens = 0;
+ for(; num >= 100; hundreds ++, num -= 100);
+ for(; num >= 10; tens ++, num -= 10);
+ #endif
+
+ #if 0
+ // wait a moment in the dark before starting
+ set_level(0);
+ if (! nice_delay_ms(200)) return 0;
+ #endif
+
+ #if 0
+ if (hundreds) {
+ if (! blink_digit(hundreds)) return 0;
+ if (! blink_digit(tens)) return 0;
+ }
+ else if (tens) {
+ if (! blink_digit(tens)) return 0;
+ }
+ if (! blink_digit(num)) return 0;
+ return nice_delay_ms(1000);
+ #else // same size :(
+ if (hundreds) if (! blink_digit(hundreds)) return 0;
+ if (hundreds || tens) if (! blink_digit(tens)) return 0;
+ if (! blink_digit(num)) return 0;
+ return nice_delay_ms(1000);
+ #endif
+
+ /*
+ uint8_t volts, tenths;
+ volts = voltage / 10;
+ tenths = voltage % 10;
+ if (! blink(volts)) return;
+ if (! nice_delay_ms(200)) return;
+ if (! blink(tenths)) return;
+ nice_delay_ms(200);
+ */
+}
+#endif
+
+#endif
diff --git a/spaghetti-monster/fsm-misc.h b/spaghetti-monster/fsm-misc.h
new file mode 100644
index 0000000..7533849
--- /dev/null
+++ b/spaghetti-monster/fsm-misc.h
@@ -0,0 +1,35 @@
+/*
+ * fsm-misc.h: Miscellaneous function for SpaghettiMonster.
+ *
+ * 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 FSM_MISC_H
+#define FSM_MISC_H
+
+#ifdef USE_BLINK_NUM
+#define USE_BLINK
+#ifndef BLINK_BRIGHTNESS
+#define BLINK_BRIGHTNESS (MAX_LEVEL/6)
+#endif
+uint8_t blink_num(uint8_t num);
+#endif
+
+#ifdef USE_BLINK
+uint8_t blink(uint8_t num, uint8_t speed);
+#endif
+
+#endif
diff --git a/spaghetti-monster/ramping-ui.c b/spaghetti-monster/ramping-ui.c
index 562cd1b..0b5bbda 100644
--- a/spaghetti-monster/ramping-ui.c
+++ b/spaghetti-monster/ramping-ui.c
@@ -25,6 +25,8 @@
#define USE_DELAY_4MS
#define USE_DELAY_ZERO
#define USE_RAMPING
+#define USE_BATTCHECK
+#define BATTCHECK_VpT
#define RAMP_LENGTH 150
#include "spaghetti-monster.h"
@@ -32,6 +34,9 @@
uint8_t off_state(EventPtr event, uint16_t arg);
uint8_t steady_state(EventPtr event, uint16_t arg);
uint8_t strobe_state(EventPtr event, uint16_t arg);
+#ifdef USE_BATTCHECK
+uint8_t battcheck_state(EventPtr event, uint16_t arg);
+#endif
// brightness control
uint8_t memorized_level = MAX_1x7135;
@@ -72,6 +77,11 @@ uint8_t off_state(EventPtr event, uint16_t arg) {
set_state(steady_state, memorized_level);
return MISCHIEF_MANAGED;
}
+ // 2 clicks (initial press): off, to prep for later events
+ else if (event == EV_click2_press) {
+ set_level(0);
+ return MISCHIEF_MANAGED;
+ }
// 2 clicks: highest mode
else if (event == EV_2clicks) {
set_state(steady_state, MAX_LEVEL);
@@ -82,6 +92,13 @@ uint8_t off_state(EventPtr event, uint16_t arg) {
set_state(strobe_state, 0);
return MISCHIEF_MANAGED;
}
+ #ifdef USE_BATTCHECK
+ // 4 clicks: battcheck mode
+ else if (event == EV_4clicks) {
+ set_state(battcheck_state, 0);
+ return MISCHIEF_MANAGED;
+ }
+ #endif
// hold: go to lowest level
else if (event == EV_click1_hold) {
// don't start ramping immediately;
@@ -149,7 +166,7 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
if (ramp_step_size == 1) ramp_step_size = MAX_LEVEL/6;
else ramp_step_size = 1;
set_level(0);
- delay_ms(20);
+ delay_4ms(20/4);
set_level(memorized_level);
return MISCHIEF_MANAGED;
}
@@ -171,7 +188,7 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
&& ((memorized_level == MAX_1x7135)
|| (memorized_level == MAX_LEVEL))) {
set_level(0);
- delay_ms(7);
+ delay_4ms(8/4);
}
set_level(memorized_level);
return MISCHIEF_MANAGED;
@@ -195,7 +212,7 @@ uint8_t steady_state(EventPtr event, uint16_t arg) {
&& ((memorized_level == MAX_1x7135)
|| (memorized_level == 1))) {
set_level(0);
- delay_ms(7);
+ delay_4ms(8/4);
}
set_level(memorized_level);
return MISCHIEF_MANAGED;
@@ -263,6 +280,18 @@ uint8_t strobe_state(EventPtr event, uint16_t arg) {
}
+#ifdef USE_BATTCHECK
+uint8_t battcheck_state(EventPtr event, uint16_t arg) {
+ // 1 click: off
+ if (event == EV_1click) {
+ set_state(off_state, 0);
+ return MISCHIEF_MANAGED;
+ }
+ return EVENT_NOT_HANDLED;
+}
+#endif
+
+
void low_voltage() {
// "step down" from strobe to something low
if (current_state == strobe_state) {
@@ -301,4 +330,9 @@ void loop() {
set_level(0);
nice_delay_ms(strobe_delay);
}
+ #ifdef USE_BATTCHECK
+ else if (current_state == battcheck_state) {
+ battcheck();
+ }
+ #endif
}
diff --git a/spaghetti-monster/spaghetti-monster.h b/spaghetti-monster/spaghetti-monster.h
index 56d03a3..3727930 100644
--- a/spaghetti-monster/spaghetti-monster.h
+++ b/spaghetti-monster/spaghetti-monster.h
@@ -34,6 +34,7 @@
#include "fsm-pcint.h"
#include "fsm-standby.h"
#include "fsm-ramping.h"
+#include "fsm-misc.h"
#include "fsm-main.h"
#if defined(USE_DELAY_MS) || defined(USE_DELAY_4MS) || defined(USE_DELAY_ZERO) || defined(USE_DEBUG_BLINK)
@@ -70,4 +71,5 @@ void loop();
#include "fsm-pcint.c"
#include "fsm-standby.c"
#include "fsm-ramping.c"
+#include "fsm-misc.c"
#include "fsm-main.c"