GP1212A02: Clock support.
authorsl
Sun, 31 Aug 2014 21:35:36 +0200
changeset 17591e9f922c63
parent 16 42ba42be810d
child 18 96c013c63595
GP1212A02: Clock support.
Display.h
FutabaGP1212A02.cpp
FutabaGP1212A02.h
MiniDisplay.cpp
MiniDisplay.h
     1.1 --- a/Display.h	Sun Aug 31 18:33:31 2014 +0200
     1.2 +++ b/Display.h	Sun Aug 31 21:35:36 2014 +0200
     1.3 @@ -5,6 +5,7 @@
     1.4  #ifndef DISPLAY_H
     1.5  #define DISPLAY_H
     1.6  
     1.7 +
     1.8  #include "HidDevice.h"
     1.9  const int KMaxDisplayStringLength = 256;
    1.10  
    1.11 @@ -47,7 +48,11 @@
    1.12  
    1.13  	virtual void TurnPowerOn(){}
    1.14  	virtual void TurnPowerOff(){}
    1.15 -	virtual bool SupportPowerOnOff(){return false;} 
    1.16 +	virtual bool SupportPowerOnOff(){return false;}
    1.17 +
    1.18 +	virtual void ShowClock(){}
    1.19 +	virtual void HideClock(){}
    1.20 +	virtual bool SupportClock(){return false;}
    1.21  
    1.22  protected:
    1.23  	void SetRequest(TMiniDisplayRequest aRequest) { iRequest=aRequest; }
     2.1 --- a/FutabaGP1212A02.cpp	Sun Aug 31 18:33:31 2014 +0200
     2.2 +++ b/FutabaGP1212A02.cpp	Sun Aug 31 21:35:36 2014 +0200
     2.3 @@ -4,8 +4,8 @@
     2.4  
     2.5  #include "FutabaGP1212A02.h"
     2.6  
     2.7 -
     2.8 -const int KNumberOfFrameBeforeDiffAlgo = 3;
     2.9 +#include <stdio.h>
    2.10 +#include <time.h>
    2.11  
    2.12  const unsigned short KMaxDataMemoryAddress = 0x4FFF;
    2.13  const unsigned short KFrameSizeInBytes = 0x800;
    2.14 @@ -82,15 +82,19 @@
    2.15          //
    2.16  		SetNonBlocking(1);
    2.17  		//
    2.18 -		SendClearCommand();
    2.19 +		SendCommandClear();
    2.20 +		//
    2.21 +		SetClockSetting();
    2.22  
    2.23 +		//BMP box setup could be removed if we don't use it anymore
    2.24  		//Setup BMP box
    2.25  		BmpBoxSetting(EBmpBoxIdOne,0x0000,256,64);
    2.26 -
    2.27  		//Select current BMP box
    2.28  		BmpBoxSelect(EBmpBoxIdOne);
    2.29 +		//
    2.30 +		iNextFrameAddress = 0x0000;
    2.31  
    2.32 -		iNextFrameAddress = 0x0000;
    2.33 +
    2.34  
    2.35  		}
    2.36  	return success;
    2.37 @@ -216,7 +220,7 @@
    2.38          }
    2.39      else
    2.40          {
    2.41 -        SendClearCommand();
    2.42 +        SendCommandClear();
    2.43          }
    2.44      }
    2.45  
    2.46 @@ -380,7 +384,7 @@
    2.47  Using this function is advised against as is causes tearing.
    2.48  Use Clear instead.
    2.49  */
    2.50 -void GP1212A02A::SendClearCommand()
    2.51 +void GP1212A02A::SendCommandClear()
    2.52  	{
    2.53      //1BH,4AH,43H,44H
    2.54      //Send Clear Display Command
    2.55 @@ -677,6 +681,7 @@
    2.56  void GP1212A02A::TurnPowerOn()
    2.57  	{
    2.58  	SendCommandPower(EPowerOn);
    2.59 +	SetClockSetting();
    2.60  	}
    2.61  
    2.62  /**
    2.63 @@ -685,3 +690,205 @@
    2.64  	{
    2.65  	SendCommandPower(EPowerOff);
    2.66  	}
    2.67 +
    2.68 +
    2.69 +/**
    2.70 +Number of characters for the given clock format.
    2.71 +@return 
    2.72 +*/
    2.73 +int GP1212A02A::ClockCharCount(TClockFormat aFormat)
    2.74 +	{
    2.75 +	switch (aFormat)
    2.76 +		{
    2.77 +	case EClockDay12:
    2.78 +	case EClockDay24:
    2.79 +		return 10;
    2.80 +	case EClock12:
    2.81 +	case EClock24:
    2.82 +		return 5;
    2.83 +		}
    2.84 +
    2.85 +	return 10;
    2.86 +	}
    2.87 +
    2.88 +/**
    2.89 +@return 
    2.90 +*/
    2.91 +int GP1212A02A::ClockCharWidthInPixels(TClockSize aSize)
    2.92 +	{
    2.93 +	switch (aSize)
    2.94 +		{
    2.95 +	case EClockTiny:
    2.96 +		return 6;
    2.97 +	case EClockSmall:
    2.98 +		return 8;
    2.99 +	case EClockMedium:
   2.100 +		return 12;
   2.101 +	case EClockLarge:
   2.102 +		return 16;
   2.103 +		}
   2.104 +
   2.105 +	return 16;
   2.106 +	}
   2.107 +
   2.108 +/**
   2.109 +@return 
   2.110 +*/
   2.111 +int GP1212A02A::ClockCharHeightInPixels(TClockSize aSize)
   2.112 +	{
   2.113 +	switch (aSize)
   2.114 +		{
   2.115 +	case EClockTiny:
   2.116 +		return 8;
   2.117 +	case EClockSmall:
   2.118 +		return 16;
   2.119 +	case EClockMedium:
   2.120 +		return 24;
   2.121 +	case EClockLarge:
   2.122 +		return 32;
   2.123 +		}
   2.124 +
   2.125 +	return 32;
   2.126 +	}
   2.127 +
   2.128 +/**
   2.129 +Return the Display Window address for centering the clock corresponding to the given parameters.
   2.130 +*/
   2.131 +unsigned short GP1212A02A::ClockCenterAddress(TClockFormat aFormat, TClockSize aSize)
   2.132 +	{
   2.133 +		int charCount=ClockCharCount(aFormat);
   2.134 +		int halfWidth=(ClockCharWidthInPixels(aSize)*charCount)/2;
   2.135 +		int halfHeight=(ClockCharHeightInPixels(aSize))/2;
   2.136 +		int x=(WidthInPixels()/2)-halfWidth;
   2.137 +		int y=(HeightInPixels()/2)-halfHeight;
   2.138 +
   2.139 +		int yOffset=y/8;
   2.140 +		int xOffset=x*8; //Not sure why...
   2.141 +
   2.142 +		unsigned short address = yOffset+xOffset;
   2.143 +		//
   2.144 +		return address;
   2.145 +	}
   2.146 +
   2.147 +/**
   2.148 +*/
   2.149 +void GP1212A02A::ShowClock()
   2.150 +	{
   2.151 +	SendCommandClockDisplay(EClockDay24,ClockCenterAddress(EClockDay24,EClockLarge),EClockLarge);
   2.152 +	}
   2.153 +
   2.154 +/**
   2.155 +*/
   2.156 +void GP1212A02A::HideClock()
   2.157 +	{
   2.158 +	SendCommandClockCancel();
   2.159 +	}
   2.160 +
   2.161 +
   2.162 +/**
   2.163 +Clock setting 
   2.164 +[Code]1BH,6BH,53H,Pd,Ph,Pm 
   2.165 +[Function]Setting the clock data. The setting data is cleared, if the Reset command is input or power 
   2.166 +is turned off. 
   2.167 +Pd = Day of the week 
   2.168 +Ph = hour 
   2.169 +Pm = minute 
   2.170 +[Definable area]
   2.171 +Pd = 00H : Sunday 
   2.172 +Pd = 01H : Monday 
   2.173 +...
   2.174 +Pd = 06H : Saturday 
   2.175 +* Clock setting is canceled, when Pd is input value that is larger than 07H, or Ph is input value that is 
   2.176 +larger than 18H,or Pm is input value that is larger than 3CH. 
   2.177 +*/
   2.178 +void GP1212A02A::SendCommandClockSetting(TWeekDay aWeekDay, unsigned char aHour, unsigned char aMinute)
   2.179 +	{
   2.180 +	FutabaVfdReport report;
   2.181 +    report[0]=0x00; //Report ID
   2.182 +    report[1]=0x06; //Report size
   2.183 +    report[2]=0x1B; //Command ID
   2.184 +    report[3]=0x6B; //Command ID
   2.185 +    report[4]=0x53; //Command ID
   2.186 +    report[5]=aWeekDay; //Sunday to Saturday
   2.187 +	report[6]=aHour;
   2.188 +	report[7]=aMinute;
   2.189 +
   2.190 +    Write(report);
   2.191 +	}
   2.192 +
   2.193 +
   2.194 +/**
   2.195 +Set display clock settings according to local system time.
   2.196 +This needs to be redone whenever we open or turn on our display.
   2.197 +*/
   2.198 +void GP1212A02A::SetClockSetting()
   2.199 +	{
   2.200 +	time_t rawtime;
   2.201 +	struct tm * timeinfo;
   2.202 +
   2.203 +	time ( &rawtime );
   2.204 +	timeinfo = localtime ( &rawtime );
   2.205 +	//
   2.206 +	SendCommandClockSetting((TWeekDay)timeinfo->tm_wday,timeinfo->tm_hour,timeinfo->tm_min);
   2.207 +	}
   2.208 +
   2.209 +
   2.210 +/**
   2.211 +Clock display
   2.212 +[Code] 1BH,6BH,55H,Ps,aL,aH,Pf
   2.213 +[Function] Clock is displayed. The display position and the font size can be freely decided. 
   2.214 +Ps = Display type select 
   2.215 +aL,aH = Address 
   2.216 +Pf = Font size select 
   2.217 +[Definable area]
   2.218 +Ps = 00H : 24hour Ex.[12:34] 
   2.219 +Ps = 01H : 24hour + day of the week  Ex.[Wed._12:34] 
   2.220 +Ps = 10H : 12hour Ex.[PM_00:34] 
   2.221 +Ps = 11H : 12hour + day of the week  Ex.[Wed._PM_00:34] 
   2.222 +Pf = 30H : 6x8 dot 
   2.223 +Pf = 31H : 8x16dot
   2.224 +Pf = 32H : 12x24 dot 
   2.225 +Pf = 33H : 16x32 dot 
   2.226 +* When the clock data is not input, clock is not displayed. 
   2.227 +* The clock display is maintained until Clock display cancel "Clear display" RESET command is input 
   2.228 +or power is turned off. 
   2.229 +The clock display area
   2.230 +Graphic can be displayed excluding the clock display area.
   2.231 +The self adjustment for the position 
   2.232 +that cannot be displayed. 
   2.233 +* Excluding the clock display area can be input other display commands.
   2.234 +*/
   2.235 +void GP1212A02A::SendCommandClockDisplay(TClockFormat aClockFormat, unsigned short aAddress, TClockSize aSize)
   2.236 +	{
   2.237 +	FutabaVfdReport report;
   2.238 +    report[0]=0x00; //Report ID
   2.239 +    report[1]=0x07; //Report size
   2.240 +    report[2]=0x1B; //Command ID
   2.241 +    report[3]=0x6B; //Command ID
   2.242 +    report[4]=0x55; //Command ID
   2.243 +    report[5]=aClockFormat; //
   2.244 +	report[6]=(unsigned char)aAddress;	//aL
   2.245 +	report[7]=aAddress>>8;				//aH
   2.246 +	report[8]=aSize;
   2.247 +
   2.248 +    Write(report);
   2.249 +	}
   2.250 +
   2.251 +
   2.252 +/**
   2.253 + Clock display cancel 
   2.254 +[Code] 1BH,6BH,3DH,58H
   2.255 +[Function] Clock display is canceled.
   2.256 +*/
   2.257 +void GP1212A02A::SendCommandClockCancel()
   2.258 +	{
   2.259 +	FutabaVfdReport report;
   2.260 +    report[0]=0x00; //Report ID
   2.261 +    report[1]=0x04; //Report size
   2.262 +    report[2]=0x1B; //Command ID
   2.263 +    report[3]=0x6B; //Command ID
   2.264 +    report[4]=0x3D; //Command ID
   2.265 +    report[5]=0x58; //
   2.266 +
   2.267 +    Write(report);
   2.268 +	}
     3.1 --- a/FutabaGP1212A02.h	Sun Aug 31 18:33:31 2014 +0200
     3.2 +++ b/FutabaGP1212A02.h	Sun Aug 31 21:35:36 2014 +0200
     3.3 @@ -27,7 +27,11 @@
     3.4  	virtual void SwapBuffers();
     3.5  	virtual void TurnPowerOn();
     3.6  	virtual void TurnPowerOff();
     3.7 -	virtual bool SupportPowerOnOff(){return true;} 
     3.8 +	virtual bool SupportPowerOnOff(){return true;}
     3.9 +	virtual void ShowClock();
    3.10 +	virtual void HideClock();
    3.11 +	virtual bool SupportClock(){return true;}
    3.12 +
    3.13  
    3.14  
    3.15  	//From GraphicDisplay
    3.16 @@ -55,6 +59,8 @@
    3.17  	char* DeviceId();
    3.18  	char* FirmwareRevision();
    3.19  
    3.20 +private:
    3.21 +
    3.22  	enum TBmpBoxId
    3.23  	{
    3.24  		EBmpBoxIdNull=0x30,
    3.25 @@ -81,28 +87,70 @@
    3.26  		EPowerOn=0x31
    3.27  	};
    3.28  
    3.29 +	enum TWeekDay
    3.30 +	{
    3.31 +		ESunday		=	0x00,
    3.32 +		EMonday		=	0x01,
    3.33 +		ETuesday	=	0x02,
    3.34 +		EWednesday	=	0x03,
    3.35 +		EThrusday	=	0x04,
    3.36 +		EFriday		=	0x05,
    3.37 +		ESaturday	=	0x06
    3.38 +	};
    3.39 +
    3.40 +	enum TClockFormat
    3.41 +	{
    3.42 +		EClock24	=	0x00,
    3.43 +		EClockDay24	=	0x01,
    3.44 +		EClock12	=	0x10,
    3.45 +		EClockDay12	=	0x11
    3.46 +	};
    3.47 +
    3.48 +	enum TClockSize
    3.49 +	{
    3.50 +		EClockTiny		=	0x30,
    3.51 +		EClockSmall		=	0x31,
    3.52 +		EClockMedium	=	0x32,
    3.53 +		EClockLarge		=	0x33
    3.54 +	};
    3.55 +
    3.56 +
    3.57  private:
    3.58  	//Specific to GP1212A02A
    3.59  	//General setting command
    3.60 +	void SendCommandClear();
    3.61 +	//
    3.62  	void BmpDataInput(TTarget aTarget, unsigned short aAddress, TDirection aDirection, unsigned short aSize, unsigned char* aPixels);
    3.63 +	//
    3.64 +	void SendCommandPower(TPowerStatus aPowerStatus);
    3.65 +	//Clock commands
    3.66 +	void SendCommandClockSetting(TWeekDay aWeekDay, unsigned char aHour, unsigned char aMinute);
    3.67 +	void SendCommandClockDisplay(TClockFormat aClockFormat, unsigned short aAddress, TClockSize aSize);
    3.68 +	void SendCommandClockCancel();
    3.69 +
    3.70  
    3.71  	//BMP box
    3.72  	void BmpBoxSetting(TBmpBoxId aBoxId, unsigned short aAddress, int aWidth, int aHeight);
    3.73  	void BmpBoxSelect(TBmpBoxId aBoxId);
    3.74  	void BmpBoxDataMemoryTransfer(unsigned short aAddress);
    3.75  	void BmpBoxDataInput(unsigned short aSize, unsigned char* aPixels);
    3.76 -	//
    3.77 -	void SendCommandPower(TPowerStatus aPowerStatus);
    3.78 +
    3.79 +	//Clock utilities
    3.80 +	int ClockCharCount(TClockFormat aFormat);
    3.81 +	int ClockCharWidthInPixels(TClockSize aSize);
    3.82 +	int ClockCharHeightInPixels(TClockSize aSize);
    3.83 +	unsigned short ClockCenterAddress(TClockFormat aFormat, TClockSize aSize);
    3.84  
    3.85  private:
    3.86      void RequestDeviceId();
    3.87      void RequestFirmwareRevision();
    3.88      void RequestPowerSupplyStatus();
    3.89 +	//
    3.90 +	void SetClockSetting();
    3.91  
    3.92  
    3.93  private:
    3.94 -	unsigned char OffScreenY() const;
    3.95 -	void SendClearCommand();
    3.96 +	unsigned char OffScreenY() const;	
    3.97  	void OffScreenTranslation(unsigned char& aX, unsigned char& aY);
    3.98  	void ResetBuffers();
    3.99  
     4.1 --- a/MiniDisplay.cpp	Sun Aug 31 18:33:31 2014 +0200
     4.2 +++ b/MiniDisplay.cpp	Sun Aug 31 21:35:36 2014 +0200
     4.3 @@ -220,4 +220,22 @@
     4.4  bool MiniDisplaySupportPowerOnOff(MiniDisplayDevice aDevice)
     4.5      {
     4.6      return ((GraphicDisplay*)aDevice)->SupportPowerOnOff();
     4.7 +    }
     4.8 +
     4.9 +//-------------------------------------------------------------
    4.10 +void MiniDisplayShowClock(MiniDisplayDevice aDevice)
    4.11 +    {
    4.12 +    ((GraphicDisplay*)aDevice)->ShowClock();
    4.13 +    }
    4.14 +
    4.15 +//-------------------------------------------------------------
    4.16 +void MiniDisplayHideClock(MiniDisplayDevice aDevice)
    4.17 +    {
    4.18 +    ((GraphicDisplay*)aDevice)->HideClock();
    4.19 +    }
    4.20 +
    4.21 +//-------------------------------------------------------------
    4.22 +bool MiniDisplaySupportClock(MiniDisplayDevice aDevice)
    4.23 +    {
    4.24 +    return ((GraphicDisplay*)aDevice)->SupportClock();
    4.25      }
    4.26 \ No newline at end of file
     5.1 --- a/MiniDisplay.h	Sun Aug 31 18:33:31 2014 +0200
     5.2 +++ b/MiniDisplay.h	Sun Aug 31 21:35:36 2014 +0200
     5.3 @@ -204,6 +204,25 @@
     5.4  */
     5.5  extern "C" MDAPI bool MiniDisplaySupportPowerOnOff(MiniDisplayDevice aDevice);
     5.6  
     5.7 +/**
     5.8 +Show built-in clock.
     5.9 +@param [IN] The device to apply this command to.
    5.10 +*/
    5.11 +extern "C" MDAPI void MiniDisplayShowClock(MiniDisplayDevice aDevice);
    5.12 +
    5.13 +/**
    5.14 +Hide built-in clock.
    5.15 +@param [IN] The device to apply this command to.
    5.16 +*/
    5.17 +extern "C" MDAPI void MiniDisplayHideClock(MiniDisplayDevice aDevice);
    5.18 +
    5.19 +/**
    5.20 +Specifies whether or not this display supports clock functions.
    5.21 +@param [IN] The device to apply this command to.
    5.22 +@return True if this display supports built-in clock, false otherwise.
    5.23 +*/
    5.24 +extern "C" MDAPI bool MiniDisplaySupportClock(MiniDisplayDevice aDevice);
    5.25 +
    5.26  
    5.27  #endif
    5.28