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