FutabaMDM166AA.cpp
changeset 28 0d426caeaefe
parent 27 949be5444c57
child 29 9b44c6e1651c
     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