diff options
author | 2019-05-27 23:12:42 +0300 | |
---|---|---|
committer | 2019-05-27 23:12:42 +0300 | |
commit | bf8b16d036e60eec56a42cbfcf012390c143e699 (patch) | |
tree | 147631af48a0b306162365147384f7dd9d1558b8 /src/device | |
parent | e37b3eacefef04258a6dc6e8714da249d2ff9c1d (diff) | |
download | usurpation-bf8b16d036e60eec56a42cbfcf012390c143e699.tar.gz usurpation-bf8b16d036e60eec56a42cbfcf012390c143e699.tar.bz2 usurpation-bf8b16d036e60eec56a42cbfcf012390c143e699.zip |
Screen: implementation of drawing and trivial docs.
Signed-off-by: Ramūnas Mažeikis <ramunasnezinomas@gmail.com>
Diffstat (limited to 'src/device')
-rw-r--r--[-rwxr-xr-x] | src/device/device_network.h | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | src/device/screen.cpp (renamed from src/device/screen.c) | 14 | ||||
-rw-r--r--[-rwxr-xr-x] | src/device/screen.h | 23 |
3 files changed, 31 insertions, 6 deletions
diff --git a/src/device/device_network.h b/src/device/device_network.h index d8f41a1..d8f41a1 100755..100644 --- a/src/device/device_network.h +++ b/src/device/device_network.h diff --git a/src/device/screen.c b/src/device/screen.cpp index ac42076..cfabcc5 100755..100644 --- a/src/device/screen.c +++ b/src/device/screen.cpp @@ -1,6 +1,8 @@ #include <time.h> #include <stdlib.h> #include <string.h> +#include <SSD1306Brzo.h> +#include <Wire.h> #include "screen.h" void draw_lines(struct display_status *status); @@ -18,7 +20,8 @@ void display_status_init(struct display_status *status, char *msg) } /** - * Turns all whitespace into literal spaces to save screen real-estate. + * Turns all whitespace into literal spaces to save screen real-estate and + * possible misinterpretation. */ void init_msg(char *msg, size_t size) { @@ -44,17 +47,20 @@ end: void display_update_scroll(struct display_status *status) { time_t crr_time = time(NULL); + /* Only scroll lines once a delta, because --- duh! */ if (status->last_scroll_time - crr_time > status->delta) { status->last_scroll_time += status->delta; status->line_cursor++; update_lines(status); + draw_lines(status); } - draw_lines(status); } -void draw_lines(struct display_status *status) +void draw_lines(SSD1306Brzo *screen, struct display_status *status) { - /* TODO */ + screen->clear(); + screen->drawString(0, 0, status->first_line); + screen->drawString(0, SCREEN_HEIGHT / 2, status->second_line); } void update_lines(struct display_status *status) diff --git a/src/device/screen.h b/src/device/screen.h index 7763bd2..54734e5 100755..100644 --- a/src/device/screen.h +++ b/src/device/screen.h @@ -1,9 +1,17 @@ +/** + * Simple API for scrolling lines. Keeps things simple by not even assuming + * which screen is being drawn on. + */ + #ifndef DEVICE_SCREEN_H #define DEVICE_SCREEN_H #include <time.h> +#include <SSD1306Brzo.h> +#include <Wire.h> -#define SCREEN_WIDTH (64) +#define SCREEN_WIDTH (128) +#define SCREEN_HEIGHT (32) #define FONT_WIDTH (8) #define SCREEN_MAX_CHARS (SCREEN_WIDTH / FONT_WIDTH) @@ -11,6 +19,7 @@ * Struct that keeps track of the lines on the screen. */ struct display_status { + SSD1306Brzo *screen; /* Screen to draw on. */ time_t delta; /* Seconds/Line */ time_t last_scroll_time; /* Last second the line was scrolled */ char *message; /* Entire message to be shown */ @@ -25,6 +34,16 @@ struct display_status { */ void display_update_scroll(struct display_status *status); -void display_status_init(struct display_status *status, char *msg); +/** + * Initialises display_status structure so it can be used for + * display_update_scroll. + * + * screen - screen to draw on + * + * status - structure to Initialise + * + * msg - message to scroll on the screen + */ +void display_status_init(SSD1306Brzo *screen, struct display_status *status, char *msg); #endif /* DEVICE_SCREEN_H */
\ No newline at end of file |