Now having only one generic request API.
authorsl
Mon, 25 Aug 2014 22:05:30 +0200
changeset 112d749a2bea34
parent 10 1c3a4964a5bd
child 12 62356e3ecb84
Now having only one generic request API.
That will help us support different display types.
Display.h
FutabaGP1212A01.cpp
FutabaGP1212A01.h
FutabaGP1212A02.cpp
FutabaGP1212A02.h
MiniDisplay.cpp
MiniDisplay.h
     1.1 --- a/Display.h	Mon Aug 25 00:07:01 2014 +0200
     1.2 +++ b/Display.h	Mon Aug 25 22:05:30 2014 +0200
     1.3 @@ -11,6 +11,7 @@
     1.4  class DisplayBase
     1.5  	{
     1.6  public:
     1.7 +	DisplayBase():iRequest(EMiniDisplayRequestNone){}
     1.8  	virtual ~DisplayBase(){};
     1.9  	//
    1.10  	virtual int Open()=0;
    1.11 @@ -23,6 +24,20 @@
    1.12  	virtual void Fill()=0;
    1.13  	//
    1.14  	virtual void SwapBuffers()=0;
    1.15 +
    1.16 +	//Request management
    1.17 +	virtual void Request(TMiniDisplayRequest /*aRequest*/){ /*No request supported by default*/ };
    1.18 +	virtual TMiniDisplayRequest AttemptRequestCompletion()=0;
    1.19 +	
    1.20 +	virtual TMiniDisplayRequest CurrentRequest(){return iRequest;}
    1.21 +    virtual void CancelRequest(){iRequest=EMiniDisplayRequestNone;}
    1.22 +	virtual bool RequestPending(){return iRequest!=EMiniDisplayRequestNone;}
    1.23 +
    1.24 +protected:
    1.25 +	void SetRequest(TMiniDisplayRequest aRequest) { iRequest=aRequest; }
    1.26 +
    1.27 +private:
    1.28 +	TMiniDisplayRequest iRequest;
    1.29  	};
    1.30  
    1.31  
     2.1 --- a/FutabaGP1212A01.cpp	Mon Aug 25 00:07:01 2014 +0200
     2.2 +++ b/FutabaGP1212A01.cpp	Mon Aug 25 22:05:30 2014 +0200
     2.3 @@ -21,7 +21,7 @@
     2.4      iFrameBeta(NULL),
     2.5      iFrameGamma(NULL),
     2.6      iNeedFullFrameUpdate(0),
     2.7 -    iRequest(EMiniDisplayRequestNone),iPowerOn(false)
     2.8 +    iPowerOn(false)
     2.9  	{
    2.10  	iDeviceId[0]=0;
    2.11  	iFirmwareRevision[0]=0;
    2.12 @@ -475,6 +475,28 @@
    2.13  	//memset(iFrameBeta,0x00,sizeof(iFrameBeta));
    2.14  	}
    2.15  
    2.16 +
    2.17 +/**
    2.18 +*/
    2.19 +void GP1212A01A::Request(TMiniDisplayRequest aRequest)
    2.20 +	{
    2.21 +	switch (aRequest)
    2.22 +		{
    2.23 +	case EMiniDisplayRequestDeviceId:
    2.24 +		RequestDeviceId();
    2.25 +		break;
    2.26 +	case EMiniDisplayRequestFirmwareRevision:
    2.27 +		RequestFirmwareRevision();
    2.28 +		break;
    2.29 +	case EMiniDisplayRequestPowerSupplyStatus:
    2.30 +		RequestPowerSupplyStatus();
    2.31 +		break;
    2.32 +	default:
    2.33 +		//Not supported
    2.34 +		break;
    2.35 +		};
    2.36 +	}
    2.37 +
    2.38  /**
    2.39  */
    2.40  void GP1212A01A::RequestDeviceId()
    2.41 @@ -497,7 +519,7 @@
    2.42      report[6]=0x44; //Command ID
    2.43      if (Write(report)==report.Size())
    2.44          {
    2.45 -        iRequest=EMiniDisplayRequestDeviceId;
    2.46 +        SetRequest(EMiniDisplayRequestDeviceId);
    2.47          }
    2.48      }
    2.49  
    2.50 @@ -523,7 +545,7 @@
    2.51      report[6]=0x52; //Command ID
    2.52      if (Write(report)==report.Size())
    2.53          {
    2.54 -        iRequest=EMiniDisplayRequestFirmwareRevision;
    2.55 +        SetRequest(EMiniDisplayRequestFirmwareRevision);
    2.56          }
    2.57      }
    2.58  
    2.59 @@ -548,7 +570,7 @@
    2.60      report[6]=0x4D; //Command ID
    2.61      if (Write(report)==report.Size())
    2.62          {
    2.63 -        iRequest=EMiniDisplayRequestPowerSupplyStatus;
    2.64 +        SetRequest(EMiniDisplayRequestPowerSupplyStatus);
    2.65          }
    2.66      }
    2.67  
    2.68 @@ -624,9 +646,9 @@
    2.69  			strcpy(iFirmwareRevision,(const char*)ptr);
    2.70  		}
    2.71  
    2.72 -    TMiniDisplayRequest completed=iRequest;
    2.73 +    TMiniDisplayRequest completed=CurrentRequest();
    2.74      //Our request was completed
    2.75 -    iRequest=EMiniDisplayRequestNone;
    2.76 +    SetRequest(EMiniDisplayRequestNone);
    2.77  
    2.78      return completed;
    2.79      }
     3.1 --- a/FutabaGP1212A01.h	Mon Aug 25 00:07:01 2014 +0200
     3.2 +++ b/FutabaGP1212A01.h	Mon Aug 25 22:05:30 2014 +0200
     3.3 @@ -44,9 +44,7 @@
     3.4      //
     3.5  	void SwapBuffers();
     3.6      //
     3.7 -    void RequestDeviceId();
     3.8 -    void RequestFirmwareRevision();
     3.9 -    void RequestPowerSupplyStatus();
    3.10 +	virtual void Request(TMiniDisplayRequest aRequest);
    3.11  	//
    3.12  	void ToggleOffScreenMode();
    3.13      void SetOffScreenMode(bool aOn);
    3.14 @@ -55,9 +53,6 @@
    3.15      void SetFrameDifferencing(bool aOn){iUseFrameDifferencing=aOn;}
    3.16      bool FrameDifferencing() const {return iUseFrameDifferencing;}
    3.17      //
    3.18 -    bool RequestPending(){return iRequest!=EMiniDisplayRequestNone;}
    3.19 -    TMiniDisplayRequest CurrentRequest(){return iRequest;}
    3.20 -    void CancelRequest(){iRequest=EMiniDisplayRequestNone;}
    3.21      TMiniDisplayRequest AttemptRequestCompletion();
    3.22      FutabaVfdReport& InputReport() {return iInputReport;}
    3.23      bool PowerOn();
    3.24 @@ -65,6 +60,12 @@
    3.25  	char* FirmwareRevision();
    3.26  
    3.27  private:
    3.28 +	void RequestDeviceId();
    3.29 +    void RequestFirmwareRevision();
    3.30 +    void RequestPowerSupplyStatus();
    3.31 +
    3.32 +
    3.33 +private:
    3.34  	enum DW
    3.35  		{
    3.36          DW1=0xC0,
    3.37 @@ -102,7 +103,6 @@
    3.38  	//unsigned char iFrameBeta[256*64];
    3.39  	//unsigned char *iFrontBuffer;
    3.40  	//unsigned char *iBackBuffer;
    3.41 -    TMiniDisplayRequest iRequest;
    3.42      FutabaVfdReport iInputReport;
    3.43  	//
    3.44  	char iDeviceId[KFutabaMaxHidReportSize];
     4.1 --- a/FutabaGP1212A02.cpp	Mon Aug 25 00:07:01 2014 +0200
     4.2 +++ b/FutabaGP1212A02.cpp	Mon Aug 25 22:05:30 2014 +0200
     4.3 @@ -22,7 +22,7 @@
     4.4      iFrameBeta(NULL),
     4.5      iFrameGamma(NULL),
     4.6      iNeedFullFrameUpdate(0),
     4.7 -    iRequest(EMiniDisplayRequestNone),iPowerOn(false)
     4.8 +    iPowerOn(false)
     4.9  	{
    4.10  	iDeviceId[0]=0;
    4.11  	iFirmwareRevision[0]=0;
    4.12 @@ -480,77 +480,21 @@
    4.13  */
    4.14  void GP1212A02A::RequestDeviceId()
    4.15      {
    4.16 -    if (RequestPending())
    4.17 -        {
    4.18 -        //Abort silently for now
    4.19 -        return;
    4.20 -        }
    4.21 -
    4.22 -    //1BH,5BH,63H,49H,44H
    4.23 -    //Send Read ID command
    4.24 -    FutabaVfdReport report;
    4.25 -    report[0]=0x00; //Report ID
    4.26 -    report[1]=0x05; //Report length
    4.27 -    report[2]=0x1B; //Command ID
    4.28 -    report[3]=0x5B; //Command ID
    4.29 -    report[4]=0x63; //Command ID
    4.30 -    report[5]=0x49; //Command ID
    4.31 -    report[6]=0x44; //Command ID
    4.32 -    if (Write(report)==report.Size())
    4.33 -        {
    4.34 -        iRequest=EMiniDisplayRequestDeviceId;
    4.35 -        }
    4.36 +	//Not supported
    4.37      }
    4.38  
    4.39  /**
    4.40  */
    4.41  void GP1212A02A::RequestFirmwareRevision()
    4.42      {
    4.43 -    if (RequestPending())
    4.44 -        {
    4.45 -        //Abort silently for now
    4.46 -        return;
    4.47 -        }
    4.48 -
    4.49 -    //1BH,5BH,63H,46H,52H
    4.50 -    //Send Software Revision Read Command
    4.51 -    FutabaVfdReport report;
    4.52 -    report[0]=0x00; //Report ID
    4.53 -    report[1]=0x05; //Report length
    4.54 -    report[2]=0x1B; //Command ID
    4.55 -    report[3]=0x5B; //Command ID
    4.56 -    report[4]=0x63; //Command ID
    4.57 -    report[5]=0x46; //Command ID
    4.58 -    report[6]=0x52; //Command ID
    4.59 -    if (Write(report)==report.Size())
    4.60 -        {
    4.61 -        iRequest=EMiniDisplayRequestFirmwareRevision;
    4.62 -        }
    4.63 +	//Not supported
    4.64      }
    4.65  
    4.66  /**
    4.67  */
    4.68  void GP1212A02A::RequestPowerSupplyStatus()
    4.69      {
    4.70 -    if (RequestPending())
    4.71 -        {
    4.72 -        //Abort silently for now
    4.73 -        return;
    4.74 -        }
    4.75 -    //1BH,5BH,63H,50H,4DH
    4.76 -    //Send Power Suppply Monitor Command
    4.77 -    FutabaVfdReport report;
    4.78 -    report[0]=0x00; //Report ID
    4.79 -    report[1]=0x05; //Report length
    4.80 -    report[2]=0x1B; //Command ID
    4.81 -    report[3]=0x5B; //Command ID
    4.82 -    report[4]=0x63; //Command ID
    4.83 -    report[5]=0x50; //Command ID
    4.84 -    report[6]=0x4D; //Command ID
    4.85 -    if (Write(report)==report.Size())
    4.86 -        {
    4.87 -        iRequest=EMiniDisplayRequestPowerSupplyStatus;
    4.88 -        }
    4.89 +	//Not supported
    4.90      }
    4.91  
    4.92  
    4.93 @@ -590,47 +534,9 @@
    4.94   */
    4.95  TMiniDisplayRequest GP1212A02A::AttemptRequestCompletion()
    4.96      {
    4.97 -    if (!RequestPending())
    4.98 -        {
    4.99 -        return EMiniDisplayRequestNone;
   4.100 -        }
   4.101 -
   4.102 -    int res=Read(iInputReport);
   4.103 -
   4.104 -    if (!res)
   4.105 -        {
   4.106 -        return EMiniDisplayRequestNone;
   4.107 -        }
   4.108 -
   4.109 -    //Process our request
   4.110 -    if (CurrentRequest()==EMiniDisplayRequestPowerSupplyStatus)
   4.111 -        {
   4.112 -        if (iInputReport[1]==0x4F && iInputReport[2]==0x4E)
   4.113 -            {
   4.114 -            iPowerOn = true;
   4.115 -            }
   4.116 -        else if (iInputReport[1]==0x4F && iInputReport[2]==0x46 && iInputReport[3]==0x46)
   4.117 -            {
   4.118 -            iPowerOn = false;
   4.119 -            }
   4.120 -        }
   4.121 -	else if (CurrentRequest()==EMiniDisplayRequestDeviceId)
   4.122 -		{
   4.123 -			unsigned char* ptr=&iInputReport[1];
   4.124 -			strcpy(iDeviceId,(const char*)ptr);
   4.125 -		}
   4.126 -	else if (CurrentRequest()==EMiniDisplayRequestFirmwareRevision)
   4.127 -		{
   4.128 -			unsigned char* ptr=&iInputReport[1];
   4.129 -			strcpy(iFirmwareRevision,(const char*)ptr);
   4.130 -		}
   4.131 -
   4.132 -    TMiniDisplayRequest completed=iRequest;
   4.133 -    //Our request was completed
   4.134 -    iRequest=EMiniDisplayRequestNone;
   4.135 -
   4.136 -    return completed;
   4.137 -    }
   4.138 +	//That display does not support any requests
   4.139 +	return EMiniDisplayRequestNone;
   4.140 +	}
   4.141  
   4.142  
   4.143  /**
     5.1 --- a/FutabaGP1212A02.h	Mon Aug 25 00:07:01 2014 +0200
     5.2 +++ b/FutabaGP1212A02.h	Mon Aug 25 22:05:30 2014 +0200
     5.3 @@ -54,10 +54,7 @@
     5.4      //
     5.5      void SetFrameDifferencing(bool aOn){iUseFrameDifferencing=aOn;}
     5.6      bool FrameDifferencing() const {return iUseFrameDifferencing;}
     5.7 -    //
     5.8 -    bool RequestPending(){return iRequest!=EMiniDisplayRequestNone;}
     5.9 -    TMiniDisplayRequest CurrentRequest(){return iRequest;}
    5.10 -    void CancelRequest(){iRequest=EMiniDisplayRequestNone;}
    5.11 +    //    
    5.12      TMiniDisplayRequest AttemptRequestCompletion();
    5.13      FutabaVfdReport& InputReport() {return iInputReport;}
    5.14      bool PowerOn();
    5.15 @@ -102,7 +99,6 @@
    5.16  	//unsigned char iFrameBeta[256*64];
    5.17  	//unsigned char *iFrontBuffer;
    5.18  	//unsigned char *iBackBuffer;
    5.19 -    TMiniDisplayRequest iRequest;
    5.20      FutabaVfdReport iInputReport;
    5.21  	//
    5.22  	char iDeviceId[KFutabaMaxHidReportSize];
     6.1 --- a/MiniDisplay.cpp	Mon Aug 25 00:07:01 2014 +0200
     6.2 +++ b/MiniDisplay.cpp	Mon Aug 25 22:05:30 2014 +0200
     6.3 @@ -157,21 +157,9 @@
     6.4      }
     6.5  
     6.6  //-------------------------------------------------------------
     6.7 -void MiniDisplayRequestDeviceId(MiniDisplayDevice aDevice)
     6.8 +void MiniDisplayRequest(MiniDisplayDevice aDevice, TMiniDisplayRequest aRequest)
     6.9      {
    6.10 -    ((GP1212A01A*)aDevice)->RequestDeviceId();
    6.11 -    }
    6.12 -
    6.13 -//-------------------------------------------------------------
    6.14 -void MiniDisplayRequestPowerSupplyStatus(MiniDisplayDevice aDevice)
    6.15 -    {
    6.16 -    ((GP1212A01A*)aDevice)->RequestPowerSupplyStatus();
    6.17 -    }
    6.18 -
    6.19 -//-------------------------------------------------------------
    6.20 -void MiniDisplayRequestFirmwareRevision(MiniDisplayDevice aDevice)
    6.21 -    {
    6.22 -    ((GP1212A01A*)aDevice)->RequestFirmwareRevision();
    6.23 +    ((GraphicDisplay*)aDevice)->Request(aRequest);
    6.24      }
    6.25  
    6.26  //-------------------------------------------------------------
     7.1 --- a/MiniDisplay.h	Mon Aug 25 00:07:01 2014 +0200
     7.2 +++ b/MiniDisplay.h	Mon Aug 25 22:05:30 2014 +0200
     7.3 @@ -135,19 +135,7 @@
     7.4  Request device ID.
     7.5  @param [IN] The device to apply this command to.
     7.6  */
     7.7 -extern "C" MDAPI void MiniDisplayRequestDeviceId(MiniDisplayDevice aDevice);
     7.8 -
     7.9 -/**
    7.10 -Request power status.
    7.11 -@param [IN] The device to apply this command to.
    7.12 -*/
    7.13 -extern "C" MDAPI void MiniDisplayRequestPowerSupplyStatus(MiniDisplayDevice aDevice);
    7.14 -
    7.15 -/**
    7.16 -Request firmware version.
    7.17 -@param [IN] The device to apply this command to.
    7.18 -*/
    7.19 -extern "C" MDAPI void MiniDisplayRequestFirmwareRevision(MiniDisplayDevice aDevice);
    7.20 +extern "C" MDAPI void MiniDisplayRequest(MiniDisplayDevice aDevice, TMiniDisplayRequest aRequest);
    7.21  
    7.22  /**
    7.23  Tell whether or not a request is pending.