1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/MiniDisplay/FutabaVfd.h Tue May 27 19:50:28 2014 +0200
1.3 @@ -0,0 +1,181 @@
1.4 +//
1.5 +//
1.6 +//
1.7 +
1.8 +#ifndef FUTABA_VFD_H
1.9 +#define FUTABA_VFD_H
1.10 +
1.11 +#include "hidapi.h"
1.12 +#include "HidDevice.h"
1.13 +#include "BitArray.h"
1.14 +
1.15 +#ifndef MIN
1.16 +#define MIN(a,b) (((a)<(b))?(a):(b))
1.17 +#endif
1.18 +
1.19 +#ifndef MAX
1.20 +#define MAX(a,b) (((a)>(b))?(a):(b))
1.21 +#endif
1.22 +
1.23 +
1.24 +//This was computed from our number of pixels as follow 256x64/8/64 = 32 + 1 = 33
1.25 +//+1 was added for our header
1.26 +const int KFutabaMaxCommandOutputReport = 33;
1.27 +//TODO: Get ride of that constant once we figure out a way to get it from hidapi
1.28 +const int KFutabaMaxHidReportSize = 65;
1.29 +
1.30 +const int KHidReportIdIndex=0;
1.31 +const int KFutabaHidReportSizeIndex=1;
1.32 +//Define Futaba vendor ID to filter our list of device
1.33 +const unsigned short KFutabaVendorId = 0x1008;
1.34 +const unsigned short KFutabaProductIdGP1212A01A = 0x100C;
1.35 +const unsigned short KFutabaProductIdGP1212A02A = 0x1013; //Or is it 0x1015
1.36 +const int KGP12xWidthInPixels = 256;
1.37 +const int KGP12xHeightInPixels = 64;
1.38 +const int KGP12xPixelsPerByte = 8;
1.39 +const int KGP12xFrameBufferSizeInBytes = KGP12xWidthInPixels*KGP12xHeightInPixels/KGP12xPixelsPerByte; //256*64/8=2048
1.40 +const int KGP12xFrameBufferPixelCount = KGP12xWidthInPixels*KGP12xHeightInPixels;
1.41 +
1.42 +//typedef struct hid_device_info HidDeviceInfo;
1.43 +
1.44 +/**
1.45 +Define a Futaba HID report.
1.46 +*/
1.47 +class FutabaVfdReport: public HidReport<KFutabaMaxHidReportSize>
1.48 + {
1.49 +
1.50 +private:
1.51 +
1.52 + };
1.53 +
1.54 +
1.55 +/**
1.56 +Define a generic Futaba VFD command.
1.57 +*/
1.58 +class FutabaVfdCommand
1.59 + {
1.60 +public:
1.61 + FutabaVfdCommand();
1.62 + ~FutabaVfdCommand();
1.63 + //
1.64 + //void Create(int aMaxSize);
1.65 + //void Delete();
1.66 +
1.67 + //inline unsigned char& operator[](int aIndex){return iBuffer[aIndex];}
1.68 +
1.69 + void Reset();
1.70 +
1.71 +private:
1.72 + //unsigned char* iBuffer;
1.73 + FutabaVfdReport iReports[KFutabaMaxCommandOutputReport];
1.74 + int iSize;
1.75 + int iMaxSize;
1.76 + };
1.77 +
1.78 +/**
1.79 +*/
1.80 +class FutabaVfd : public HidDevice
1.81 + {
1.82 +public:
1.83 + virtual int MinBrightness() const=0;
1.84 + virtual int MaxBrightness() const=0;
1.85 + virtual void SetBrightness(int aBrightness)=0;
1.86 + virtual void Clear()=0;
1.87 + };
1.88 +
1.89 +
1.90 +/**
1.91 +*/
1.92 +class FutabaGraphicVfd : public FutabaVfd
1.93 + {
1.94 +public:
1.95 + virtual int WidthInPixels() const=0;
1.96 + virtual int HeightInPixels() const=0;
1.97 + virtual void SetPixel(unsigned char aX, unsigned char aY, bool aOn)=0;
1.98 + virtual void SetAllPixels(unsigned char aOn)=0;
1.99 + virtual int FrameBufferSizeInBytes() const=0;
1.100 + //virtual int BitBlit(unsigned char* aSrc, unsigned char aSrcWidth, unsigned char aSrcHeight, unsigned char aTargetX, unsigned char aTargetY) const=0;
1.101 +
1.102 + };
1.103 +
1.104 +/**
1.105 +Common functionality between GP1212A01A and GP1212A02A
1.106 +*/
1.107 +class GP1212XXXX : public FutabaGraphicVfd
1.108 + {
1.109 +public:
1.110 + //From FutabaVfd
1.111 + virtual int MinBrightness() const {return 0;}
1.112 + virtual int MaxBrightness() const {return 5;}
1.113 + };
1.114 +
1.115 +/**
1.116 +GP1212A01A is a graphic display module using a FUTABA 256x64dots VFD.
1.117 +The module do not include character ROM, the customer will compile the character
1.118 +by themselves (from main system).
1.119 +*/
1.120 +class GP1212A01A : public GP1212XXXX
1.121 + {
1.122 +public:
1.123 + GP1212A01A();
1.124 + ~GP1212A01A();
1.125 + //
1.126 + int Open();
1.127 + //From FutabaGraphicVfd
1.128 + virtual int WidthInPixels() const {return KGP12xWidthInPixels;}
1.129 + virtual int HeightInPixels() const {return KGP12xHeightInPixels;}
1.130 + virtual void SetPixel(unsigned char aX, unsigned char aY, bool aOn);
1.131 + virtual void SetAllPixels(unsigned char aPattern);
1.132 + virtual int FrameBufferSizeInBytes() const {return KGP12xFrameBufferSizeInBytes;}
1.133 + virtual void BitBlit(BitArray& aBitmap, int aSrcWidth, int aSrcHeight, int aTargetX, int aTargetY) const;
1.134 + //From FutabaVfd
1.135 + virtual void SetBrightness(int aBrightness);
1.136 + virtual void Clear();
1.137 +
1.138 + //Specific to GP1212A01A
1.139 + void SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char aValue);
1.140 + void SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char* aPixels);
1.141 + //
1.142 + void SetDisplayPosition(unsigned char aX, unsigned char aY);
1.143 + void SwapBuffers();
1.144 + //
1.145 + void RequestId();
1.146 + void RequestFirmwareRevision();
1.147 + void RequestPowerSupplyStatus();
1.148 + //
1.149 + void ToggleOffScreenMode();
1.150 + bool OffScreenMode() const {return iOffScreenMode;}
1.151 + //
1.152 +
1.153 +
1.154 +private:
1.155 + enum DW
1.156 + {
1.157 + DW1=0xC0,
1.158 + DW2=0xD0
1.159 + };
1.160 +
1.161 + void SetDisplayPosition(DW aDw,unsigned char aX, unsigned char aY);
1.162 + unsigned char OffScreenY() const;
1.163 + void SendClearCommand();
1.164 + void OffScreenTranslation(unsigned char& aX, unsigned char& aY);
1.165 + void ResetBuffers();
1.166 +
1.167 +private:
1.168 + unsigned char iDisplayPositionX;
1.169 + unsigned char iDisplayPositionY;
1.170 + ///Off screen mode is the recommended default settings to avoid tearing.
1.171 + ///Though turning it off can be useful for debugging
1.172 + bool iOffScreenMode;
1.173 + ///
1.174 + //FutabaVfdReport iReport;
1.175 + ///
1.176 + //unsigned char iFrameBuffer[256*64];
1.177 + BitArray* iFrameBuffer;
1.178 + //unsigned char iFrameBeta[256*64];
1.179 + //unsigned char *iFrontBuffer;
1.180 + //unsigned char *iBackBuffer;
1.181 + };
1.182 +
1.183 +
1.184 +#endif