VFD modular clock firmware
Dependencies: DipCortex-EEprom RTC flw mbed
VFDDisplay.h@9:4bb5c30a475f, 2015-02-20 (annotated)
- Committer:
- Backstrom
- Date:
- Fri Feb 20 10:08:50 2015 +0000
- Revision:
- 9:4bb5c30a475f
- Parent:
- 0:f6e68b4ce169
Update flw library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Backstrom | 0:f6e68b4ce169 | 1 | /* |
Backstrom | 0:f6e68b4ce169 | 2 | * VFD Modular Clock - mbed |
Backstrom | 0:f6e68b4ce169 | 3 | * (C) 2011-14 Akafugu Corporation |
Backstrom | 0:f6e68b4ce169 | 4 | * |
Backstrom | 0:f6e68b4ce169 | 5 | * This program is free software; you can redistribute it and/or modify it under the |
Backstrom | 0:f6e68b4ce169 | 6 | * terms of the GNU General Public License as published by the Free Software |
Backstrom | 0:f6e68b4ce169 | 7 | * Foundation; either version 2 of the License, or (at your option) any later |
Backstrom | 0:f6e68b4ce169 | 8 | * version. |
Backstrom | 0:f6e68b4ce169 | 9 | * |
Backstrom | 0:f6e68b4ce169 | 10 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY |
Backstrom | 0:f6e68b4ce169 | 11 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
Backstrom | 0:f6e68b4ce169 | 12 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
Backstrom | 0:f6e68b4ce169 | 13 | * |
Backstrom | 0:f6e68b4ce169 | 14 | */ |
Backstrom | 0:f6e68b4ce169 | 15 | |
Backstrom | 0:f6e68b4ce169 | 16 | #ifndef __VFDDISPLAY_H_ |
Backstrom | 0:f6e68b4ce169 | 17 | #define __VFDDISPLAY_H_ |
Backstrom | 0:f6e68b4ce169 | 18 | |
Backstrom | 0:f6e68b4ce169 | 19 | #include "mbed.h" |
Backstrom | 0:f6e68b4ce169 | 20 | |
Backstrom | 0:f6e68b4ce169 | 21 | #define MESSAGE_LIMIT 96 |
Backstrom | 0:f6e68b4ce169 | 22 | |
Backstrom | 0:f6e68b4ce169 | 23 | class VFDDisplay : public Stream { |
Backstrom | 0:f6e68b4ce169 | 24 | public: |
Backstrom | 0:f6e68b4ce169 | 25 | enum TimeMode { |
Backstrom | 0:f6e68b4ce169 | 26 | Long = 0, |
Backstrom | 0:f6e68b4ce169 | 27 | Short, |
Backstrom | 0:f6e68b4ce169 | 28 | Extra |
Backstrom | 0:f6e68b4ce169 | 29 | }; |
Backstrom | 0:f6e68b4ce169 | 30 | |
Backstrom | 0:f6e68b4ce169 | 31 | // Controls how display blinks when m_blink is true |
Backstrom | 0:f6e68b4ce169 | 32 | enum BlinkMode { |
Backstrom | 0:f6e68b4ce169 | 33 | Full = 0, // Blink whole display |
Backstrom | 0:f6e68b4ce169 | 34 | Hours, // Blink hours |
Backstrom | 0:f6e68b4ce169 | 35 | Minutes, // Blink minutes |
Backstrom | 0:f6e68b4ce169 | 36 | Seconds // Blink seconds |
Backstrom | 0:f6e68b4ce169 | 37 | }; |
Backstrom | 0:f6e68b4ce169 | 38 | |
Backstrom | 0:f6e68b4ce169 | 39 | protected: |
Backstrom | 0:f6e68b4ce169 | 40 | TimeMode m_mode; |
Backstrom | 0:f6e68b4ce169 | 41 | BlinkMode m_blink_mode; |
Backstrom | 0:f6e68b4ce169 | 42 | |
Backstrom | 0:f6e68b4ce169 | 43 | public: |
Backstrom | 0:f6e68b4ce169 | 44 | VFDDisplay(PinName data, PinName clock, PinName latch, PinName blank, uint8_t digits); |
Backstrom | 0:f6e68b4ce169 | 45 | |
Backstrom | 0:f6e68b4ce169 | 46 | virtual void cls(); |
Backstrom | 0:f6e68b4ce169 | 47 | virtual void setPosition(uint8_t pos); |
Backstrom | 0:f6e68b4ce169 | 48 | |
Backstrom | 0:f6e68b4ce169 | 49 | virtual int putc(int c) { return _putc(c); } |
Backstrom | 0:f6e68b4ce169 | 50 | int printf(const char* format, ...); |
Backstrom | 0:f6e68b4ce169 | 51 | |
Backstrom | 0:f6e68b4ce169 | 52 | void scroll(int8_t spaces = 1); |
Backstrom | 0:f6e68b4ce169 | 53 | void resetScroll(); |
Backstrom | 0:f6e68b4ce169 | 54 | bool scrollFinished(); |
Backstrom | 0:f6e68b4ce169 | 55 | bool scrollAtOrigin() { return m_scroll_offset == 0; } |
Backstrom | 0:f6e68b4ce169 | 56 | |
Backstrom | 0:f6e68b4ce169 | 57 | void setAlarmIndicator(bool on) { m_alarm_indicator = on; } |
Backstrom | 0:f6e68b4ce169 | 58 | void setGPSIndicator(bool on) { m_gps_indicator = on; } |
Backstrom | 0:f6e68b4ce169 | 59 | void setColon(bool on) { m_colon = on; } |
Backstrom | 0:f6e68b4ce169 | 60 | |
Backstrom | 0:f6e68b4ce169 | 61 | void setDots(uint16_t dots) { m_dots = dots; } |
Backstrom | 0:f6e68b4ce169 | 62 | void setDot(uint8_t pos, bool on); |
Backstrom | 0:f6e68b4ce169 | 63 | |
Backstrom | 0:f6e68b4ce169 | 64 | void setTimeMode(TimeMode mode) { m_mode = mode; } |
Backstrom | 0:f6e68b4ce169 | 65 | void toggleTimeMode(); |
Backstrom | 0:f6e68b4ce169 | 66 | |
Backstrom | 0:f6e68b4ce169 | 67 | //virtual void printTime(time_t t, uint8_t hundredths) = 0; |
Backstrom | 0:f6e68b4ce169 | 68 | virtual void printTime(struct tm* tm, uint8_t hundredths) = 0; |
Backstrom | 0:f6e68b4ce169 | 69 | virtual void printTimeLong(struct tm* tm, uint8_t hundredths) = 0; |
Backstrom | 0:f6e68b4ce169 | 70 | virtual void printTimeSet(struct tm* tm, bool showSeconds = true) = 0; |
Backstrom | 0:f6e68b4ce169 | 71 | virtual void printDate(struct tm* tm) = 0; |
Backstrom | 0:f6e68b4ce169 | 72 | |
Backstrom | 0:f6e68b4ce169 | 73 | void setBrightness(uint8_t brite); |
Backstrom | 0:f6e68b4ce169 | 74 | uint8_t getBrightness() { return m_brightness; } |
Backstrom | 0:f6e68b4ce169 | 75 | uint8_t incBrightness(); |
Backstrom | 0:f6e68b4ce169 | 76 | |
Backstrom | 0:f6e68b4ce169 | 77 | uint8_t digits() { return m_digits; } |
Backstrom | 0:f6e68b4ce169 | 78 | |
Backstrom | 0:f6e68b4ce169 | 79 | void setBlinkMode(BlinkMode blink_mode) { m_blink_mode = blink_mode; } |
Backstrom | 0:f6e68b4ce169 | 80 | void blink(bool b) { m_blink = b; m_display_on = true; } |
Backstrom | 0:f6e68b4ce169 | 81 | void blank(bool b) { m_blank = b; } |
Backstrom | 0:f6e68b4ce169 | 82 | |
Backstrom | 0:f6e68b4ce169 | 83 | protected: |
Backstrom | 0:f6e68b4ce169 | 84 | DigitalOut m_data; |
Backstrom | 0:f6e68b4ce169 | 85 | DigitalOut m_clock; |
Backstrom | 0:f6e68b4ce169 | 86 | DigitalOut m_latch; |
Backstrom | 0:f6e68b4ce169 | 87 | //PwmOut m_blank; |
Backstrom | 0:f6e68b4ce169 | 88 | DigitalOut m_blank; |
Backstrom | 0:f6e68b4ce169 | 89 | |
Backstrom | 0:f6e68b4ce169 | 90 | uint8_t m_digits; |
Backstrom | 0:f6e68b4ce169 | 91 | uint8_t m_multiplex_limit; |
Backstrom | 0:f6e68b4ce169 | 92 | uint8_t m_multiplex_counter; |
Backstrom | 0:f6e68b4ce169 | 93 | bool m_reverse_display; |
Backstrom | 0:f6e68b4ce169 | 94 | uint8_t m_position; |
Backstrom | 0:f6e68b4ce169 | 95 | int8_t m_scroll_offset; |
Backstrom | 0:f6e68b4ce169 | 96 | uint8_t m_message_length; |
Backstrom | 0:f6e68b4ce169 | 97 | bool m_has_dots; |
Backstrom | 0:f6e68b4ce169 | 98 | |
Backstrom | 0:f6e68b4ce169 | 99 | char m_buffer[MESSAGE_LIMIT]; |
Backstrom | 0:f6e68b4ce169 | 100 | char m_dot_buffer[MESSAGE_LIMIT]; |
Backstrom | 0:f6e68b4ce169 | 101 | char m_char_buffer[MESSAGE_LIMIT]; |
Backstrom | 0:f6e68b4ce169 | 102 | |
Backstrom | 0:f6e68b4ce169 | 103 | void writeHV5812(uint8_t data); |
Backstrom | 0:f6e68b4ce169 | 104 | virtual uint16_t calculateSegments(char c, uint8_t digit) = 0; |
Backstrom | 0:f6e68b4ce169 | 105 | virtual void handleBlink(char d) = 0; |
Backstrom | 0:f6e68b4ce169 | 106 | |
Backstrom | 0:f6e68b4ce169 | 107 | // extra indicators (not present on all displays |
Backstrom | 0:f6e68b4ce169 | 108 | bool m_alarm_indicator; |
Backstrom | 0:f6e68b4ce169 | 109 | bool m_gps_indicator; |
Backstrom | 0:f6e68b4ce169 | 110 | bool m_colon; |
Backstrom | 0:f6e68b4ce169 | 111 | uint16_t m_dots; |
Backstrom | 0:f6e68b4ce169 | 112 | |
Backstrom | 0:f6e68b4ce169 | 113 | // display blinking |
Backstrom | 0:f6e68b4ce169 | 114 | volatile bool m_blink; |
Backstrom | 0:f6e68b4ce169 | 115 | volatile bool m_display_on; |
Backstrom | 0:f6e68b4ce169 | 116 | |
Backstrom | 0:f6e68b4ce169 | 117 | // brightness |
Backstrom | 0:f6e68b4ce169 | 118 | uint8_t m_brightness; |
Backstrom | 0:f6e68b4ce169 | 119 | |
Backstrom | 0:f6e68b4ce169 | 120 | public: |
Backstrom | 0:f6e68b4ce169 | 121 | virtual void writeDisplay(uint8_t digit, uint16_t segments) = 0; |
Backstrom | 0:f6e68b4ce169 | 122 | void multiplexTick(); |
Backstrom | 0:f6e68b4ce169 | 123 | |
Backstrom | 0:f6e68b4ce169 | 124 | protected: |
Backstrom | 0:f6e68b4ce169 | 125 | virtual int _putc(int c); |
Backstrom | 0:f6e68b4ce169 | 126 | virtual int _getc(); |
Backstrom | 0:f6e68b4ce169 | 127 | }; |
Backstrom | 0:f6e68b4ce169 | 128 | |
Backstrom | 0:f6e68b4ce169 | 129 | #endif // __VFDDISPLAY_H_ |