From a7e19b5b8eb509d132f762baa8f181f629abe133 Mon Sep 17 00:00:00 2001 From: DWW Date: Sat, 16 Oct 2021 00:54:57 +0300 Subject: [PATCH] Fixed updating the screen when sleeping --- code/main.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/code/main.c b/code/main.c index c881a7c..03c3f1f 100644 --- a/code/main.c +++ b/code/main.c @@ -25,7 +25,9 @@ // Rotary Encoder Parameters #define ROT_PULSE_COUNT 12 -#define ROT_WHEEL_RAD 12 +#define ROT_DETENTS 24 +#define ROT_WHEEL_RAD 13.125 +//#define ROT_CW_UP // Input masks #define BUTTON_V 0x01 @@ -66,6 +68,7 @@ uint8_t *event_write = events; uint32_t ms = 0; +#ifdef ROT_CW_UP const uint8_t PROGMEM rot_table[16] = { EVENT_NONE, EVENT_ROT_CCW, EVENT_ROT_CW, EVENT_NONE, @@ -73,6 +76,15 @@ const uint8_t PROGMEM rot_table[16] = EVENT_ROT_CCW, EVENT_NONE, EVENT_NONE, EVENT_ROT_CW, EVENT_NONE, EVENT_ROT_CW, EVENT_ROT_CCW, EVENT_NONE }; +#else +const uint8_t PROGMEM rot_table[16] = +{ + EVENT_NONE, EVENT_ROT_CW, EVENT_ROT_CCW, EVENT_NONE, + EVENT_ROT_CCW, EVENT_NONE, EVENT_NONE, EVENT_ROT_CW, + EVENT_ROT_CW, EVENT_NONE, EVENT_NONE, EVENT_ROT_CCW, + EVENT_NONE, EVENT_ROT_CCW, EVENT_ROT_CW, EVENT_NONE +}; +#endif const uint8_t PROGMEM unfold_table[16] = { @@ -297,7 +309,7 @@ int main() } } - if (rot_value / 2 != 0) + if (rot_value / (ROT_PULSE_COUNT * 4 / ROT_DETENTS) != 0) { int8_t rot_abs; int8_t adjust; @@ -340,7 +352,7 @@ int main() } count_value = (uint32_t) count_value_fine; - if (0 != sleep_when_ms) + if ((0 != sleep_when_ms) && (sleep_when_ms > ms)) { needs_update = 1; } @@ -360,6 +372,7 @@ int main() { display_enable(0); do_sleep(); + sleep_when_ms = 1; } // STATE_COUNTING @@ -604,7 +617,19 @@ void display_init() void display_enable(uint8_t en) { - display_send_cmd(0xAE | (en & 0x01)); + static uint8_t old_state = 1; + + if (en != 0) + { + en = 1; + } + + if (en != old_state) + { + display_send_cmd(0xAE | (en & 0x01)); + } + + old_state = en; } void get_symbol16(uint8_t index, uint8_t *out) @@ -936,7 +961,7 @@ void do_sleep() // Reset ms counter cli(); - ms = 0; + ms = 2; sei(); // Disable sleep