summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-11-01 12:29:14 +0100
committerErich Eckner <git@eckner.net>2018-11-01 12:29:14 +0100
commita9679f6210fad1b1d8b05529dd6f4443c633365b (patch)
treec8271be5c740359b0dbe1027d2235bc2a91889d9
parentd9b831fcc29585eab34c58c5a67c060d886bc8a6 (diff)
downloadanzeige-a9679f6210fad1b1d8b05529dd6f4443c633365b.tar.xz
probe SENSE_PIN
-rw-r--r--anzeige.c5
-rw-r--r--multiplexer.c70
-rw-r--r--multiplexer.h4
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<<PAR_CLK_PIN;
#endif
} // turn_off_display
+
+int got_input()
+{
+#ifdef SKIP_GPIO
+ struct timeval tv = { 0L, 0L };
+ fd_set fds;
+ FD_ZERO(&fds);
+ FD_SET(0, &fds);
+ if (select(1, &fds, NULL, NULL, &tv)) {
+ unsigned char c;
+ read(0, &c, sizeof(c));
+ return 1;
+ }
+ else
+ return 0;
+#else
+ return ! GET_GPIO(SENSE_PIN); // low = active
+#endif
+} // got_input
diff --git a/multiplexer.h b/multiplexer.h
index 86e99ee..bf40ad5 100644
--- a/multiplexer.h
+++ b/multiplexer.h
@@ -49,7 +49,7 @@ void *gpio_map;
typedef struct {
char buf[3][40];
- int should_buf, is_buf, keep_running;
+ int should_buf, is_buf, keep_running, should_be_on, is_on;
pthread_t thread_id;
} t_display_data;
@@ -62,6 +62,7 @@ typedef struct {
int update;
char input[(SCROLL_BUF_LEN - 39) / 2];
int input_len, keep_running;
+ time_t shine_until;
pthread_t thread_id;
} t_scroll_data;
@@ -86,3 +87,4 @@ int multiplexer_setup_root();
void multiplexer_setup_non_root(t_display_data *display_data);
void multiplexer_setup_scroll(t_scroll_data *scroll_data);
void turn_off_display();
+int got_input();