ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/DashInterface/Display.hpp
Revision: 30
Committed: 2008-02-28T17:01:10-08:00 (17 years, 3 months ago) by douglas
File size: 5109 byte(s)
Log Message:
w00t! Moar progress!

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 <posix.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
72 inline Packet Communicate(Packet::Command command) { return Communicate_(command, 0, reinterpret_cast<const uint8_t *>(NULL)); }
73 template <typename Arg0>
74 Packet Communicate(Packet::Command command, Arg0 arg0);
75 template <typename Arg0, typename Arg1>
76 Packet Communicate(Packet::Command command, Arg0 arg0, Arg1 arg1);
77 template <typename Arg0, typename Arg1, typename Arg2>
78 Packet Communicate(Packet::Command command, Arg0 arg0, Arg1 arg1, Arg2 arg2);
79 Packet Communicate_(Packet::Command command, uint8_t length, const uint8_t *data);
80
81 public:
82 enum CursorStyle
83 {
84 NoCursor = 0,
85 BlinkingBlockCursor = 1,
86 UnderscoreCursor = 2,
87 BlinkingBlockPlusUnderscore = 3,
88 InvertingBlinkingBlock = 4,
89 };
90 enum Key
91 {
92 Up = 0x01,
93 Enter = 0x02,
94 Cancel = 0x04,
95 Left = 0x08,
96 Right = 0x10,
97 Down = 0x20,
98 };
99 enum Color
100 {
101 Green = 1,
102 Red = 0,
103 };
104
105 Display(const std::string &device);
106 ~Display() { Posix::Close(ucom); }
107
108 bool Ping(const std::string &data = std::string());
109 std::string Version();
110 inline void Store() { Communicate(Packet::StoreCurrentStateAsBootState); }
111 inline void Clear() { Communicate(Packet::ClearLCDScreen); }
112 inline void SetCursorPosition(uint8_t column, uint8_t row) { Communicate(Packet::SetLCDCursorPosition, column, row); }
113 inline void SetCursorStyle(CursorStyle style) { Communicate(Packet::SetLCDCursorStyle, style); }
114 inline void SetContrast(uint8_t contrast) { Communicate(Packet::SetLCDContrast, contrast); }
115 inline void SetBacklight(uint8_t backlight) { Communicate(Packet::SetLCDAndKeypadBacklight, backlight); }
116 inline void KeyReporting(uint8_t press, uint8_t release) { Communicate(Packet::ConfigureKeyReporting, press, release); }
117 void Set(uint8_t column, uint8_t row, const std::string &data);
118 void Set(uint8_t led, Color color, uint8_t brightness) { Communicate(Packet::SetOrSetAndConfigureGPIOPin, 12 - (led << 1) - color, brightness); }
119
120 friend std::ostream &operator<<(std::ostream &output, const Packet &packet);
121 friend void operator<<(int fd, const Display::Packet &packet);
122 friend void operator>>(int fd, Display::Packet &packet);
123 };
124
125 template <typename Arg0>
126 inline Display::Packet Display::Communicate(Packet::Command command, Arg0 arg0)
127 {
128 uint8_t data(arg0);
129
130 return Communicate_(command, 1, &data);
131 }
132
133 template <>
134 inline Display::Packet Display::Communicate(Packet::Command command, const std::string &string)
135 {
136 return Communicate_(command, string.size(), reinterpret_cast<const uint8_t *>(string.data()));
137 }
138
139 template <typename Arg0, typename Arg1>
140 inline Display::Packet Display::Communicate(Packet::Command command, Arg0 arg0, Arg1 arg1)
141 {
142 uint8_t data[] = { arg0, arg1 };
143
144 return Communicate_(command, 2, data);
145 }
146
147 template <typename Arg0, typename Arg1, typename Arg2>
148 inline Display::Packet Display::Communicate(Packet::Command command, Arg0 arg0, Arg1 arg1, Arg2 arg2)
149 {
150 uint8_t data[] = { arg0, arg1, arg2 };
151
152 return Communicate_(command, 2, data);
153 }
154
155 template <>
156 inline Display::Packet Display::Communicate(Packet::Command command, uint8_t arg0, uint8_t arg1, std::string string)
157 {
158 string.insert(0, 1, arg0);
159 string.insert(1, 1, arg1);
160
161 return Communicate<const std::string &>(command, string);
162 }
163
164 #endif//_Display_hpp_

Properties

Name Value
svn:keywords Id