ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/DashInterface/Display.hpp
Revision: 31
Committed: 2008-02-28T22:06:06-08:00 (17 years, 3 months ago) by douglas
File size: 5181 byte(s)
Log Message:
Snarfed some Menes code...

File Contents

# Content
1 // Display (Crystalfontz CFA-635 USB LCD)
2 //
3 // Douglas Thrift
4 //
5 // $Id$
6
7 #ifndef _Display_hpp_
8 #define _Display_hpp_
9
10 #include <threads.hpp>
11 #include <truck.hpp>
12
13 #include <queue>
14
15 class Display
16 {
17 int ucom;
18 struct Packet
19 {
20 enum Command
21 {
22 PingCommand = 0x00,
23 GetHardwareAndFirmwareVersion = 0x01,
24 WriteUserFlashArea = 0x02,
25 ReadUserFlashArea = 0x03,
26 StoreCurrentStateAsBootState = 0x04,
27 RebootResetHostOrPowerOffHost = 0x05,
28 ClearLCDScreen = 0x06,
29 SetLCDSpecialCharacterData = 0x09,
30 Read8ByesOfLCDMemory = 0x0a,
31 SetLCDCursorPosition = 0x0b,
32 SetLCDCursorStyle = 0x0c,
33 SetLCDContrast = 0x0d,
34 SetLCDAndKeypadBacklight = 0x0e,
35 SetUpFanReporting = 0x10,
36 SetFanPower = 0x11,
37 ReadDOWDeviceInformation = 0x12,
38 SetUpTemperatureReporting = 0x13,
39 ArbitraryDOWTransaction = 0x14,
40 SendCommandDirectlyToTheLCDController = 0x16,
41 ConfigureKeyReporting = 0x17,
42 ReadKeypad = 0x18,
43 SetFanPowerFailSafe = 0x19,
44 SetFanTachometerGlitchFilter = 0x1a,
45 QueryFanPowerAndFailSafeMask = 0x1b,
46 SetATXPowerSwitchFunctionality = 0x1c,
47 EnableDisableAndResetTheWatchdog = 0x1d,
48 ReadReportingAndStatus = 0x1e,
49 SendDataToLCD = 0x1f,
50 SetBaudRate = 0x21,
51 SetOrSetAndConfigureGPIOPin = 0x22,
52 ReadGPIOPinLevelsAndConfigurationState = 0x23,
53 Response = 0x40,
54 KeyActivity = 0x80,
55 FanSpeedReport = 0x81,
56 TemperatureSensorReport = 0x82,
57 Error = 0xc0,
58 };
59
60 uint8_t command;
61 uint8_t length;
62 uint8_t data[22];
63 uint16_t crc;
64
65 inline Packet() {}
66 Packet(Command command, uint8_t length, const uint8_t *data);
67
68 inline std::string GetData() const { return std::string(reinterpret_cast<const char *>(data), length); }
69 };
70 std::queue<Packet> keyActivity;
71 Pthreads::Thread thread;
72
73 inline Packet Communicate(Packet::Command command) { return Communicate_(command, 0, reinterpret_cast<const uint8_t *>(NULL)); }
74 template <typename Arg0>
75 Packet Communicate(Packet::Command command, Arg0 arg0);
76 template <typename Arg0, typename Arg1>
77 Packet Communicate(Packet::Command command, Arg0 arg0, Arg1 arg1);
78 template <typename Arg0, typename Arg1, typename Arg2>
79 Packet Communicate(Packet::Command command, Arg0 arg0, Arg1 arg1, Arg2 arg2);
80 Packet Communicate_(Packet::Command command, uint8_t length, const uint8_t *data);
81
82 public:
83 enum CursorStyle
84 {
85 NoCursor = 0,
86 BlinkingBlockCursor = 1,
87 UnderscoreCursor = 2,
88 BlinkingBlockPlusUnderscore = 3,
89 InvertingBlinkingBlock = 4,
90 };
91 enum Key
92 {
93 Up = 0x01,
94 Enter = 0x02,
95 Cancel = 0x04,
96 Left = 0x08,
97 Right = 0x10,
98 Down = 0x20,
99 };
100 enum Color
101 {
102 Green = 1,
103 Red = 0,
104 };
105
106 Display(const std::string &device);
107 ~Display() { Posix::Close(ucom); }
108
109 bool Ping(const std::string &data = std::string());
110 std::string Version();
111 inline void Store() { Communicate(Packet::StoreCurrentStateAsBootState); }
112 inline void Clear() { Communicate(Packet::ClearLCDScreen); }
113 inline void SetCursorPosition(uint8_t column, uint8_t row) { Communicate(Packet::SetLCDCursorPosition, column, row); }
114 inline void SetCursorStyle(CursorStyle style) { Communicate(Packet::SetLCDCursorStyle, style); }
115 inline void SetContrast(uint8_t contrast) { Communicate(Packet::SetLCDContrast, contrast); }
116 inline void SetBacklight(uint8_t backlight) { Communicate(Packet::SetLCDAndKeypadBacklight, backlight); }
117 inline void KeyReporting(uint8_t press, uint8_t release) { Communicate(Packet::ConfigureKeyReporting, press, release); }
118 void Set(uint8_t column, uint8_t row, const std::string &data);
119 void Set(uint8_t led, Color color, uint8_t brightness) { Communicate(Packet::SetOrSetAndConfigureGPIOPin, 12 - (led << 1) - color, brightness); }
120
121 friend std::ostream &operator<<(std::ostream &output, const Packet &packet);
122 friend void operator<<(int fd, const Display::Packet &packet);
123 friend void operator>>(int fd, Display::Packet &packet);
124 friend void Communicate(Display *display);
125 };
126
127 template <typename Arg0>
128 inline Display::Packet Display::Communicate(Packet::Command command, Arg0 arg0)
129 {
130 uint8_t data(arg0);
131
132 return Communicate_(command, 1, &data);
133 }
134
135 template <>
136 inline Display::Packet Display::Communicate(Packet::Command command, const std::string &string)
137 {
138 return Communicate_(command, string.size(), reinterpret_cast<const uint8_t *>(string.data()));
139 }
140
141 template <typename Arg0, typename Arg1>
142 inline Display::Packet Display::Communicate(Packet::Command command, Arg0 arg0, Arg1 arg1)
143 {
144 uint8_t data[] = { arg0, arg1 };
145
146 return Communicate_(command, 2, data);
147 }
148
149 template <typename Arg0, typename Arg1, typename Arg2>
150 inline Display::Packet Display::Communicate(Packet::Command command, Arg0 arg0, Arg1 arg1, Arg2 arg2)
151 {
152 uint8_t data[] = { arg0, arg1, arg2 };
153
154 return Communicate_(command, 2, data);
155 }
156
157 template <>
158 inline Display::Packet Display::Communicate(Packet::Command command, uint8_t arg0, uint8_t arg1, std::string string)
159 {
160 string.insert(0, 1, arg0);
161 string.insert(1, 1, arg1);
162
163 return Communicate<const std::string &>(command, string);
164 }
165
166 #endif//_Display_hpp_

Properties

Name Value
svn:keywords Id