summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/device/screen.c62
-rwxr-xr-xsrc/device/screen.h8
2 files changed, 45 insertions, 25 deletions
diff --git a/src/device/screen.c b/src/device/screen.c
index 6ad9a87..ac42076 100755
--- a/src/device/screen.c
+++ b/src/device/screen.c
@@ -1,10 +1,45 @@
#include <time.h>
#include <stdlib.h>
+#include <string.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 init_msg(char *msg, size_t size);
+
+void display_status_init(struct display_status *status, char *msg)
+{
+ status->delta = 2; /* Currently default */
+ init_msg(msg, strlen(msg));
+ status->message = msg;
+ status->line_cursor = 0;
+ status->last_scroll_time = time(NULL);
+ update_lines(status);
+}
+
+/**
+ * Turns all whitespace into literal spaces to save screen real-estate.
+ */
+void init_msg(char *msg, size_t size)
+{
+ size_t i;
+
+ for (i = 0; i < size; i++) {
+ switch (msg[i]) {
+ case '\n':
+ case '\t':
+ case '\r':
+ msg[i] = ' ';
+ break;
+ case '\0':
+ goto end;
+ default:
+ break;
+ }
+ }
+end:
+ return;
+}
void display_update_scroll(struct display_status *status)
{
@@ -19,34 +54,11 @@ void display_update_scroll(struct display_status *status)
void draw_lines(struct display_status *status)
{
-
+ /* TODO */
}
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
index ec30cd5..7763bd2 100755
--- a/src/device/screen.h
+++ b/src/device/screen.h
@@ -3,6 +3,10 @@
#include <time.h>
+#define SCREEN_WIDTH (64)
+#define FONT_WIDTH (8)
+#define SCREEN_MAX_CHARS (SCREEN_WIDTH / FONT_WIDTH)
+
/**
* Struct that keeps track of the lines on the screen.
*/
@@ -16,7 +20,11 @@ struct display_status {
size_t line_cursor; /* Index of the first line being displayed. */
};
+/**
+ * Displays scrolling text on the screen.
+ */
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