summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-10-29 09:33:22 +0100
committerErich Eckner <git@eckner.net>2018-10-31 21:35:22 +0100
commit03e7f394ff74407e36b0554f6547d0d72f9785b3 (patch)
tree562b2fe64687141b213ff8500a58ef83cff0830a
parentc47ba6a1a83a40fdda755b6c2d55aa4f54a39c3d (diff)
downloadanzeige-03e7f394ff74407e36b0554f6547d0d72f9785b3.tar.xz
multiplexer.c: wait based on timers to counter measure any fluctuations
-rw-r--r--multiplexer.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/multiplexer.c b/multiplexer.c
index a8df74c..7fe0d3d 100644
--- a/multiplexer.c
+++ b/multiplexer.c
@@ -62,6 +62,9 @@ void *put_on_display(void *param)
{
t_display_data *display_data = param;
int line, column;
+#ifndef SKIP_GPIO
+ struct timespec start_time, stop_time;
+#endif
while (display_data -> keep_running) {
@@ -80,6 +83,11 @@ void *put_on_display(void *param)
#else
for (line=7; line>=0; line--) {
GPIO_CLR = 1<<GATE_PIN; // Licht an
+ if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time) != 0) {
+ display_data -> keep_running = 0;
+ perror("clock_gettime failed");
+ break;
+ }
for (column=0; column<8; column++) {
GPIO_CLR = 1<<SER_CLK_PIN;
GPIO_ALTER(column + line == 7) = 1<<SER_DAT_PIN;
@@ -98,6 +106,13 @@ void *put_on_display(void *param)
#ifdef SKIP_GPIO
printf("\n");
#else
+ if (clock_gettime(CLOCK_MONOTONIC_RAW, &stop_time) != 0) {
+ display_data -> keep_running = 0;
+ perror("clock_gettime failed");
+ break;
+ }
+ // wait until start_time + 1ms
+ usleep((start_time.tv_sec - stop_time.tv_sec) * 1000000 + (start_time.tv_nsec - stop_time.tv_nsec) / 1000 + 1000);
GPIO_SET = 1<<GATE_PIN; // Licht aus
usleep(5);
GPIO_CLR = 1<<PAR_CLK_PIN;
@@ -120,7 +135,14 @@ void *scroll_it(void *param)
multiplexer_setup_non_root(&display_data);
int is_buf = 0;
int column = 0;
+ struct timespec start_time, stop_time;
+
while (scroll_data -> keep_running) {
+ if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time) != 0) {
+ scroll_data -> keep_running = 0;
+ perror("clock_gettime failed");
+ break;
+ }
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;
@@ -144,12 +166,18 @@ void *scroll_it(void *param)
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(50000);
+ if (clock_gettime(CLOCK_MONOTONIC_RAW, &stop_time) != 0) {
+ scroll_data -> keep_running = 0;
+ perror("clock_gettime failed");
+ break;
+ }
+ // wait until start_time + 50ms
+ usleep((start_time.tv_sec - stop_time.tv_sec) * 1000000 + (start_time.tv_nsec - stop_time.tv_nsec) / 1000 + 50000);
+ display_data . should_buf = (display_data . should_buf + 1) % 3;
}
display_data . keep_running = 0;
pthread_join(display_data . thread_id, NULL);