summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2016-01-22 16:27:33 +0100
committerDaniel Friesel <derf@finalrewind.org>2016-01-22 16:37:32 +0100
commit83d6a0ee679e73c89d0ba84602d3052527726230 (patch)
treee97938f84b1740093ad20d94fc2f7f34b49c8385
parenta4d13d607e5d7d6308c52f7a184290916ddd1296 (diff)
make display buffer private, add separate modem receive buffer
-rw-r--r--src/display.cc18
-rw-r--r--src/display.h3
-rw-r--r--src/main.cc8
-rw-r--r--src/system.cc6
4 files changed, 16 insertions, 19 deletions
diff --git a/src/display.cc b/src/display.cc
index b0bc636..42710c9 100644
--- a/src/display.cc
+++ b/src/display.cc
@@ -11,14 +11,6 @@ Display display;
Display::Display()
{
- disp_buf[0] = 0xff;
- disp_buf[1] = 0xfb;
- disp_buf[2] = 0xdd;
- disp_buf[3] = 0xfd;
- disp_buf[4] = 0xdd;
- disp_buf[5] = 0xfb;
- disp_buf[6] = 0xff;
- disp_buf[7] = 0xff;
char_pos = -1;
scroll_delay = 400;
}
@@ -89,12 +81,20 @@ void Display::multiplex()
void Display::reset()
{
- for (int i = 0; i < 8; i++)
+ for (uint8_t i = 0; i < 8; i++)
disp_buf[i] = 0xff;
str_pos = 0;
char_pos = -1;
}
+void Display::setString(char *new_str)
+{
+ reset();
+ for (uint8_t i = 0; new_str[i] != 0; i++) {
+ string[i] = new_str[i];
+ }
+}
+
/*
* Draws a single display column. This function should be called at least once
* per millisecond.
diff --git a/src/display.h b/src/display.h
index 666648a..f0ea0a4 100644
--- a/src/display.h
+++ b/src/display.h
@@ -11,13 +11,14 @@ class Display {
uint8_t disp_buf[8];
uint8_t str_pos;
int8_t char_pos;
+ char string[128];
public:
Display();
void enable(void);
void disable(void);
void multiplex(void);
void reset(void);
- char string[128];
+ void setString(char *str);
};
extern Display display;
diff --git a/src/main.cc b/src/main.cc
index 9558109..aefad1c 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -20,13 +20,7 @@ int main (void)
// Enable pull-ups on PC3 and PC7 (button pins)
PORTC |= _BV(PC3) | _BV(PC7);
- display.string[0] = 'O';
- display.string[1] = 'h';
- display.string[2] = 'a';
- display.string[3] = 'i';
- display.string[4] = '!';
- display.string[5] = ' ';
- display.string[6] = 0;
+ display.setString("Ohai! ");
display.enable();
modem.enable();
diff --git a/src/system.cc b/src/system.cc
index 6c44a30..5c7b177 100644
--- a/src/system.cc
+++ b/src/system.cc
@@ -12,6 +12,8 @@
System rocket;
+char disp_buf[128];
+
void System::loop()
{
static uint8_t i = 0;
@@ -70,12 +72,12 @@ void System::loop()
while (modem.buffer_available()) {
modem_char = modem.buffer_get();
- display.string[i++] = modem_char;
+ disp_buf[i++] = modem_char;
if (i == 127) {
i = 0;
} else if (modem_char == 0) {
i = 0;
- display.reset();
+ display.setString(disp_buf);
}
}
}