summaryrefslogtreecommitdiff
path: root/multiplexer.c
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-10-27 22:45:41 +0200
committerErich Eckner <git@eckner.net>2018-10-27 22:45:41 +0200
commit71e97ec2bc954e57b6955b3ec3fc49379116efc7 (patch)
tree6c257725c88bf2cbdd0912db750994fb9b2dddaf /multiplexer.c
parentfc5f0e6e60bcaed784c955b79d173cd6eb7f4305 (diff)
downloadanzeige-71e97ec2bc954e57b6955b3ec3fc49379116efc7.tar.xz
put scrolling into separate thread; activate minutely updates; cleanup
Diffstat (limited to 'multiplexer.c')
-rw-r--r--multiplexer.c61
1 files changed, 57 insertions, 4 deletions
diff --git a/multiplexer.c b/multiplexer.c
index c81864b..52c7af1 100644
--- a/multiplexer.c
+++ b/multiplexer.c
@@ -7,6 +7,7 @@
#include <unistd.h>
#include <string.h>
#include <pthread.h>
+#include <assert.h>
#include "multiplexer.h"
@@ -108,10 +109,54 @@ void *put_on_display(void *param)
return NULL;
} // put_on_display
-pthread_t multiplexer_setup_non_root(t_display_data *display_data)
+// scroll the text over the display
+void *scroll_it(void *param)
{
- pthread_t thread_id;
+ t_scroll_data *scroll_data = (t_scroll_data *) param;
+ t_scroll_buffer buf[3];
+ for (int i=0; i<3; i++)
+ memset(&buf[i], 0, sizeof(buf[i]));
+ t_display_data display_data;
+ multiplexer_setup_non_root(&display_data);
+ int is_buf = 0;
+ int column = 0;
+ while (scroll_data -> keep_running) {
+ 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;
+ // copy the currently visible, old content
+ memcpy(buf[is_buf] . buf, &buf[(is_buf + 1) % 2] . buf[column + 1], 39);
+ buf[is_buf] . start = 39;
+ // set the length of the new content
+ buf[is_buf] . len = scroll_data -> input_len;
+ // copy the new content from input
+ for (int i=0; i<2; i++)
+ memcpy(
+ &buf[is_buf] . buf[39 + i * buf[is_buf] . len],
+ scroll_data -> input,
+ buf[is_buf] . len
+ );
+ column = 0;
+ }
+ // 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];
+ display_data . should_buf = (display_data . should_buf + 1) % 3;
+ column++;
+ if (buf[is_buf] . len > 0)
+ while (column >= buf[is_buf] . start + buf[is_buf] . len)
+ column -= buf[is_buf] . len;
+ usleep(100000);
+ }
+ display_data . keep_running = 0;
+ pthread_join(display_data . thread_id, NULL);
+} // scroll_it
+void multiplexer_setup_non_root(t_display_data *display_data)
+{
#ifndef SKIP_GPIO
// must use INP_GPIO before we can use OUT_GPIO
INP_GPIO(SER_DAT_PIN);
@@ -130,6 +175,14 @@ pthread_t multiplexer_setup_non_root(t_display_data *display_data)
display_data -> is_buf = 0;
display_data -> should_buf = 0;
display_data -> keep_running = 1;
- pthread_create(&thread_id, NULL, put_on_display, display_data);
- return thread_id;
+ pthread_create(&display_data -> thread_id, NULL, put_on_display, display_data);
+ return;
} // multiplexer_setup_non_root
+
+void multiplexer_setup_scroll(t_scroll_data *scroll_data)
+{
+ scroll_data -> update = 0;
+ scroll_data -> keep_running = 1;
+ pthread_create(&scroll_data -> thread_id, NULL, scroll_it, scroll_data);
+ return;
+} // multiplexer_setup_scroll