# HG changeset patch # User sl # Date 1409513736 -7200 # Node ID 591e9f922c6343aa827283065e73fff92c7ce596 # Parent 42ba42be810d109a8b17f5c43390f3661708c2b1 GP1212A02: Clock support. diff -r 42ba42be810d -r 591e9f922c63 Display.h --- a/Display.h Sun Aug 31 18:33:31 2014 +0200 +++ b/Display.h Sun Aug 31 21:35:36 2014 +0200 @@ -5,6 +5,7 @@ #ifndef DISPLAY_H #define DISPLAY_H + #include "HidDevice.h" const int KMaxDisplayStringLength = 256; @@ -47,7 +48,11 @@ virtual void TurnPowerOn(){} virtual void TurnPowerOff(){} - virtual bool SupportPowerOnOff(){return false;} + virtual bool SupportPowerOnOff(){return false;} + + virtual void ShowClock(){} + virtual void HideClock(){} + virtual bool SupportClock(){return false;} protected: void SetRequest(TMiniDisplayRequest aRequest) { iRequest=aRequest; } diff -r 42ba42be810d -r 591e9f922c63 FutabaGP1212A02.cpp --- a/FutabaGP1212A02.cpp Sun Aug 31 18:33:31 2014 +0200 +++ b/FutabaGP1212A02.cpp Sun Aug 31 21:35:36 2014 +0200 @@ -4,8 +4,8 @@ #include "FutabaGP1212A02.h" - -const int KNumberOfFrameBeforeDiffAlgo = 3; +#include +#include const unsigned short KMaxDataMemoryAddress = 0x4FFF; const unsigned short KFrameSizeInBytes = 0x800; @@ -82,15 +82,19 @@ // SetNonBlocking(1); // - SendClearCommand(); + SendCommandClear(); + // + SetClockSetting(); + //BMP box setup could be removed if we don't use it anymore //Setup BMP box BmpBoxSetting(EBmpBoxIdOne,0x0000,256,64); - //Select current BMP box BmpBoxSelect(EBmpBoxIdOne); + // + iNextFrameAddress = 0x0000; - iNextFrameAddress = 0x0000; + } return success; @@ -216,7 +220,7 @@ } else { - SendClearCommand(); + SendCommandClear(); } } @@ -380,7 +384,7 @@ Using this function is advised against as is causes tearing. Use Clear instead. */ -void GP1212A02A::SendClearCommand() +void GP1212A02A::SendCommandClear() { //1BH,4AH,43H,44H //Send Clear Display Command @@ -677,6 +681,7 @@ void GP1212A02A::TurnPowerOn() { SendCommandPower(EPowerOn); + SetClockSetting(); } /** @@ -685,3 +690,205 @@ { SendCommandPower(EPowerOff); } + + +/** +Number of characters for the given clock format. +@return +*/ +int GP1212A02A::ClockCharCount(TClockFormat aFormat) + { + switch (aFormat) + { + case EClockDay12: + case EClockDay24: + return 10; + case EClock12: + case EClock24: + return 5; + } + + return 10; + } + +/** +@return +*/ +int GP1212A02A::ClockCharWidthInPixels(TClockSize aSize) + { + switch (aSize) + { + case EClockTiny: + return 6; + case EClockSmall: + return 8; + case EClockMedium: + return 12; + case EClockLarge: + return 16; + } + + return 16; + } + +/** +@return +*/ +int GP1212A02A::ClockCharHeightInPixels(TClockSize aSize) + { + switch (aSize) + { + case EClockTiny: + return 8; + case EClockSmall: + return 16; + case EClockMedium: + return 24; + case EClockLarge: + return 32; + } + + return 32; + } + +/** +Return the Display Window address for centering the clock corresponding to the given parameters. +*/ +unsigned short GP1212A02A::ClockCenterAddress(TClockFormat aFormat, TClockSize aSize) + { + int charCount=ClockCharCount(aFormat); + int halfWidth=(ClockCharWidthInPixels(aSize)*charCount)/2; + int halfHeight=(ClockCharHeightInPixels(aSize))/2; + int x=(WidthInPixels()/2)-halfWidth; + int y=(HeightInPixels()/2)-halfHeight; + + int yOffset=y/8; + int xOffset=x*8; //Not sure why... + + unsigned short address = yOffset+xOffset; + // + return address; + } + +/** +*/ +void GP1212A02A::ShowClock() + { + SendCommandClockDisplay(EClockDay24,ClockCenterAddress(EClockDay24,EClockLarge),EClockLarge); + } + +/** +*/ +void GP1212A02A::HideClock() + { + SendCommandClockCancel(); + } + + +/** +Clock setting +[Code]1BH,6BH,53H,Pd,Ph,Pm +[Function]Setting the clock data. The setting data is cleared, if the Reset command is input or power +is turned off. +Pd = Day of the week +Ph = hour +Pm = minute +[Definable area] +Pd = 00H : Sunday +Pd = 01H : Monday +... +Pd = 06H : Saturday +* Clock setting is canceled, when Pd is input value that is larger than 07H, or Ph is input value that is +larger than 18H,or Pm is input value that is larger than 3CH. +*/ +void GP1212A02A::SendCommandClockSetting(TWeekDay aWeekDay, unsigned char aHour, unsigned char aMinute) + { + FutabaVfdReport report; + report[0]=0x00; //Report ID + report[1]=0x06; //Report size + report[2]=0x1B; //Command ID + report[3]=0x6B; //Command ID + report[4]=0x53; //Command ID + report[5]=aWeekDay; //Sunday to Saturday + report[6]=aHour; + report[7]=aMinute; + + Write(report); + } + + +/** +Set display clock settings according to local system time. +This needs to be redone whenever we open or turn on our display. +*/ +void GP1212A02A::SetClockSetting() + { + time_t rawtime; + struct tm * timeinfo; + + time ( &rawtime ); + timeinfo = localtime ( &rawtime ); + // + SendCommandClockSetting((TWeekDay)timeinfo->tm_wday,timeinfo->tm_hour,timeinfo->tm_min); + } + + +/** +Clock display +[Code] 1BH,6BH,55H,Ps,aL,aH,Pf +[Function] Clock is displayed. The display position and the font size can be freely decided. +Ps = Display type select +aL,aH = Address +Pf = Font size select +[Definable area] +Ps = 00H : 24hour Ex.[12:34] +Ps = 01H : 24hour + day of the week Ex.[Wed._12:34] +Ps = 10H : 12hour Ex.[PM_00:34] +Ps = 11H : 12hour + day of the week Ex.[Wed._PM_00:34] +Pf = 30H : 6x8 dot +Pf = 31H : 8x16dot +Pf = 32H : 12x24 dot +Pf = 33H : 16x32 dot +* When the clock data is not input, clock is not displayed. +* The clock display is maintained until Clock display cancel "Clear display" RESET command is input +or power is turned off. +The clock display area +Graphic can be displayed excluding the clock display area. +The self adjustment for the position +that cannot be displayed. +* Excluding the clock display area can be input other display commands. +*/ +void GP1212A02A::SendCommandClockDisplay(TClockFormat aClockFormat, unsigned short aAddress, TClockSize aSize) + { + FutabaVfdReport report; + report[0]=0x00; //Report ID + report[1]=0x07; //Report size + report[2]=0x1B; //Command ID + report[3]=0x6B; //Command ID + report[4]=0x55; //Command ID + report[5]=aClockFormat; // + report[6]=(unsigned char)aAddress; //aL + report[7]=aAddress>>8; //aH + report[8]=aSize; + + Write(report); + } + + +/** + Clock display cancel +[Code] 1BH,6BH,3DH,58H +[Function] Clock display is canceled. +*/ +void GP1212A02A::SendCommandClockCancel() + { + FutabaVfdReport report; + report[0]=0x00; //Report ID + report[1]=0x04; //Report size + report[2]=0x1B; //Command ID + report[3]=0x6B; //Command ID + report[4]=0x3D; //Command ID + report[5]=0x58; // + + Write(report); + } diff -r 42ba42be810d -r 591e9f922c63 FutabaGP1212A02.h --- a/FutabaGP1212A02.h Sun Aug 31 18:33:31 2014 +0200 +++ b/FutabaGP1212A02.h Sun Aug 31 21:35:36 2014 +0200 @@ -27,7 +27,11 @@ virtual void SwapBuffers(); virtual void TurnPowerOn(); virtual void TurnPowerOff(); - virtual bool SupportPowerOnOff(){return true;} + virtual bool SupportPowerOnOff(){return true;} + virtual void ShowClock(); + virtual void HideClock(); + virtual bool SupportClock(){return true;} + //From GraphicDisplay @@ -55,6 +59,8 @@ char* DeviceId(); char* FirmwareRevision(); +private: + enum TBmpBoxId { EBmpBoxIdNull=0x30, @@ -81,28 +87,70 @@ EPowerOn=0x31 }; + enum TWeekDay + { + ESunday = 0x00, + EMonday = 0x01, + ETuesday = 0x02, + EWednesday = 0x03, + EThrusday = 0x04, + EFriday = 0x05, + ESaturday = 0x06 + }; + + enum TClockFormat + { + EClock24 = 0x00, + EClockDay24 = 0x01, + EClock12 = 0x10, + EClockDay12 = 0x11 + }; + + enum TClockSize + { + EClockTiny = 0x30, + EClockSmall = 0x31, + EClockMedium = 0x32, + EClockLarge = 0x33 + }; + + private: //Specific to GP1212A02A //General setting command + void SendCommandClear(); + // void BmpDataInput(TTarget aTarget, unsigned short aAddress, TDirection aDirection, unsigned short aSize, unsigned char* aPixels); + // + void SendCommandPower(TPowerStatus aPowerStatus); + //Clock commands + void SendCommandClockSetting(TWeekDay aWeekDay, unsigned char aHour, unsigned char aMinute); + void SendCommandClockDisplay(TClockFormat aClockFormat, unsigned short aAddress, TClockSize aSize); + void SendCommandClockCancel(); + //BMP box void BmpBoxSetting(TBmpBoxId aBoxId, unsigned short aAddress, int aWidth, int aHeight); void BmpBoxSelect(TBmpBoxId aBoxId); void BmpBoxDataMemoryTransfer(unsigned short aAddress); void BmpBoxDataInput(unsigned short aSize, unsigned char* aPixels); - // - void SendCommandPower(TPowerStatus aPowerStatus); + + //Clock utilities + int ClockCharCount(TClockFormat aFormat); + int ClockCharWidthInPixels(TClockSize aSize); + int ClockCharHeightInPixels(TClockSize aSize); + unsigned short ClockCenterAddress(TClockFormat aFormat, TClockSize aSize); private: void RequestDeviceId(); void RequestFirmwareRevision(); void RequestPowerSupplyStatus(); + // + void SetClockSetting(); private: - unsigned char OffScreenY() const; - void SendClearCommand(); + unsigned char OffScreenY() const; void OffScreenTranslation(unsigned char& aX, unsigned char& aY); void ResetBuffers(); diff -r 42ba42be810d -r 591e9f922c63 MiniDisplay.cpp --- a/MiniDisplay.cpp Sun Aug 31 18:33:31 2014 +0200 +++ b/MiniDisplay.cpp Sun Aug 31 21:35:36 2014 +0200 @@ -220,4 +220,22 @@ bool MiniDisplaySupportPowerOnOff(MiniDisplayDevice aDevice) { return ((GraphicDisplay*)aDevice)->SupportPowerOnOff(); + } + +//------------------------------------------------------------- +void MiniDisplayShowClock(MiniDisplayDevice aDevice) + { + ((GraphicDisplay*)aDevice)->ShowClock(); + } + +//------------------------------------------------------------- +void MiniDisplayHideClock(MiniDisplayDevice aDevice) + { + ((GraphicDisplay*)aDevice)->HideClock(); + } + +//------------------------------------------------------------- +bool MiniDisplaySupportClock(MiniDisplayDevice aDevice) + { + return ((GraphicDisplay*)aDevice)->SupportClock(); } \ No newline at end of file diff -r 42ba42be810d -r 591e9f922c63 MiniDisplay.h --- a/MiniDisplay.h Sun Aug 31 18:33:31 2014 +0200 +++ b/MiniDisplay.h Sun Aug 31 21:35:36 2014 +0200 @@ -204,6 +204,25 @@ */ extern "C" MDAPI bool MiniDisplaySupportPowerOnOff(MiniDisplayDevice aDevice); +/** +Show built-in clock. +@param [IN] The device to apply this command to. +*/ +extern "C" MDAPI void MiniDisplayShowClock(MiniDisplayDevice aDevice); + +/** +Hide built-in clock. +@param [IN] The device to apply this command to. +*/ +extern "C" MDAPI void MiniDisplayHideClock(MiniDisplayDevice aDevice); + +/** +Specifies whether or not this display supports clock functions. +@param [IN] The device to apply this command to. +@return True if this display supports built-in clock, false otherwise. +*/ +extern "C" MDAPI bool MiniDisplaySupportClock(MiniDisplayDevice aDevice); + #endif