summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/device/screen.c52
-rwxr-xr-xsrc/device/screen.h22
2 files changed, 74 insertions, 0 deletions
diff --git a/src/device/screen.c b/src/device/screen.c
new file mode 100755
index 0000000..6ad9a87
--- /dev/null
+++ b/src/device/screen.c
@@ -0,0 +1,52 @@
+#include <time.h>
+#include <stdlib.h>
+#include "screen.h"
+
+void draw_lines(struct display_status *status);
+void update_lines(struct display_status *status);
+char * get_line(struct display_status *status, size_t rline);
+
+void display_update_scroll(struct display_status *status)
+{
+ time_t crr_time = time(NULL);
+ if (status->last_scroll_time - crr_time > status->delta) {
+ status->last_scroll_time += status->delta;
+ status->line_cursor++;
+ update_lines(status);
+ }
+ draw_lines(status);
+}
+
+void draw_lines(struct display_status *status)
+{
+
+}
+
+void update_lines(struct display_status *status)
+{
+ status->first_line = get_line(status, status->line_cursor);
+ status->second_line = get_line(status, status->line_cursor + 1);
+}
+
+/**
+ * Returns a pointer to the first charachter of requested line. If line does not
+ * exist --- a null is returned.
+ */
+char * get_line(struct display_status *status, size_t rline)
+{
+ size_t i;
+ size_t line_idx = 0;
+
+ for (i = 0; i < status->message_len; i++) {
+ if (rline == line_idx) {
+ return status->message + i;
+ }
+ if (status->message[i] == '\0') {
+ line_idx++;
+ }
+ }
+ /* The fact that we are here means that end of the message was reached.
+ * In that case --- return null;
+ */
+ return NULL;
+} \ No newline at end of file
diff --git a/src/device/screen.h b/src/device/screen.h
new file mode 100755
index 0000000..ec30cd5
--- /dev/null
+++ b/src/device/screen.h
@@ -0,0 +1,22 @@
+#ifndef DEVICE_SCREEN_H
+#define DEVICE_SCREEN_H
+
+#include <time.h>
+
+/**
+ * Struct that keeps track of the lines on the screen.
+ */
+struct display_status {
+ time_t delta; /* Seconds/Line */
+ time_t last_scroll_time; /* Last second the line was scrolled */
+ char *message; /* Entire message to be shown */
+ char *first_line; /* First line on display */
+ char *second_line; /* Second line on display */
+ size_t message_len; /* Length of the message */
+ size_t line_cursor; /* Index of the first line being displayed. */
+};
+
+void display_update_scroll(struct display_status *status);
+void display_status_init(struct display_status *status, char *msg);
+
+#endif /* DEVICE_SCREEN_H */ \ No newline at end of file