// Display (Crystalfontz CFA-635 USB LCD) // // Douglas Thrift // // $Id$ #ifndef _Display_hpp_ #define _Display_hpp_ #include #include #include class Display { int ucom; struct Packet { enum Command { PingCommand = 0x00, GetHardwareAndFirmwareVersion = 0x01, WriteUserFlashArea = 0x02, ReadUserFlashArea = 0x03, StoreCurrentStateAsBootState = 0x04, RebootResetHostOrPowerOffHost = 0x05, ClearLCDScreen = 0x06, SetLCDSpecialCharacterData = 0x09, Read8ByesOfLCDMemory = 0x0a, SetLCDCursorPosition = 0x0b, SetLCDCursorStyle = 0x0c, SetLCDContrast = 0x0d, SetLCDAndKeypadBacklight = 0x0e, SetUpFanReporting = 0x10, SetFanPower = 0x11, ReadDOWDeviceInformation = 0x12, SetUpTemperatureReporting = 0x13, ArbitraryDOWTransaction = 0x14, SendCommandDirectlyToTheLCDController = 0x16, ConfigureKeyReporting = 0x17, ReadKeypad = 0x18, SetFanPowerFailSafe = 0x19, SetFanTachometerGlitchFilter = 0x1a, QueryFanPowerAndFailSafeMask = 0x1b, SetATXPowerSwitchFunctionality = 0x1c, EnableDisableAndResetTheWatchdog = 0x1d, ReadReportingAndStatus = 0x1e, SendDataToLCD = 0x1f, SetBaudRate = 0x21, SetOrSetAndConfigureGPIOPin = 0x22, ReadGPIOPinLevelsAndConfigurationState = 0x23, Response = 0x40, KeyActivity = 0x80, FanSpeedReport = 0x81, TemperatureSensorReport = 0x82, Error = 0xc0, }; uint8_t command; uint8_t length; uint8_t data[22]; uint16_t crc; inline Packet() {} Packet(Command command, uint8_t length, const uint8_t *data); inline std::string GetData() { return std::string(reinterpret_cast(data), length); } }; std::queue keyActivity; Packet Communicate(Packet::Command command, uint8_t length = 0, const uint8_t *data = NULL); inline Packet Communicate(Packet::Command command, const std::string &data) { return Communicate(command, data.size(), reinterpret_cast(data.data())); } public: enum CursorStyle { NoCursor, BlinkingBlockCursor, UnderscoreCursor, BlinkingBlockPlusUnderscore, InvertingBlinkingBlock }; enum Key { Up = 0x01, Enter = 0x02, Cancel = 0x04, Left = 0x08, Right = 0x10, Down = 0x20, }; Display(const std::string &device); ~Display() { Posix::Close(ucom); } bool Ping(const std::string &data = std::string()); std::string Version(); inline void Store() { Communicate(Packet::StoreCurrentStateAsBootState); } inline void Clear() { Communicate(Packet::ClearLCDScreen); } void SetCursorPosition(uint8_t column, uint8_t row); void SetCursorStyle(CursorStyle style); inline void SetContrast(uint8_t contrast) { Communicate(Packet::SetLCDContrast, 1, &contrast); } inline void SetBacklight(uint8_t backlight) { Communicate(Packet::SetLCDAndKeypadBacklight, 1, &backlight); } inline void KeyReporting(uint8_t press, uint8_t release); }; #endif//_Display_hpp_