ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/DashInterface/Display.hpp
Revision: 44
Committed: 2008-03-06T15:21:03-08:00 (14 years, 8 months ago) by douglas
File size: 6169 byte(s)
Log Message:
Cleanup!

File Contents

# User Rev Content
1 douglas 26 // Display (Crystalfontz CFA-635 USB LCD)
2 douglas 6 //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7 douglas 26 #ifndef _Display_hpp_
8     #define _Display_hpp_
9 douglas 6
10 douglas 31 #include <threads.hpp>
11 douglas 25 #include <truck.hpp>
12    
13 douglas 28 #include <queue>
14    
15 douglas 26 class Display
16 douglas 25 {
17 douglas 26 int ucom;
18 douglas 33 Pthreads::ThreadMutex ucomLock;
19     Pthreads::ThreadCondition ucomCondition;
20     volatile bool running;
21 douglas 38
22 douglas 26 struct Packet
23     {
24     enum Command
25     {
26     PingCommand = 0x00,
27     GetHardwareAndFirmwareVersion = 0x01,
28     WriteUserFlashArea = 0x02,
29     ReadUserFlashArea = 0x03,
30     StoreCurrentStateAsBootState = 0x04,
31     RebootResetHostOrPowerOffHost = 0x05,
32     ClearLCDScreen = 0x06,
33     SetLCDSpecialCharacterData = 0x09,
34     Read8ByesOfLCDMemory = 0x0a,
35     SetLCDCursorPosition = 0x0b,
36     SetLCDCursorStyle = 0x0c,
37     SetLCDContrast = 0x0d,
38 douglas 28 SetLCDAndKeypadBacklight = 0x0e,
39 douglas 26 SetUpFanReporting = 0x10,
40     SetFanPower = 0x11,
41     ReadDOWDeviceInformation = 0x12,
42     SetUpTemperatureReporting = 0x13,
43     ArbitraryDOWTransaction = 0x14,
44     SendCommandDirectlyToTheLCDController = 0x16,
45     ConfigureKeyReporting = 0x17,
46     ReadKeypad = 0x18,
47     SetFanPowerFailSafe = 0x19,
48     SetFanTachometerGlitchFilter = 0x1a,
49     QueryFanPowerAndFailSafeMask = 0x1b,
50     SetATXPowerSwitchFunctionality = 0x1c,
51     EnableDisableAndResetTheWatchdog = 0x1d,
52     ReadReportingAndStatus = 0x1e,
53     SendDataToLCD = 0x1f,
54     SetBaudRate = 0x21,
55     SetOrSetAndConfigureGPIOPin = 0x22,
56     ReadGPIOPinLevelsAndConfigurationState = 0x23,
57     Response = 0x40,
58 douglas 33 Report = 0x80,
59 douglas 26 KeyActivity = 0x80,
60     FanSpeedReport = 0x81,
61     TemperatureSensorReport = 0x82,
62     Error = 0xc0,
63     };
64 douglas 25
65 douglas 26 uint8_t command;
66     uint8_t length;
67     uint8_t data[22];
68     uint16_t crc;
69    
70 douglas 28 inline Packet() {}
71     Packet(Command command, uint8_t length, const uint8_t *data);
72    
73 douglas 38 inline std::string GetData() const
74     {
75     return std::string(reinterpret_cast<const char *>(data), length);
76     }
77 douglas 26 };
78 douglas 38
79 douglas 33 std::queue<Packet> responses;
80     Pthreads::ThreadMutex responsesLock;
81     Pthreads::ThreadCondition responsesCondition;
82 douglas 28 std::queue<Packet> keyActivity;
83 douglas 33 Pthreads::ThreadMutex keyActivityLock;
84 douglas 38 Pthreads::ThreadCondition keyActivityCondition;
85 douglas 26
86 douglas 38 inline Packet Communicate(Packet::Command command)
87     {
88     return Communicate_(command, 0, reinterpret_cast<const uint8_t *>(NULL));
89     }
90    
91 douglas 29 template <typename Arg0>
92     Packet Communicate(Packet::Command command, Arg0 arg0);
93     template <typename Arg0, typename Arg1>
94     Packet Communicate(Packet::Command command, Arg0 arg0, Arg1 arg1);
95     template <typename Arg0, typename Arg1, typename Arg2>
96     Packet Communicate(Packet::Command command, Arg0 arg0, Arg1 arg1, Arg2 arg2);
97 douglas 33 void Communicate_();
98 douglas 29 Packet Communicate_(Packet::Command command, uint8_t length, const uint8_t *data);
99 douglas 38 void Activity();
100 douglas 28
101 douglas 25 public:
102 douglas 38 enum KeyActivity
103     {
104     None = 0,
105     UpPress = 1,
106     DownPress = 2,
107     LeftPress = 3,
108     RightPress = 4,
109     EnterPress = 5,
110     ExitPress = 6,
111     UpRelease = 7,
112     DownRelease = 8,
113     LeftRelease = 9,
114     RightRelease = 10,
115     EnterRelease = 11,
116     ExitRelease = 12,
117     };
118    
119 douglas 39 typedef void (*Callback)(KeyActivity, void *);
120 douglas 38
121     private:
122     Callback callback;
123 douglas 39 void *data;
124 douglas 38 Pthreads::Thread communicate, activity;
125    
126     public:
127 douglas 28 enum CursorStyle
128     {
129 douglas 29 NoCursor = 0,
130     BlinkingBlockCursor = 1,
131     UnderscoreCursor = 2,
132     BlinkingBlockPlusUnderscore = 3,
133     InvertingBlinkingBlock = 4,
134 douglas 28 };
135 douglas 38
136 douglas 28 enum Key
137     {
138     Up = 0x01,
139     Enter = 0x02,
140     Cancel = 0x04,
141     Left = 0x08,
142     Right = 0x10,
143     Down = 0x20,
144     };
145 douglas 38
146 douglas 29 enum Color
147     {
148     Green = 1,
149     Red = 0,
150     };
151 douglas 28
152 douglas 39 Display(const std::string &device, Callback callback = NULL, void *data = NULL);
153 douglas 33 ~Display();
154 douglas 25
155 douglas 26 bool Ping(const std::string &data = std::string());
156 douglas 28 std::string Version();
157 douglas 38
158     inline void Store()
159     {
160     Communicate(Packet::StoreCurrentStateAsBootState);
161     }
162    
163     inline void Clear()
164     {
165     Communicate(Packet::ClearLCDScreen);
166     }
167    
168     inline void SetCursorPosition(uint8_t column, uint8_t row)
169     {
170     Communicate(Packet::SetLCDCursorPosition, column, row);
171     }
172    
173     inline void SetCursorStyle(CursorStyle style)
174     {
175     Communicate(Packet::SetLCDCursorStyle, style);
176     }
177    
178     inline void SetContrast(uint8_t contrast)
179     {
180     Communicate(Packet::SetLCDContrast, contrast);
181     }
182    
183     inline void SetBacklight(uint8_t backlight)
184     {
185     Communicate(Packet::SetLCDAndKeypadBacklight, backlight);
186     }
187    
188     inline void KeyReporting(uint8_t press, uint8_t release)
189     {
190     Communicate(Packet::ConfigureKeyReporting, press, release);
191     }
192    
193 douglas 29 void Set(uint8_t column, uint8_t row, const std::string &data);
194 douglas 30
195 douglas 44 inline void Set(uint8_t column, uint8_t row, char data)
196     {
197     Set(column, row, std::string(1, data));
198     }
199    
200 douglas 38 inline void Set(uint8_t led, Color color, uint8_t brightness)
201     {
202     Communicate(Packet::SetOrSetAndConfigureGPIOPin, 12 - (led << 1) - color, brightness);
203     }
204    
205 douglas 30 friend std::ostream &operator<<(std::ostream &output, const Packet &packet);
206     friend void operator<<(int fd, const Display::Packet &packet);
207     friend void operator>>(int fd, Display::Packet &packet);
208 douglas 31 friend void Communicate(Display *display);
209 douglas 38 friend void Activity(Display *display);
210 douglas 25 };
211    
212 douglas 29 template <typename Arg0>
213     inline Display::Packet Display::Communicate(Packet::Command command, Arg0 arg0)
214     {
215     uint8_t data(arg0);
216    
217     return Communicate_(command, 1, &data);
218     }
219    
220     template <>
221     inline Display::Packet Display::Communicate(Packet::Command command, const std::string &string)
222     {
223     return Communicate_(command, string.size(), reinterpret_cast<const uint8_t *>(string.data()));
224     }
225    
226     template <typename Arg0, typename Arg1>
227     inline Display::Packet Display::Communicate(Packet::Command command, Arg0 arg0, Arg1 arg1)
228     {
229     uint8_t data[] = { arg0, arg1 };
230    
231     return Communicate_(command, 2, data);
232     }
233    
234     template <typename Arg0, typename Arg1, typename Arg2>
235     inline Display::Packet Display::Communicate(Packet::Command command, Arg0 arg0, Arg1 arg1, Arg2 arg2)
236     {
237     uint8_t data[] = { arg0, arg1, arg2 };
238    
239     return Communicate_(command, 2, data);
240     }
241    
242     template <>
243 douglas 30 inline Display::Packet Display::Communicate(Packet::Command command, uint8_t arg0, uint8_t arg1, std::string string)
244 douglas 29 {
245 douglas 30 string.insert(0, 1, arg0);
246     string.insert(1, 1, arg1);
247 douglas 29
248 douglas 30 return Communicate<const std::string &>(command, string);
249 douglas 29 }
250    
251 douglas 26 #endif//_Display_hpp_

Properties

Name Value
svn:keywords Id