Now supporting read request for device ID, firmware version and power status.
authorsl
Wed, 28 May 2014 15:23:41 +0200
changeset 952372bbbc0f8
parent 8 9543e1703afb
child 10 64cfde8062c7
Now supporting read request for device ID, firmware version and power status.
DisplayStatusBar.qml
MiniDisplay/FutabaVfd.cpp
MiniDisplay/FutabaVfd.h
MiniDisplay/minidisplay.cpp
MiniDisplay/minidisplay.h
     1.1 --- a/DisplayStatusBar.qml	Wed May 28 11:42:49 2014 +0200
     1.2 +++ b/DisplayStatusBar.qml	Wed May 28 15:23:41 2014 +0200
     1.3 @@ -7,11 +7,54 @@
     1.4  StatusBar {
     1.5  
     1.6      Component.onCompleted: {
     1.7 -        display.closed.connect(updateDisplayStatus);
     1.8 -        display.opened.connect(updateDisplayStatus);
     1.9 +        display.closed.connect(onDisplayClosed);
    1.10 +        display.opened.connect(onDisplayOpened);
    1.11          display.openError.connect(updateDisplayStatusError);
    1.12 +        display.powerStatus.connect(updatePowerStatus);
    1.13 +        display.deviceId.connect(updateDeviceId);
    1.14 +        display.firmwareVersion.connect(updateFirmwareVersion);
    1.15      }
    1.16  
    1.17 +    function updatePowerStatus(powerOn)
    1.18 +    {
    1.19 +        if (powerOn)
    1.20 +        {
    1.21 +            labelDisplayPowerStatus.text=qsTr("Power: ON");
    1.22 +        }
    1.23 +        else
    1.24 +        {
    1.25 +            labelDisplayPowerStatus.text=qsTr("Power: OFF");
    1.26 +        }
    1.27 +    }
    1.28 +
    1.29 +    function updateDeviceId(deviceId)
    1.30 +    {
    1.31 +        labelDisplayDeviceId.text = deviceId;
    1.32 +        display.requestFirmwareVersion();
    1.33 +    }
    1.34 +
    1.35 +    function updateFirmwareVersion(version)
    1.36 +    {
    1.37 +        labelDisplayFirmwareVersion.text = "Firmware v" + version;
    1.38 +        display.requestPowerStatus();
    1.39 +    }
    1.40 +
    1.41 +    function onDisplayOpened()
    1.42 +    {
    1.43 +        updateDisplayStatus();
    1.44 +        //
    1.45 +        display.requestDeviceId();
    1.46 +    }
    1.47 +
    1.48 +    function onDisplayClosed()
    1.49 +    {
    1.50 +        updateDisplayStatus();
    1.51 +        labelDisplayDeviceId.text="";
    1.52 +        labelDisplayFirmwareVersion.text="";
    1.53 +        labelDisplayPowerStatus.text="";
    1.54 +    }
    1.55 +
    1.56 +
    1.57      function updateDisplayStatusError()
    1.58      {
    1.59          updateDisplayStatus();
    1.60 @@ -56,5 +99,21 @@
    1.61              visible: false //We don't want to display that. GP1212A01A does not even provide a proper string.
    1.62              text: qsTr("")
    1.63          }
    1.64 +
    1.65 +        Label {
    1.66 +            id: labelDisplayDeviceId
    1.67 +            text: qsTr("")
    1.68 +        }
    1.69 +
    1.70 +        Label {
    1.71 +            id: labelDisplayFirmwareVersion
    1.72 +            text: qsTr("")
    1.73 +        }
    1.74 +
    1.75 +        Label {
    1.76 +            id: labelDisplayPowerStatus
    1.77 +            text: qsTr("")
    1.78 +        }
    1.79 +
    1.80      }
    1.81  }
     2.1 --- a/MiniDisplay/FutabaVfd.cpp	Wed May 28 11:42:49 2014 +0200
     2.2 +++ b/MiniDisplay/FutabaVfd.cpp	Wed May 28 15:23:41 2014 +0200
     2.3 @@ -73,7 +73,7 @@
     2.4  
     2.5  GP1212A01A::GP1212A01A():
     2.6  	iDisplayPositionX(0),iDisplayPositionY(0),
     2.7 -	iOffScreenMode(true),iFrameBuffer(NULL)
     2.8 +    iOffScreenMode(true),iFrameBuffer(NULL),iRequest(ERequestNone),iPowerOn(false)
     2.9  	{
    2.10  	//ResetBuffers();
    2.11  	}
    2.12 @@ -381,8 +381,14 @@
    2.13  
    2.14  /**
    2.15  */
    2.16 -void GP1212A01A::RequestId()
    2.17 +void GP1212A01A::RequestDeviceId()
    2.18      {
    2.19 +    if (RequestPending())
    2.20 +        {
    2.21 +        //Abort silently for now
    2.22 +        return;
    2.23 +        }
    2.24 +
    2.25      //1BH,5BH,63H,49H,44H
    2.26      //Send Read ID command
    2.27      FutabaVfdReport report;
    2.28 @@ -393,13 +399,22 @@
    2.29      report[4]=0x63; //Command ID
    2.30      report[5]=0x49; //Command ID
    2.31      report[6]=0x44; //Command ID
    2.32 -    Write(report);
    2.33 +    if (Write(report)==report.Size())
    2.34 +        {
    2.35 +        iRequest=ERequestDeviceId;
    2.36 +        }
    2.37      }
    2.38  
    2.39  /**
    2.40  */
    2.41  void GP1212A01A::RequestFirmwareRevision()
    2.42      {
    2.43 +    if (RequestPending())
    2.44 +        {
    2.45 +        //Abort silently for now
    2.46 +        return;
    2.47 +        }
    2.48 +
    2.49      //1BH,5BH,63H,46H,52H
    2.50      //Send Software Revision Read Command
    2.51      FutabaVfdReport report;
    2.52 @@ -410,13 +425,21 @@
    2.53      report[4]=0x63; //Command ID
    2.54      report[5]=0x46; //Command ID
    2.55      report[6]=0x52; //Command ID
    2.56 -    Write(report);
    2.57 +    if (Write(report)==report.Size())
    2.58 +        {
    2.59 +        iRequest=ERequestFirmwareRevision;
    2.60 +        }
    2.61      }
    2.62  
    2.63  /**
    2.64  */
    2.65  void GP1212A01A::RequestPowerSupplyStatus()
    2.66      {
    2.67 +    if (RequestPending())
    2.68 +        {
    2.69 +        //Abort silently for now
    2.70 +        return;
    2.71 +        }
    2.72      //1BH,5BH,63H,50H,4DH
    2.73      //Send Power Suppply Monitor Command
    2.74      FutabaVfdReport report;
    2.75 @@ -427,7 +450,10 @@
    2.76      report[4]=0x63; //Command ID
    2.77      report[5]=0x50; //Command ID
    2.78      report[6]=0x4D; //Command ID
    2.79 -    Write(report);
    2.80 +    if (Write(report)==report.Size())
    2.81 +        {
    2.82 +        iRequest=ERequestPowerSupplyStatus;
    2.83 +        }
    2.84      }
    2.85  
    2.86  
    2.87 @@ -444,3 +470,39 @@
    2.88  	SwapBuffers();
    2.89  	Clear();
    2.90  	}
    2.91 +
    2.92 +/**
    2.93 + */
    2.94 +GP1212A01A::Request GP1212A01A::AttemptRequestCompletion()
    2.95 +    {
    2.96 +    if (!RequestPending())
    2.97 +        {
    2.98 +        return ERequestNone;
    2.99 +        }
   2.100 +
   2.101 +    int res=Read(iInputReport);
   2.102 +
   2.103 +    if (!res)
   2.104 +        {
   2.105 +        return ERequestNone;
   2.106 +        }
   2.107 +
   2.108 +    //Process our request
   2.109 +    if (CurrentRequest()==GP1212A01A::ERequestPowerSupplyStatus)
   2.110 +        {
   2.111 +        if (iInputReport[1]==0x4F && iInputReport[2]==0x4E)
   2.112 +            {
   2.113 +            iPowerOn = true;
   2.114 +            }
   2.115 +        else if (iInputReport[1]==0x4F && iInputReport[2]==0x46 && iInputReport[3]==0x46)
   2.116 +            {
   2.117 +            iPowerOn = false;
   2.118 +            }
   2.119 +        }
   2.120 +
   2.121 +    Request completed=iRequest;
   2.122 +    //Our request was completed
   2.123 +    iRequest=ERequestNone;
   2.124 +
   2.125 +    return completed;
   2.126 +    }
     3.1 --- a/MiniDisplay/FutabaVfd.h	Wed May 28 11:42:49 2014 +0200
     3.2 +++ b/MiniDisplay/FutabaVfd.h	Wed May 28 15:23:41 2014 +0200
     3.3 @@ -117,8 +117,18 @@
     3.4  class GP1212A01A : public GP1212XXXX
     3.5  	{
     3.6  public:
     3.7 -	GP1212A01A();
     3.8 -	~GP1212A01A();
     3.9 +    enum Request
    3.10 +        {
    3.11 +        ERequestNone,
    3.12 +        ERequestDeviceId,
    3.13 +        ERequestFirmwareRevision,
    3.14 +        ERequestPowerSupplyStatus
    3.15 +        };
    3.16 +
    3.17 +public:
    3.18 +    GP1212A01A();
    3.19 +    ~GP1212A01A();
    3.20 +
    3.21  	//
    3.22  	int Open();
    3.23  	//From FutabaGraphicVfd
    3.24 @@ -139,14 +149,19 @@
    3.25  	void SetDisplayPosition(unsigned char aX, unsigned char aY);
    3.26  	void SwapBuffers();
    3.27      //
    3.28 -    void RequestId();
    3.29 +    void RequestDeviceId();
    3.30      void RequestFirmwareRevision();
    3.31      void RequestPowerSupplyStatus();
    3.32  	//
    3.33  	void ToggleOffScreenMode();
    3.34      bool OffScreenMode() const {return iOffScreenMode;}
    3.35  	//
    3.36 -
    3.37 +    bool RequestPending(){return iRequest!=ERequestNone;}
    3.38 +    Request CurrentRequest(){return iRequest;}
    3.39 +    void CancelRequest(){iRequest=ERequestNone;}
    3.40 +    Request AttemptRequestCompletion();
    3.41 +    FutabaVfdReport& InputReport() {return iInputReport;}
    3.42 +    bool PowerOn(){return iPowerOn;}
    3.43  	
    3.44  private:
    3.45  	enum DW
    3.46 @@ -175,6 +190,9 @@
    3.47  	//unsigned char iFrameBeta[256*64];
    3.48  	//unsigned char *iFrontBuffer;
    3.49  	//unsigned char *iBackBuffer;
    3.50 +    Request iRequest;
    3.51 +    FutabaVfdReport iInputReport;
    3.52 +    bool iPowerOn;
    3.53  	};
    3.54  
    3.55  
     4.1 --- a/MiniDisplay/minidisplay.cpp	Wed May 28 11:42:49 2014 +0200
     4.2 +++ b/MiniDisplay/minidisplay.cpp	Wed May 28 15:23:41 2014 +0200
     4.3 @@ -1,8 +1,11 @@
     4.4  #include "minidisplay.h"
     4.5  #include <QPainter>
     4.6 +#include <QTimer>
     4.7 +
     4.8 +const int KMaxReadAttempt=100;
     4.9  
    4.10  MiniDisplay::MiniDisplay(QQuickItem *parent):
    4.11 -    QQuickItem(parent)
    4.12 +    QQuickItem(parent),iReadAttempt(0)
    4.13  {
    4.14      // By default, QQuickItem does not draw anything. If you subclass
    4.15      // QQuickItem to create a visual item, you will need to uncomment the
    4.16 @@ -66,6 +69,35 @@
    4.17      iDisplay.SwapBuffers();
    4.18  }
    4.19  
    4.20 +void MiniDisplay::requestPowerStatus()
    4.21 +{
    4.22 +    if (!iDisplay.IsOpen()) return;
    4.23 +
    4.24 +    iDisplay.RequestPowerSupplyStatus();
    4.25 +    QTimer::singleShot(4, this, SLOT(readTimer()));
    4.26 +    iReadAttempt=0;
    4.27 +}
    4.28 +
    4.29 +void MiniDisplay::requestDeviceId()
    4.30 +{
    4.31 +    if (!iDisplay.IsOpen()) return;
    4.32 +
    4.33 +    iDisplay.RequestDeviceId();
    4.34 +    QTimer::singleShot(4, this, SLOT(readTimer()));
    4.35 +    iReadAttempt=0;
    4.36 +}
    4.37 +
    4.38 +void MiniDisplay::requestFirmwareVersion()
    4.39 +{
    4.40 +    if (!iDisplay.IsOpen()) return;
    4.41 +
    4.42 +    iDisplay.RequestFirmwareRevision();
    4.43 +    QTimer::singleShot(4, this, SLOT(readTimer()));
    4.44 +    iReadAttempt=0;
    4.45 +}
    4.46 +
    4.47 +
    4.48 +
    4.49  /**
    4.50   * @brief setFont
    4.51   * @param aFont
    4.52 @@ -133,4 +165,42 @@
    4.53      return QString::fromWCharArray(iDisplay.SerialNumber());
    4.54  }
    4.55  
    4.56 +/**
    4.57 + * @brief MiniDisplay::readTimer
    4.58 + */
    4.59 +void MiniDisplay::readTimer()
    4.60 +{
    4.61 +    if (!iDisplay.IsOpen()) return;
    4.62 +    if (!iDisplay.RequestPending()) return;
    4.63  
    4.64 +    iReadAttempt++;
    4.65 +    GP1212A01A::Request request = iDisplay.AttemptRequestCompletion();
    4.66 +
    4.67 +    if (!request)
    4.68 +    {
    4.69 +        if (iReadAttempt<KMaxReadAttempt)
    4.70 +        {
    4.71 +            //Will try again later
    4.72 +            QTimer::singleShot(4, this, SLOT(readTimer()));
    4.73 +        }
    4.74 +
    4.75 +        return;
    4.76 +    }
    4.77 +
    4.78 +    //TODO: Find a way to remove device specific stuff from here
    4.79 +    if (request==GP1212A01A::ERequestFirmwareRevision)
    4.80 +    {
    4.81 +        QString version=QString::fromLocal8Bit((const char*)iDisplay.InputReport().Buffer()+1);
    4.82 +        emit firmwareVersion(version);
    4.83 +    }
    4.84 +    else if (request==GP1212A01A::ERequestDeviceId)
    4.85 +    {
    4.86 +        QString id=QString::fromLocal8Bit((const char*)iDisplay.InputReport().Buffer()+1);
    4.87 +        emit deviceId(id);
    4.88 +    }
    4.89 +    else if (request==GP1212A01A::ERequestPowerSupplyStatus)
    4.90 +    {
    4.91 +        emit powerStatus(iDisplay.PowerOn());
    4.92 +    }
    4.93 +}
    4.94 +
     5.1 --- a/MiniDisplay/minidisplay.h	Wed May 28 11:42:49 2014 +0200
     5.2 +++ b/MiniDisplay/minidisplay.h	Wed May 28 15:23:41 2014 +0200
     5.3 @@ -23,6 +23,10 @@
     5.4      Q_INVOKABLE void clear();
     5.5      Q_INVOKABLE void fill();
     5.6      Q_INVOKABLE void swapBuffers();
     5.7 +    //
     5.8 +    Q_INVOKABLE void requestPowerStatus();
     5.9 +    Q_INVOKABLE void requestDeviceId();
    5.10 +    Q_INVOKABLE void requestFirmwareVersion();
    5.11  
    5.12  public:
    5.13      //Properties
    5.14 @@ -40,6 +44,14 @@
    5.15      void closed();
    5.16      void statusChanged();
    5.17      void fontChanged();
    5.18 +    //
    5.19 +    void powerStatus(bool powerOn);
    5.20 +    void deviceId(QString deviceId);
    5.21 +    void firmwareVersion(QString version);
    5.22 +
    5.23 +public slots:
    5.24 +    void readTimer();
    5.25 +
    5.26  
    5.27  public:
    5.28      MiniDisplay(QQuickItem *parent = 0);
    5.29 @@ -48,6 +60,7 @@
    5.30  private:
    5.31      GP1212A01A iDisplay;
    5.32      QFont iFont;
    5.33 +    int iReadAttempt;
    5.34  };
    5.35  
    5.36  #endif // MINIDISPLAY_H