summaryrefslogtreecommitdiffstats
path: root/src/device
diff options
context:
space:
mode:
authorGravatar Ramūnas Mažeikis <ramunasnezinomas@gmail.com> 2019-05-28 20:00:23 +0300
committerGravatar Ramūnas Mažeikis <ramunasnezinomas@gmail.com> 2019-05-28 20:00:23 +0300
commitf267021479ab1f020c7956378d5bf23405ee3e65 (patch)
tree9242c595e351d55621877a2e906367d5c4db41b2 /src/device
parentbf8b16d036e60eec56a42cbfcf012390c143e699 (diff)
downloadusurpation-f267021479ab1f020c7956378d5bf23405ee3e65.tar.gz
usurpation-f267021479ab1f020c7956378d5bf23405ee3e65.tar.bz2
usurpation-f267021479ab1f020c7956378d5bf23405ee3e65.zip
Screen: adjustments, bug fixes and abstraction.
Line drawing code no longer assumes a particular screen as long as it's interface includes OLEDDisplay. Signed-off-by: Ramūnas Mažeikis <ramunasnezinomas@gmail.com>
Diffstat (limited to 'src/device')
-rw-r--r--src/device/screen.cpp22
-rw-r--r--src/device/screen.h9
2 files changed, 22 insertions, 9 deletions
diff --git a/src/device/screen.cpp b/src/device/screen.cpp
index cfabcc5..c923b99 100644
--- a/src/device/screen.cpp
+++ b/src/device/screen.cpp
@@ -1,7 +1,7 @@
#include <time.h>
#include <stdlib.h>
#include <string.h>
-#include <SSD1306Brzo.h>
+#include <OLEDDisplay.h>
#include <Wire.h>
#include "screen.h"
@@ -9,6 +9,9 @@ void draw_lines(struct display_status *status);
void update_lines(struct display_status *status);
void init_msg(char *msg, size_t size);
+/* Effectively const. For type safety reasons. */
+static char NOTHING[] = {'\0'};
+
void display_status_init(struct display_status *status, char *msg)
{
status->delta = 2; /* Currently default */
@@ -44,7 +47,7 @@ end:
return;
}
-void display_update_scroll(struct display_status *status)
+int display_update_scroll(struct display_status *status)
{
time_t crr_time = time(NULL);
/* Only scroll lines once a delta, because --- duh! */
@@ -54,9 +57,14 @@ void display_update_scroll(struct display_status *status)
update_lines(status);
draw_lines(status);
}
+ if (status->first_line == NOTHING && status->second_line == NOTHING) {
+ return END_OF_MESSAGE;
+ } else {
+ return 0;
+ }
}
-void draw_lines(SSD1306Brzo *screen, struct display_status *status)
+void draw_lines(OLEDDisplay *screen, struct display_status *status)
{
screen->clear();
screen->drawString(0, 0, status->first_line);
@@ -65,6 +73,10 @@ void draw_lines(SSD1306Brzo *screen, 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);
+ status->first_line = (status->line_cursor * SCREEN_MAX_CHARS < status->message_len)
+ ? status->message + status->line_cursor * SCREEN_MAX_CHARS
+ : NOTHING;
+ status->second_line = (status->line_cursor * SCREEN_MAX_CHARS < status->message_len)
+ ? status->message + (status->line_cursor + 1) * SCREEN_MAX_CHARS
+ : NOTHING;
} \ No newline at end of file
diff --git a/src/device/screen.h b/src/device/screen.h
index 54734e5..5d0e3b3 100644
--- a/src/device/screen.h
+++ b/src/device/screen.h
@@ -7,7 +7,7 @@
#define DEVICE_SCREEN_H
#include <time.h>
-#include <SSD1306Brzo.h>
+#include <OLEDDisplay.h>
#include <Wire.h>
#define SCREEN_WIDTH (128)
@@ -19,7 +19,7 @@
* Struct that keeps track of the lines on the screen.
*/
struct display_status {
- SSD1306Brzo *screen; /* Screen to draw on. */
+ OLEDDisplay *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 */
@@ -32,8 +32,9 @@ struct display_status {
/**
* Displays scrolling text on the screen.
*/
-void display_update_scroll(struct display_status *status);
+int display_update_scroll(struct display_status *status);
+#define END_OF_MESSAGE (1 << 0)
/**
* Initialises display_status structure so it can be used for
* display_update_scroll.
@@ -44,6 +45,6 @@ void display_update_scroll(struct display_status *status);
*
* msg - message to scroll on the screen
*/
-void display_status_init(SSD1306Brzo *screen, struct display_status *status, char *msg);
+void display_status_init(OLEDDisplay *screen, struct display_status *status, char *msg);
#endif /* DEVICE_SCREEN_H */ \ No newline at end of file