# HG changeset patch # User StephaneLenclud # Date 1423141347 -3600 # Node ID 0d426caeaefe2f368b3f9ef20e1cbea972e9e82a # Parent 949be5444c57d6c18245e2f6818d6f115102cdb8 MDM166AA: more accurate time setting and cleanup. diff -r 949be5444c57 -r 0d426caeaefe FutabaMDM166AA.cpp --- a/FutabaMDM166AA.cpp Thu Feb 05 11:41:19 2015 +0100 +++ b/FutabaMDM166AA.cpp Thu Feb 05 14:02:27 2015 +0100 @@ -20,17 +20,13 @@ // MDM166AA::MDM166AA(): - iDisplayPositionX(0),iDisplayPositionY(0), iOffScreenMode(true), - iUseFrameDifferencing(true), iFrameNext(NULL), iFrameCurrent(NULL), iFramePrevious(NULL), iFrameAlpha(NULL), iFrameBeta(NULL), - iFrameGamma(NULL), - iNeedFullFrameUpdate(0), - iPowerOn(false) + iFrameGamma(NULL) { iDeviceId[0]=0; iFirmwareRevision[0]=0; @@ -53,8 +49,6 @@ iFrameNext=NULL; iFrameCurrent=NULL; iFramePrevious=NULL; - // - iNeedFullFrameUpdate=0; } /** @@ -80,16 +74,12 @@ iFrameNext=iFrameAlpha; iFrameCurrent=iFrameBeta; iFramePrevious=iFrameGamma; - - - //To make sure it is synced properly - iNeedFullFrameUpdate=0; // SetNonBlocking(1); // - SendCommandClear(); + SendCommandReset(); // - SetClockSetting(); + ShowClock(); } return success; @@ -148,8 +138,7 @@ void MDM166AA::Clear() { //That one also clear the symbols - SendCommandClear(); - //TODO: Consider just clearing the pixels instead + SetAllPixels(0x00); } /** @@ -207,16 +196,6 @@ Write(report); } - -/** -Provide Y coordinate of our off screen buffer. -*/ -unsigned char MDM166AA::OffScreenY() const - { - //Overflowing is fine this is just what we want - return iDisplayPositionY+HeightInPixels(); - } - /** Put our off screen buffer on screen. On screen buffer goes off screen. @@ -226,7 +205,9 @@ //Only perform buffer swapping if off screen mode is enabled if (OffScreenMode()) { - //Send pixel directly into BMP box + //Send next frame to our display RAM + //We could attempt to implement a frame differencing algorithm much like we did for GP1212A01. + //However we see little point doing that since we already run at above 20 FPS. SendCommandWriteGraphicData(FrameBufferSizeInBytes(),iFrameNext->Ptr()); //Cycle through our frame buffers @@ -254,19 +235,6 @@ /** -Translate the given pixel coordinate according to our off screen mode. -*/ -void MDM166AA::OffScreenTranslation(unsigned char& aX, unsigned char& aY) - { - if (OffScreenMode()) - { - aX+=WidthInPixels()-iDisplayPositionX; - aY+=HeightInPixels()-iDisplayPositionY; - } - } - - -/** */ void MDM166AA::Request(TMiniDisplayRequest aRequest) { @@ -305,32 +273,10 @@ } /** -ID code -[Code] 1BH,6AH,49H,44H -[Function] Send the ID code to the Host system. ID code is software version. */ void MDM166AA::RequestFirmwareRevision() { - if (RequestPending()) - { - //Abort silently for now - return; - } - - //1BH,6AH,49H,44H - //Send Software Revision Read Command - FutabaVfdReport report; - report[0]=0x00; //Report ID - report[1]=0x04; //Report length - report[2]=0x1B; //Command ID - report[3]=0x6A; //Command ID - report[4]=0x49; //Command ID - report[5]=0x44; //Command ID - if (Write(report)==report.Size()) - { - SetRequest(EMiniDisplayRequestFirmwareRevision); - } - + //Not supported } /** @@ -376,31 +322,7 @@ */ TMiniDisplayRequest MDM166AA::AttemptRequestCompletion() { - if (!RequestPending()) - { - return EMiniDisplayRequestNone; - } - - int res=Read(iInputReport); - - if (!res) - { - return EMiniDisplayRequestNone; - } - - //Process our request - if (CurrentRequest()==EMiniDisplayRequestFirmwareRevision) - { - unsigned char* ptr=&iInputReport[2]; - iInputReport[7]=0x00; - strcpy(iFirmwareRevision,(const char*)ptr); - } - - TMiniDisplayRequest completed=CurrentRequest(); - //Our request was completed - SetRequest(EMiniDisplayRequestNone); - - return completed; + return EMiniDisplayRequestNone; } @@ -426,33 +348,13 @@ Write(report); } -/** -*/ -bool MDM166AA::IsPowerOn() - { - return iPowerOn; - } - -/** -*/ -char* MDM166AA::DeviceId() - { - return iDeviceId; - } - -/** -*/ -char* MDM166AA::FirmwareRevision() - { - return iFirmwareRevision; - } /** */ void MDM166AA::ShowClock() { + SetClockData(); SendCommandClockDisplay(EClockLarge,EClock24); - SetClockSetting(); } /** @@ -471,7 +373,7 @@ Ph = hour Pm = minute */ -void MDM166AA::SendCommandClockSetting(unsigned char aHour, unsigned char aMinute) +void MDM166AA::SendCommandSetClockData(unsigned char aHour, unsigned char aMinute) { FutabaVfdReport report; report[0]=0x00; //Report ID @@ -490,18 +392,36 @@ /** -Set display clock settings according to local system time. +Set display clock data according to local system time. This needs to be redone whenever we open or turn on our display. */ -void MDM166AA::SetClockSetting() +void MDM166AA::SetClockData() { time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); - // - SendCommandClockSetting(timeinfo->tm_hour,timeinfo->tm_min); + //Adjust minute as best as we can so that we have a 30 seconds offset at most rather a than a full minute. + if (timeinfo->tm_sec>30) + { + //Use the next minute then + timeinfo->tm_min++; + if (timeinfo->tm_min==60) + { + //Use the next hour then + timeinfo->tm_hour++; + timeinfo->tm_min=0; + if (timeinfo->tm_hour==24) + { + //Move to the next day then + timeinfo->tm_hour=0; + } + } + } + + //Send hours and minutes to our display + SendCommandSetClockData(timeinfo->tm_hour,timeinfo->tm_min); } diff -r 949be5444c57 -r 0d426caeaefe FutabaMDM166AA.h --- a/FutabaMDM166AA.h Thu Feb 05 11:41:19 2015 +0100 +++ b/FutabaMDM166AA.h Thu Feb 05 14:02:27 2015 +0100 @@ -21,7 +21,6 @@ class MDM166AA : public FutabaGraphicDisplay { public: - MDM166AA(); ~MDM166AA(); @@ -52,29 +51,23 @@ void ToggleOffScreenMode(); void SetOffScreenMode(bool aOn); bool OffScreenMode() const {return iOffScreenMode;} - // - void SetFrameDifferencing(bool aOn){iUseFrameDifferencing=aOn;} - bool FrameDifferencing() const {return iUseFrameDifferencing;} // TMiniDisplayRequest AttemptRequestCompletion(); - FutabaVfdReport& InputReport() {return iInputReport;} - bool IsPowerOn(); - char* DeviceId(); - char* FirmwareRevision(); + private: enum TClockFormat - { + { EClock12 = 0x00, EClock24 = 0x01, - }; + }; enum TClockSize - { + { EClockSmall = 0x01, EClockLarge = 0x02 - }; + }; private: @@ -84,56 +77,35 @@ void SendCommandReset(); // //Clock commands - void SendCommandClockSetting(unsigned char aHour, unsigned char aMinute); + void SendCommandSetClockData(unsigned char aHour, unsigned char aMinute); void SendCommandClockDisplay(TClockSize aClockSize, TClockFormat aClockFormat); //Graphics commands void SendCommandSetAddressCounter(unsigned char aAddressCounter); void SendCommandWriteGraphicData(int aSize, unsigned char* aPixels); - private: void RequestDeviceId(); void RequestFirmwareRevision(); void RequestPowerSupplyStatus(); // - void SetClockSetting(); - + void SetClockData(); private: - unsigned char OffScreenY() const; - void OffScreenTranslation(unsigned char& aX, unsigned char& aY); void ResetBuffers(); private: - unsigned char iDisplayPositionX; - unsigned char iDisplayPositionY; ///Off screen mode is the recommended default settings to avoid tearing. ///Though turning it off can be useful for debugging bool iOffScreenMode; - ///Frame differences algo is used to reduce USB bus traffic and improve frame rate in typical use case - bool iUseFrameDifferencing; - /// - //FutabaVfdReport iReport; - /// - //unsigned char iFrameBuffer[256*64]; - BitArrayLow* iFrameNext; + // + BitArrayLow* iFrameNext; BitArrayLow* iFrameCurrent; BitArrayLow* iFramePrevious; // - BitArrayLow* iFrameAlpha; - BitArrayLow* iFrameBeta; - BitArrayLow* iFrameGamma; - // - int iNeedFullFrameUpdate; - //unsigned char iFrameBeta[256*64]; - //unsigned char *iFrontBuffer; - //unsigned char *iBackBuffer; - FutabaVfdReport iInputReport; - // - char iDeviceId[KFutabaMaxHidReportSize]; - char iFirmwareRevision[KFutabaMaxHidReportSize]; - bool iPowerOn; + BitArrayLow* iFrameAlpha; //owned + BitArrayLow* iFrameBeta; //owned + BitArrayLow* iFrameGamma; //owned };