From c8f52f8271c5f2a048d8849efe656c5391da29ba Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 20 Jan 2016 12:27:20 +0100 Subject: move display and modem code from ISR to class functions --- src/display.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/display.h') diff --git a/src/display.h b/src/display.h index d239e18..6545caa 100644 --- a/src/display.h +++ b/src/display.h @@ -9,6 +9,7 @@ class Display { Display() {}; void enable(void); void disable(void); + void multiplex(void); char string[128]; }; -- cgit v1.2.3 From b0285847fc295b0034aa7e7d3b90d6b70ba37b8e Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 20 Jan 2016 12:34:56 +0100 Subject: excapsulate display and modem state in their respective classes --- src/display.cc | 22 ++++++++++++++-------- src/display.h | 7 ++++++- src/modem.cc | 16 ++++++---------- src/modem.h | 7 ++++++- 4 files changed, 32 insertions(+), 20 deletions(-) (limited to 'src/display.h') diff --git a/src/display.cc b/src/display.cc index 30a441f..4b4c22d 100644 --- a/src/display.cc +++ b/src/display.cc @@ -9,6 +9,19 @@ 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; +} + void Display::disable() { TIMSK0 &= ~_BV(TOIE0); @@ -30,14 +43,7 @@ void Display::enable() void Display::multiplex() { - static uint8_t active_col = 0; - static uint16_t scroll = 0; - - static uint8_t disp_buf[] = {0xff,0xfb,0xdd,0xfd,0xdd,0xfb,0xff,0xff}; - - static uint8_t str_pos = 0; - static int8_t char_pos = -1; - + static uint16_t scroll; uint8_t i, glyph_len; uint8_t *glyph_addr; diff --git a/src/display.h b/src/display.h index 6545caa..655ffa1 100644 --- a/src/display.h +++ b/src/display.h @@ -5,8 +5,13 @@ #include class Display { + private: + uint8_t active_col; + uint8_t disp_buf[8]; + uint8_t str_pos; + int8_t char_pos; public: - Display() {}; + Display(); void enable(void); void disable(void); void multiplex(void); diff --git a/src/modem.cc b/src/modem.cc index 0a89586..e9cddb7 100644 --- a/src/modem.cc +++ b/src/modem.cc @@ -11,26 +11,22 @@ #include #include "modem.h" -/* Ring buffer global variables */ -static volatile uint8_t modem_buffer_head = 0, modem_buffer_tail = 0; -static volatile uint8_t modem_buffer[MODEM_BUFFER_SIZE]; - Modem modem; /* * Returns number of available bytes in ringbuffer or 0 if empty */ uint8_t Modem::buffer_available() { - return modem_buffer_head - modem_buffer_tail; + return buffer_head - buffer_tail; } /* * Store 1 byte in ringbuffer */ -static inline void modem_buffer_put(const uint8_t c) { +inline void Modem::buffer_put(const uint8_t c) { if (modem.buffer_available() != MODEM_BUFFER_SIZE) { - modem_buffer[modem_buffer_head++ % MODEM_BUFFER_SIZE] = c; - } + buffer[buffer_head++ % MODEM_BUFFER_SIZE] = c; + } } /* @@ -39,7 +35,7 @@ static inline void modem_buffer_put(const uint8_t c) { uint8_t Modem::buffer_get() { uint8_t b = 0; if (buffer_available() != 0) { - b = modem_buffer[modem_buffer_tail++ % MODEM_BUFFER_SIZE]; + b = buffer[buffer_tail++ % MODEM_BUFFER_SIZE]; } return b; } @@ -98,7 +94,7 @@ void Modem::receive() { /* Check if we received complete byte and store it in ring buffer */ if (!(++modem_bit % 0x08)) { - modem_buffer_put(modem_byte); + buffer_put(modem_byte); } } diff --git a/src/modem.h b/src/modem.h index afd6aff..18273f0 100644 --- a/src/modem.h +++ b/src/modem.h @@ -11,7 +11,7 @@ #include /* Modem ring buffer size must be power of 2 */ -#define MODEM_BUFFER_SIZE 4 +#define MODEM_BUFFER_SIZE 8 /* Modem defines */ #define MODEM_SYNC_LEN 42 @@ -23,6 +23,11 @@ #define MODEM_DDR DDRA class Modem { + private: + uint8_t buffer_head; + uint8_t buffer_tail; + uint8_t buffer[MODEM_BUFFER_SIZE]; + void buffer_put(const uint8_t c); public: Modem() {}; uint8_t buffer_available(void); -- cgit v1.2.3 From f0261ac07dada88c46bc6bb74a55324425cfba9c Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 20 Jan 2016 13:20:49 +0100 Subject: reset display after receiving data --- src/display.cc | 8 ++++++++ src/display.h | 1 + src/system.cc | 1 + 3 files changed, 10 insertions(+) (limited to 'src/display.h') diff --git a/src/display.cc b/src/display.cc index 4b4c22d..0a64c18 100644 --- a/src/display.cc +++ b/src/display.cc @@ -86,6 +86,14 @@ void Display::multiplex() } } +void Display::reset() +{ + for (int i = 0; i < 8; i++) + disp_buf[i] = 0xff; + str_pos = 0; + char_pos = -1; +} + /* * 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 655ffa1..3eab2a8 100644 --- a/src/display.h +++ b/src/display.h @@ -15,6 +15,7 @@ class Display { void enable(void); void disable(void); void multiplex(void); + void reset(void); char string[128]; }; diff --git a/src/system.cc b/src/system.cc index 340615d..6c44a30 100644 --- a/src/system.cc +++ b/src/system.cc @@ -75,6 +75,7 @@ void System::loop() i = 0; } else if (modem_char == 0) { i = 0; + display.reset(); } } } -- cgit v1.2.3 From d1d0e300d9c3a7d6289afcb0bfc544f5d9e81eee Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 20 Jan 2016 13:30:25 +0100 Subject: display: add variable for scroll delay --- src/display.cc | 3 ++- src/display.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src/display.h') diff --git a/src/display.cc b/src/display.cc index 0a64c18..b0bc636 100644 --- a/src/display.cc +++ b/src/display.cc @@ -20,6 +20,7 @@ Display::Display() disp_buf[6] = 0xff; disp_buf[7] = 0xff; char_pos = -1; + scroll_delay = 400; } void Display::disable() @@ -58,7 +59,7 @@ void Display::multiplex() if (++active_col == 8) active_col = 0; - if (++scroll == 512) { + if (++scroll == scroll_delay) { scroll = 0; for (i = 0; i < 7; i++) { diff --git a/src/display.h b/src/display.h index 3eab2a8..666648a 100644 --- a/src/display.h +++ b/src/display.h @@ -6,6 +6,7 @@ class Display { private: + uint16_t scroll_delay; uint8_t active_col; uint8_t disp_buf[8]; uint8_t str_pos; -- cgit v1.2.3