From a9679f6210fad1b1d8b05529dd6f4443c633365b Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Thu, 1 Nov 2018 12:29:14 +0100 Subject: probe SENSE_PIN --- anzeige.c | 5 +++++ multiplexer.c | 70 +++++++++++++++++++++++++++++++++++++++++++---------------- multiplexer.h | 4 +++- 3 files changed, 59 insertions(+), 20 deletions(-) diff --git a/anzeige.c b/anzeige.c index 36465a3..8f5953a 100644 --- a/anzeige.c +++ b/anzeige.c @@ -70,10 +70,15 @@ int main(int argc, char **argv) } time_t next_update = 0; + scroll_data . shine_until = time(NULL) + 10; int i=0; while (scroll_data . keep_running) { + if (got_input()) { + next_update = 0; // update now! + scroll_data . shine_until = time(NULL) + 60; + } if ((time(NULL) >= next_update) && (scroll_data . update == 0)) { next_update = time(NULL) + 60; // one minute ahead diff --git a/multiplexer.c b/multiplexer.c index 9bfdf1b..48e218c 100644 --- a/multiplexer.c +++ b/multiplexer.c @@ -11,16 +11,6 @@ #include "multiplexer.h" -/** TODO -void printButton(int g) -{ - if (GET_GPIO(g)) // !=0 <-> bit is 1 <- port is HIGH=3.3V - printf("Button pressed!\n"); - else // port is LOW=0V - printf("Button released!\n"); -} **/ - - // // Set up a memory regions to access GPIO // @@ -70,10 +60,18 @@ void *put_on_display(void *param) #ifdef SKIP_GPIO usleep(10000); - printf("=\n"); #endif display_data -> is_buf = display_data -> should_buf; + if (!display_data -> should_be_on) { + if (!display_data -> is_on) + sleep(1); + else + turn_off_display(); + continue; + } + display_data -> is_on = display_data -> should_be_on; #ifdef SKIP_GPIO + printf("=\n"); for (line=0; line<7; line++) { for (column=0; column<40; column++) { if (display_data -> buf[display_data -> is_buf][column] & (0x01 << line)) @@ -143,6 +141,15 @@ void *scroll_it(void *param) perror("clock_gettime failed"); break; } + if ((scroll_data -> shine_until != 0) && (scroll_data -> shine_until < time(NULL))) { + // turn off display + display_data . should_be_on = 0; + column = 0; + } + else { + // turn on display + display_data . should_be_on = 1; + } if (scroll_data -> update) { if ((buf[is_buf] . len != scroll_data -> input_len) || (memcmp(&buf[is_buf] . buf[buf[is_buf] . start], scroll_data -> input, scroll_data -> input_len) != 0)) { is_buf = (is_buf + 1) % 2; @@ -163,13 +170,15 @@ void *scroll_it(void *param) // clear update flag scroll_data -> update = 0; } - for (int i=0; i<40; i++) - display_data . buf[(display_data . should_buf + 1) % 3][i] = - buf[is_buf] . buf[column + i]; - column++; - if (buf[is_buf] . len > 0) - while (column >= buf[is_buf] . start + buf[is_buf] . len) - column -= buf[is_buf] . len; + if (display_data . should_be_on != 0) { + for (int i=0; i<40; i++) + display_data . buf[(display_data . should_buf + 1) % 3][i] = + buf[is_buf] . buf[column + i]; + column++; + if (buf[is_buf] . len > 0) + while (column >= buf[is_buf] . start + buf[is_buf] . len) + column -= buf[is_buf] . len; + } if (clock_gettime(CLOCK_MONOTONIC_RAW, &stop_time) != 0) { scroll_data -> keep_running = 0; perror("clock_gettime failed"); @@ -179,7 +188,8 @@ void *scroll_it(void *param) int wait = (start_time.tv_sec - stop_time.tv_sec) * 1000000 + (start_time.tv_nsec - stop_time.tv_nsec) / 1000 + 25000; if (wait > 0) usleep(wait); - display_data . should_buf = (display_data . should_buf + 1) % 3; + if (display_data . should_be_on != 0) + display_data . should_buf = (display_data . should_buf + 1) % 3; } display_data . keep_running = 0; pthread_join(display_data . thread_id, NULL); @@ -216,6 +226,8 @@ void multiplexer_setup_non_root(t_display_data *display_data) display_data -> is_buf = 0; display_data -> should_buf = 0; display_data -> keep_running = 1; + display_data -> is_on = 1; + display_data -> should_be_on = 1; pthread_create(&display_data -> thread_id, NULL, put_on_display, display_data); return; } // multiplexer_setup_non_root @@ -224,6 +236,7 @@ void multiplexer_setup_scroll(t_scroll_data *scroll_data) { scroll_data -> update = 0; scroll_data -> keep_running = 1; + scroll_data -> shine_until = 0; pthread_create(&scroll_data -> thread_id, NULL, scroll_it, scroll_data); return; } // multiplexer_setup_scroll @@ -241,3 +254,22 @@ void turn_off_display() GPIO_SET = 1<