VFD modular clock firmware

Dependencies:   DipCortex-EEprom RTC flw mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers VFDDisplay.h Source File

VFDDisplay.h

00001 /*
00002  * VFD Modular Clock - mbed
00003  * (C) 2011-14 Akafugu Corporation
00004  *
00005  * This program is free software; you can redistribute it and/or modify it under the
00006  * terms of the GNU General Public License as published by the Free Software
00007  * Foundation; either version 2 of the License, or (at your option) any later
00008  * version.
00009  *
00010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
00011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
00012  * PARTICULAR PURPOSE.  See the GNU General Public License for more details.
00013  *
00014  */
00015 
00016 #ifndef __VFDDISPLAY_H_
00017 #define __VFDDISPLAY_H_
00018 
00019 #include "mbed.h"
00020 
00021 #define MESSAGE_LIMIT 96
00022 
00023 class VFDDisplay : public Stream {
00024 public:
00025     enum TimeMode {
00026         Long = 0,
00027         Short,
00028         Extra 
00029     };
00030     
00031     // Controls how display blinks when m_blink is true
00032     enum BlinkMode {
00033         Full = 0, // Blink whole display
00034         Hours,    // Blink hours
00035         Minutes,  // Blink minutes
00036         Seconds   // Blink seconds
00037     };
00038     
00039 protected:
00040     TimeMode m_mode;
00041     BlinkMode m_blink_mode;
00042     
00043 public:
00044     VFDDisplay(PinName data, PinName clock, PinName latch, PinName blank, uint8_t digits);
00045 
00046     virtual void cls();
00047     virtual void setPosition(uint8_t pos);
00048     
00049     virtual int putc(int c) { return _putc(c); }
00050     int printf(const char* format, ...);
00051 
00052     void scroll(int8_t spaces = 1);
00053     void resetScroll();
00054     bool scrollFinished();
00055     bool scrollAtOrigin() { return m_scroll_offset == 0; }
00056 
00057     void setAlarmIndicator(bool on) { m_alarm_indicator = on; }
00058     void setGPSIndicator(bool on)   { m_gps_indicator   = on; }
00059     void setColon(bool on)          { m_colon = on; }
00060     
00061     void setDots(uint16_t dots) { m_dots = dots; }
00062     void setDot(uint8_t pos, bool on);
00063 
00064     void setTimeMode(TimeMode mode) { m_mode = mode; }
00065     void toggleTimeMode();
00066     
00067     //virtual void printTime(time_t t, uint8_t hundredths) = 0;
00068     virtual void printTime(struct tm* tm, uint8_t hundredths) = 0;
00069     virtual void printTimeLong(struct tm* tm, uint8_t hundredths) = 0;
00070     virtual void printTimeSet(struct tm* tm, bool showSeconds = true) = 0;
00071     virtual void printDate(struct tm* tm) = 0;
00072     
00073     void setBrightness(uint8_t brite);
00074     uint8_t getBrightness() { return m_brightness; }
00075     uint8_t incBrightness();
00076 
00077     uint8_t digits() { return m_digits; }
00078     
00079     void setBlinkMode(BlinkMode blink_mode) { m_blink_mode = blink_mode; }
00080     void blink(bool b) { m_blink = b; m_display_on = true; }
00081     void blank(bool b) { m_blank = b; }    
00082     
00083 protected:
00084     DigitalOut m_data;
00085     DigitalOut m_clock;
00086     DigitalOut m_latch;
00087     //PwmOut m_blank;
00088     DigitalOut m_blank;
00089 
00090     uint8_t m_digits;
00091     uint8_t m_multiplex_limit;
00092     uint8_t m_multiplex_counter;
00093     bool m_reverse_display;
00094     uint8_t m_position;
00095     int8_t m_scroll_offset;
00096     uint8_t m_message_length;
00097     bool m_has_dots;
00098 
00099     char m_buffer[MESSAGE_LIMIT];
00100     char m_dot_buffer[MESSAGE_LIMIT];
00101     char m_char_buffer[MESSAGE_LIMIT];
00102         
00103     void writeHV5812(uint8_t data);
00104     virtual uint16_t calculateSegments(char c, uint8_t digit) = 0;
00105     virtual void handleBlink(char d) = 0;
00106     
00107     // extra indicators (not present on all displays
00108     bool m_alarm_indicator;
00109     bool m_gps_indicator;
00110     bool m_colon;
00111     uint16_t m_dots;
00112     
00113     // display blinking
00114     volatile bool m_blink;
00115     volatile bool m_display_on;
00116     
00117     // brightness
00118     uint8_t m_brightness;
00119 
00120 public:
00121     virtual void writeDisplay(uint8_t digit, uint16_t segments) = 0;
00122     void multiplexTick();
00123             
00124 protected:
00125     virtual int _putc(int c);
00126     virtual int _getc();
00127 };
00128 
00129 #endif // __VFDDISPLAY_H_