MDM166AA: more accurate time setting and cleanup.
authorStephaneLenclud
Thu, 05 Feb 2015 14:02:27 +0100
changeset 280d426caeaefe
parent 27 949be5444c57
child 29 9b44c6e1651c
MDM166AA: more accurate time setting and cleanup.
FutabaMDM166AA.cpp
FutabaMDM166AA.h
     1.1 --- a/FutabaMDM166AA.cpp	Thu Feb 05 11:41:19 2015 +0100
     1.2 +++ b/FutabaMDM166AA.cpp	Thu Feb 05 14:02:27 2015 +0100
     1.3 @@ -20,17 +20,13 @@
     1.4  //
     1.5  
     1.6  MDM166AA::MDM166AA():
     1.7 -	iDisplayPositionX(0),iDisplayPositionY(0),
     1.8      iOffScreenMode(true),
     1.9 -    iUseFrameDifferencing(true),
    1.10      iFrameNext(NULL),
    1.11      iFrameCurrent(NULL),
    1.12      iFramePrevious(NULL),
    1.13      iFrameAlpha(NULL),
    1.14      iFrameBeta(NULL),
    1.15 -    iFrameGamma(NULL),
    1.16 -    iNeedFullFrameUpdate(0),
    1.17 -    iPowerOn(false)
    1.18 +    iFrameGamma(NULL)
    1.19  	{
    1.20  	iDeviceId[0]=0;
    1.21  	iFirmwareRevision[0]=0;
    1.22 @@ -53,8 +49,6 @@
    1.23      iFrameNext=NULL;
    1.24      iFrameCurrent=NULL;
    1.25      iFramePrevious=NULL;
    1.26 -    //
    1.27 -    iNeedFullFrameUpdate=0;
    1.28  	}
    1.29  
    1.30  /**
    1.31 @@ -80,16 +74,12 @@
    1.32          iFrameNext=iFrameAlpha;
    1.33          iFrameCurrent=iFrameBeta;
    1.34          iFramePrevious=iFrameGamma;
    1.35 -
    1.36 -
    1.37 -        //To make sure it is synced properly
    1.38 -        iNeedFullFrameUpdate=0;
    1.39          //
    1.40  		SetNonBlocking(1);
    1.41  		//
    1.42 -		SendCommandClear();
    1.43 +		SendCommandReset();
    1.44  		//
    1.45 -		SetClockSetting();
    1.46 +		ShowClock();
    1.47  
    1.48  		}
    1.49  	return success;
    1.50 @@ -148,8 +138,7 @@
    1.51  void MDM166AA::Clear()
    1.52      {
    1.53  	//That one also clear the symbols
    1.54 -    SendCommandClear();
    1.55 -	//TODO: Consider just clearing the pixels instead
    1.56 +    SetAllPixels(0x00);
    1.57      }
    1.58  
    1.59  /**
    1.60 @@ -207,16 +196,6 @@
    1.61  	Write(report);
    1.62  	}
    1.63  
    1.64 -
    1.65 -/**
    1.66 -Provide Y coordinate of our off screen buffer.
    1.67 -*/
    1.68 -unsigned char MDM166AA::OffScreenY() const
    1.69 -	{
    1.70 -	//Overflowing is fine this is just what we want
    1.71 -	return iDisplayPositionY+HeightInPixels();
    1.72 -	}
    1.73 -
    1.74  /**
    1.75  Put our off screen buffer on screen.
    1.76  On screen buffer goes off screen.
    1.77 @@ -226,7 +205,9 @@
    1.78  	//Only perform buffer swapping if off screen mode is enabled
    1.79  	if (OffScreenMode())
    1.80  		{
    1.81 -		//Send pixel directly into BMP box
    1.82 +		//Send next frame to our display RAM
    1.83 +		//We could attempt to implement a frame differencing algorithm much like we did for GP1212A01.
    1.84 +		//However we see little point doing that since we already run at above 20 FPS.
    1.85  		SendCommandWriteGraphicData(FrameBufferSizeInBytes(),iFrameNext->Ptr());
    1.86  
    1.87          //Cycle through our frame buffers
    1.88 @@ -254,19 +235,6 @@
    1.89  
    1.90  
    1.91  /**
    1.92 -Translate the given pixel coordinate according to our off screen mode.
    1.93 -*/
    1.94 -void MDM166AA::OffScreenTranslation(unsigned char& aX, unsigned char& aY)
    1.95 -	{
    1.96 -	if (OffScreenMode())
    1.97 -		{
    1.98 -		aX+=WidthInPixels()-iDisplayPositionX;
    1.99 -		aY+=HeightInPixels()-iDisplayPositionY;
   1.100 -		}
   1.101 -	}
   1.102 -
   1.103 -
   1.104 -/**
   1.105  */
   1.106  void MDM166AA::Request(TMiniDisplayRequest aRequest)
   1.107  	{
   1.108 @@ -305,32 +273,10 @@
   1.109      }
   1.110  
   1.111  /**
   1.112 -ID code 
   1.113 -[Code] 1BH,6AH,49H,44H
   1.114 -[Function] Send the ID code to the Host system. ID code is software version.
   1.115  */
   1.116  void MDM166AA::RequestFirmwareRevision()
   1.117      {
   1.118 -    if (RequestPending())
   1.119 -        {
   1.120 -        //Abort silently for now
   1.121 -        return;
   1.122 -        }
   1.123 -
   1.124 -    //1BH,6AH,49H,44H
   1.125 -    //Send Software Revision Read Command
   1.126 -    FutabaVfdReport report;
   1.127 -    report[0]=0x00; //Report ID
   1.128 -    report[1]=0x04; //Report length
   1.129 -    report[2]=0x1B; //Command ID
   1.130 -    report[3]=0x6A; //Command ID
   1.131 -    report[4]=0x49; //Command ID
   1.132 -    report[5]=0x44; //Command ID
   1.133 -    if (Write(report)==report.Size())
   1.134 -        {
   1.135 -        SetRequest(EMiniDisplayRequestFirmwareRevision);
   1.136 -        }
   1.137 -
   1.138 +	//Not supported
   1.139      }
   1.140  
   1.141  /**
   1.142 @@ -376,31 +322,7 @@
   1.143   */
   1.144  TMiniDisplayRequest MDM166AA::AttemptRequestCompletion()
   1.145      {
   1.146 -    if (!RequestPending())
   1.147 -        {
   1.148 -        return EMiniDisplayRequestNone;
   1.149 -        }
   1.150 -
   1.151 -    int res=Read(iInputReport);
   1.152 -
   1.153 -    if (!res)
   1.154 -        {
   1.155 -        return EMiniDisplayRequestNone;
   1.156 -        }
   1.157 -
   1.158 -    //Process our request
   1.159 -	if (CurrentRequest()==EMiniDisplayRequestFirmwareRevision)
   1.160 -		{
   1.161 -			unsigned char* ptr=&iInputReport[2];
   1.162 -			iInputReport[7]=0x00;
   1.163 -			strcpy(iFirmwareRevision,(const char*)ptr);
   1.164 -		}
   1.165 -
   1.166 -    TMiniDisplayRequest completed=CurrentRequest();
   1.167 -    //Our request was completed
   1.168 -    SetRequest(EMiniDisplayRequestNone);
   1.169 -
   1.170 -    return completed;
   1.171 +	return EMiniDisplayRequestNone;
   1.172  	}
   1.173  
   1.174  
   1.175 @@ -426,33 +348,13 @@
   1.176      Write(report);
   1.177      }
   1.178  
   1.179 -/**
   1.180 -*/
   1.181 -bool MDM166AA::IsPowerOn()
   1.182 -	{
   1.183 -	return iPowerOn;
   1.184 -	}
   1.185 -
   1.186 -/**
   1.187 -*/
   1.188 -char* MDM166AA::DeviceId()
   1.189 -	{
   1.190 -	return iDeviceId;
   1.191 -	}
   1.192 -
   1.193 -/**
   1.194 -*/
   1.195 -char* MDM166AA::FirmwareRevision()
   1.196 -	{
   1.197 -	return iFirmwareRevision;
   1.198 -	}
   1.199  
   1.200  /**
   1.201  */
   1.202  void MDM166AA::ShowClock()
   1.203  	{
   1.204 +	SetClockData();
   1.205  	SendCommandClockDisplay(EClockLarge,EClock24);
   1.206 -	SetClockSetting();
   1.207  	}
   1.208  
   1.209  /**
   1.210 @@ -471,7 +373,7 @@
   1.211  Ph = hour 
   1.212  Pm = minute 
   1.213  */
   1.214 -void MDM166AA::SendCommandClockSetting(unsigned char aHour, unsigned char aMinute)
   1.215 +void MDM166AA::SendCommandSetClockData(unsigned char aHour, unsigned char aMinute)
   1.216  	{
   1.217  	FutabaVfdReport report;
   1.218      report[0]=0x00; //Report ID
   1.219 @@ -490,18 +392,36 @@
   1.220  
   1.221  
   1.222  /**
   1.223 -Set display clock settings according to local system time.
   1.224 +Set display clock data according to local system time.
   1.225  This needs to be redone whenever we open or turn on our display.
   1.226  */
   1.227 -void MDM166AA::SetClockSetting()
   1.228 +void MDM166AA::SetClockData()
   1.229  	{
   1.230  	time_t rawtime;
   1.231  	struct tm * timeinfo;
   1.232  
   1.233  	time ( &rawtime );
   1.234  	timeinfo = localtime ( &rawtime );
   1.235 -	//
   1.236 -	SendCommandClockSetting(timeinfo->tm_hour,timeinfo->tm_min);
   1.237 +	//Adjust minute as best as we can so that we have a 30 seconds offset at most rather a than a full minute.
   1.238 +	if (timeinfo->tm_sec>30)
   1.239 +		{
   1.240 +		//Use the next minute then
   1.241 +		timeinfo->tm_min++;
   1.242 +		if (timeinfo->tm_min==60)
   1.243 +			{
   1.244 +			//Use the next hour then
   1.245 +			timeinfo->tm_hour++;
   1.246 +			timeinfo->tm_min=0;
   1.247 +			if (timeinfo->tm_hour==24)
   1.248 +				{
   1.249 +				//Move to the next day then
   1.250 +				timeinfo->tm_hour=0;
   1.251 +				}
   1.252 +			}
   1.253 +		}
   1.254 +
   1.255 +	//Send hours and minutes to our display
   1.256 +	SendCommandSetClockData(timeinfo->tm_hour,timeinfo->tm_min);
   1.257  	}
   1.258  
   1.259  
     2.1 --- a/FutabaMDM166AA.h	Thu Feb 05 11:41:19 2015 +0100
     2.2 +++ b/FutabaMDM166AA.h	Thu Feb 05 14:02:27 2015 +0100
     2.3 @@ -21,7 +21,6 @@
     2.4  class MDM166AA : public FutabaGraphicDisplay
     2.5  	{
     2.6  public:
     2.7 -
     2.8      MDM166AA();
     2.9      ~MDM166AA();
    2.10  
    2.11 @@ -52,29 +51,23 @@
    2.12  	void ToggleOffScreenMode();
    2.13      void SetOffScreenMode(bool aOn);
    2.14      bool OffScreenMode() const {return iOffScreenMode;}
    2.15 -    //
    2.16 -    void SetFrameDifferencing(bool aOn){iUseFrameDifferencing=aOn;}
    2.17 -    bool FrameDifferencing() const {return iUseFrameDifferencing;}
    2.18      //    
    2.19      TMiniDisplayRequest AttemptRequestCompletion();
    2.20 -    FutabaVfdReport& InputReport() {return iInputReport;}
    2.21 -    bool IsPowerOn();
    2.22 -	char* DeviceId();
    2.23 -	char* FirmwareRevision();
    2.24 +
    2.25  
    2.26  private:
    2.27  
    2.28  	enum TClockFormat
    2.29 -	{
    2.30 +		{
    2.31  		EClock12	=	0x00,
    2.32  		EClock24	=	0x01,
    2.33 -	};
    2.34 +		};
    2.35  
    2.36  	enum TClockSize
    2.37 -	{
    2.38 +		{
    2.39  		EClockSmall		=	0x01,
    2.40  		EClockLarge		=	0x02
    2.41 -	};
    2.42 +		};
    2.43  	
    2.44  
    2.45  private:
    2.46 @@ -84,56 +77,35 @@
    2.47  	void SendCommandReset();
    2.48  	//
    2.49  	//Clock commands
    2.50 -	void SendCommandClockSetting(unsigned char aHour, unsigned char aMinute);
    2.51 +	void SendCommandSetClockData(unsigned char aHour, unsigned char aMinute);
    2.52  	void SendCommandClockDisplay(TClockSize aClockSize, TClockFormat aClockFormat);	
    2.53  
    2.54  	//Graphics commands
    2.55  	void SendCommandSetAddressCounter(unsigned char aAddressCounter);
    2.56  	void SendCommandWriteGraphicData(int aSize, unsigned char* aPixels);
    2.57  
    2.58 -
    2.59  private:
    2.60      void RequestDeviceId();
    2.61      void RequestFirmwareRevision();
    2.62      void RequestPowerSupplyStatus();
    2.63  	//
    2.64 -	void SetClockSetting();
    2.65 -
    2.66 +	void SetClockData();
    2.67  
    2.68  private:
    2.69 -	unsigned char OffScreenY() const;	
    2.70 -	void OffScreenTranslation(unsigned char& aX, unsigned char& aY);
    2.71  	void ResetBuffers();
    2.72  
    2.73  private:
    2.74 -	unsigned char iDisplayPositionX;
    2.75 -	unsigned char iDisplayPositionY;
    2.76  	///Off screen mode is the recommended default settings to avoid tearing.
    2.77  	///Though turning it off can be useful for debugging
    2.78  	bool iOffScreenMode;
    2.79 -    ///Frame differences algo is used to reduce USB bus traffic and improve frame rate in typical use case
    2.80 -    bool iUseFrameDifferencing;
    2.81 -	///
    2.82 -	//FutabaVfdReport iReport;
    2.83 -	///
    2.84 -	//unsigned char iFrameBuffer[256*64];
    2.85 -    BitArrayLow* iFrameNext;
    2.86 +    //
    2.87 +	BitArrayLow* iFrameNext;
    2.88      BitArrayLow* iFrameCurrent;
    2.89      BitArrayLow* iFramePrevious;
    2.90      //
    2.91 -    BitArrayLow* iFrameAlpha;
    2.92 -    BitArrayLow* iFrameBeta;
    2.93 -    BitArrayLow* iFrameGamma;
    2.94 -    //
    2.95 -    int iNeedFullFrameUpdate;
    2.96 -	//unsigned char iFrameBeta[256*64];
    2.97 -	//unsigned char *iFrontBuffer;
    2.98 -	//unsigned char *iBackBuffer;
    2.99 -    FutabaVfdReport iInputReport;
   2.100 -	//
   2.101 -	char iDeviceId[KFutabaMaxHidReportSize];
   2.102 -	char iFirmwareRevision[KFutabaMaxHidReportSize];
   2.103 -    bool iPowerOn;
   2.104 +    BitArrayLow* iFrameAlpha; //owned
   2.105 +    BitArrayLow* iFrameBeta;  //owned
   2.106 +    BitArrayLow* iFrameGamma; //owned
   2.107  	};
   2.108  
   2.109