sl@0: // sl@0: // sl@0: // sl@0: sl@0: #ifndef FUTABA_VFD_H sl@0: #define FUTABA_VFD_H sl@0: sl@0: #include "hidapi.h" sl@0: #include "HidDevice.h" sl@0: #include "BitArray.h" sl@0: sl@0: #ifndef MIN sl@0: #define MIN(a,b) (((a)<(b))?(a):(b)) sl@0: #endif sl@0: sl@0: #ifndef MAX sl@0: #define MAX(a,b) (((a)>(b))?(a):(b)) sl@0: #endif sl@0: sl@0: sl@0: //This was computed from our number of pixels as follow 256x64/8/64 = 32 + 1 = 33 sl@0: //+1 was added for our header sl@0: const int KFutabaMaxCommandOutputReport = 33; sl@0: //TODO: Get ride of that constant once we figure out a way to get it from hidapi sl@0: const int KFutabaMaxHidReportSize = 65; sl@0: sl@0: const int KHidReportIdIndex=0; sl@0: const int KFutabaHidReportSizeIndex=1; sl@0: //Define Futaba vendor ID to filter our list of device sl@0: const unsigned short KFutabaVendorId = 0x1008; sl@0: const unsigned short KFutabaProductIdGP1212A01A = 0x100C; sl@0: const unsigned short KFutabaProductIdGP1212A02A = 0x1013; //Or is it 0x1015 sl@0: const int KGP12xWidthInPixels = 256; sl@0: const int KGP12xHeightInPixels = 64; sl@0: const int KGP12xPixelsPerByte = 8; sl@0: const int KGP12xFrameBufferSizeInBytes = KGP12xWidthInPixels*KGP12xHeightInPixels/KGP12xPixelsPerByte; //256*64/8=2048 sl@0: const int KGP12xFrameBufferPixelCount = KGP12xWidthInPixels*KGP12xHeightInPixels; sl@0: sl@0: //typedef struct hid_device_info HidDeviceInfo; sl@0: sl@0: /** sl@0: Define a Futaba HID report. sl@0: */ sl@0: class FutabaVfdReport: public HidReport sl@0: { sl@0: sl@0: private: sl@0: sl@0: }; sl@0: sl@0: sl@0: /** sl@0: Define a generic Futaba VFD command. sl@0: */ sl@0: class FutabaVfdCommand sl@0: { sl@0: public: sl@0: FutabaVfdCommand(); sl@0: ~FutabaVfdCommand(); sl@0: // sl@0: //void Create(int aMaxSize); sl@0: //void Delete(); sl@0: sl@0: //inline unsigned char& operator[](int aIndex){return iBuffer[aIndex];} sl@0: sl@0: void Reset(); sl@0: sl@0: private: sl@0: //unsigned char* iBuffer; sl@0: FutabaVfdReport iReports[KFutabaMaxCommandOutputReport]; sl@0: int iSize; sl@0: int iMaxSize; sl@0: }; sl@0: sl@0: /** sl@0: */ sl@0: class FutabaVfd : public HidDevice sl@0: { sl@0: public: sl@0: virtual int MinBrightness() const=0; sl@0: virtual int MaxBrightness() const=0; sl@0: virtual void SetBrightness(int aBrightness)=0; sl@0: virtual void Clear()=0; sl@0: }; sl@0: sl@0: sl@0: /** sl@0: */ sl@0: class FutabaGraphicVfd : public FutabaVfd sl@0: { sl@0: public: sl@0: virtual int WidthInPixels() const=0; sl@0: virtual int HeightInPixels() const=0; sl@0: virtual void SetPixel(unsigned char aX, unsigned char aY, bool aOn)=0; sl@0: virtual void SetAllPixels(unsigned char aOn)=0; sl@0: virtual int FrameBufferSizeInBytes() const=0; sl@0: //virtual int BitBlit(unsigned char* aSrc, unsigned char aSrcWidth, unsigned char aSrcHeight, unsigned char aTargetX, unsigned char aTargetY) const=0; sl@0: sl@0: }; sl@0: sl@0: /** sl@0: Common functionality between GP1212A01A and GP1212A02A sl@0: */ sl@0: class GP1212XXXX : public FutabaGraphicVfd sl@0: { sl@0: public: sl@0: //From FutabaVfd sl@0: virtual int MinBrightness() const {return 0;} sl@0: virtual int MaxBrightness() const {return 5;} sl@0: }; sl@0: sl@0: /** sl@0: GP1212A01A is a graphic display module using a FUTABA 256x64dots VFD. sl@0: The module do not include character ROM, the customer will compile the character sl@0: by themselves (from main system). sl@0: */ sl@0: class GP1212A01A : public GP1212XXXX sl@0: { sl@0: public: sl@0: enum Request sl@0: { sl@0: ERequestNone, sl@0: ERequestDeviceId, sl@0: ERequestFirmwareRevision, sl@0: ERequestPowerSupplyStatus sl@0: }; sl@0: sl@0: public: sl@0: GP1212A01A(); sl@0: ~GP1212A01A(); sl@0: sl@0: // sl@0: int Open(); sl@0: //From FutabaGraphicVfd sl@0: virtual int WidthInPixels() const {return KGP12xWidthInPixels;} sl@0: virtual int HeightInPixels() const {return KGP12xHeightInPixels;} sl@0: virtual void SetPixel(unsigned char aX, unsigned char aY, bool aOn); sl@0: virtual void SetAllPixels(unsigned char aPattern); sl@0: virtual int FrameBufferSizeInBytes() const {return KGP12xFrameBufferSizeInBytes;} sl@0: virtual void BitBlit(const BitArray& aBitmap, int aSrcWidth, int aSrcHeight, int aTargetX, int aTargetY) const; sl@0: //From FutabaVfd sl@0: virtual void SetBrightness(int aBrightness); sl@0: virtual void Clear(); sl@0: sl@0: //Specific to GP1212A01A sl@0: void SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char aValue); sl@0: void SetPixelBlock(unsigned char aX, unsigned char aY, int aHeight, int aSize, unsigned char* aPixels); sl@0: //Define display position within our display RAM sl@0: void SetDisplayPosition(unsigned char aX, unsigned char aY); sl@0: unsigned char DisplayPositionX() const {return iDisplayPositionX;} sl@0: unsigned char DisplayPositionY() const {return iDisplayPositionY;} sl@0: // sl@0: void SwapBuffers(); sl@0: // sl@0: void RequestDeviceId(); sl@0: void RequestFirmwareRevision(); sl@0: void RequestPowerSupplyStatus(); sl@0: // sl@0: void ToggleOffScreenMode(); sl@0: void SetOffScreenMode(bool aOn); sl@0: bool OffScreenMode() const {return iOffScreenMode;} sl@0: // sl@0: void SetFrameDifferencing(bool aOn){iUseFrameDifferencing=aOn;} sl@0: bool FrameDifferencing() const {return iUseFrameDifferencing;} sl@0: // sl@0: bool RequestPending(){return iRequest!=ERequestNone;} sl@0: Request CurrentRequest(){return iRequest;} sl@0: void CancelRequest(){iRequest=ERequestNone;} sl@0: Request AttemptRequestCompletion(); sl@0: FutabaVfdReport& InputReport() {return iInputReport;} sl@0: bool PowerOn(){return iPowerOn;} sl@0: sl@0: private: sl@0: enum DW sl@0: { sl@0: DW1=0xC0, sl@0: DW2=0xD0 sl@0: }; sl@0: sl@0: void SetDisplayPosition(DW aDw,unsigned char aX, unsigned char aY); sl@0: unsigned char OffScreenY() const; sl@0: void SendClearCommand(); sl@0: void OffScreenTranslation(unsigned char& aX, unsigned char& aY); sl@0: void ResetBuffers(); sl@0: void SendModifiedPixelBlocks(); sl@0: sl@0: private: sl@0: unsigned char iDisplayPositionX; sl@0: unsigned char iDisplayPositionY; sl@0: ///Off screen mode is the recommended default settings to avoid tearing. sl@0: ///Though turning it off can be useful for debugging sl@0: bool iOffScreenMode; sl@0: ///Frame differences algo is used to reduce USB bus traffic and improve frame rate in typical use case sl@0: bool iUseFrameDifferencing; sl@0: /// sl@0: //FutabaVfdReport iReport; sl@0: /// sl@0: //unsigned char iFrameBuffer[256*64]; sl@0: BitArray* iFrameNext; sl@0: BitArray* iFrameCurrent; sl@0: BitArray* iFramePrevious; sl@0: // sl@0: BitArray* iFrameAlpha; sl@0: BitArray* iFrameBeta; sl@0: BitArray* iFrameGamma; sl@0: // sl@0: int iNeedFullFrameUpdate; sl@0: //unsigned char iFrameBeta[256*64]; sl@0: //unsigned char *iFrontBuffer; sl@0: //unsigned char *iBackBuffer; sl@0: Request iRequest; sl@0: FutabaVfdReport iInputReport; sl@0: bool iPowerOn; sl@0: }; sl@0: sl@0: sl@0: #endif