Drafting new Futaba class.
authorsl
Wed, 21 May 2014 16:11:09 +0200
changeset 9e6c42e1e2a96
parent 8 631f53604811
child 10 4c3d32f38c09
Drafting new Futaba class.
FutabaVfd.cpp
FutabaVfd.h
FutabaVfd.vcxproj
MainWindow.h
test.cpp
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/FutabaVfd.cpp	Wed May 21 16:11:09 2014 +0200
     1.3 @@ -0,0 +1,54 @@
     1.4 +
     1.5 +#include "FutabaVfd.h"
     1.6 +//#include <stdlib.h>
     1.7 +#include <string.h>
     1.8 +
     1.9 +FutabaVfdCommand::FutabaVfdCommand():/*iBuffer(NULL),*/iSize(0),iMaxSize(0)
    1.10 +    {
    1.11 +    }
    1.12 +
    1.13 +FutabaVfdCommand::~FutabaVfdCommand()
    1.14 +    {
    1.15 +    //Delete();
    1.16 +    }
    1.17 +
    1.18 +
    1.19 +/**
    1.20 +
    1.21 +*/
    1.22 +void FutabaVfdCommand::Reset()
    1.23 +    {
    1.24 +    memset(iReports,0,sizeof(iReports));
    1.25 +    }
    1.26 +
    1.27 +
    1.28 +
    1.29 +/**
    1.30 +
    1.31 +*/
    1.32 +/*
    1.33 +void FutabaVfdCommand::Create(int aMaxSize)
    1.34 +    {
    1.35 +    iBuffer=new unsigned char[aMaxSize];
    1.36 +    if (iBuffer)
    1.37 +        {
    1.38 +        iMaxSize = aMaxSize;
    1.39 +        iSize = 0;
    1.40 +        }
    1.41 +    }
    1.42 +*/
    1.43 +
    1.44 +/**
    1.45 +
    1.46 +*/
    1.47 +/*
    1.48 +void FutabaVfdCommand::Delete()
    1.49 +{
    1.50 +    delete[] iBuffer;
    1.51 +    iBuffer = NULL;
    1.52 +    iMaxSize = 0;
    1.53 +    iSize = 0;
    1.54 +}
    1.55 +*/
    1.56 +
    1.57 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/FutabaVfd.h	Wed May 21 16:11:09 2014 +0200
     2.3 @@ -0,0 +1,39 @@
     2.4 +
     2.5 +
     2.6 +#ifndef FUTABA_VFD_H
     2.7 +#define FUTABA_VFD_H
     2.8 +
     2.9 +#include "hidapi.h"
    2.10 +
    2.11 +//This was computed from our number of pixels as follow 256x64/8/64 = 32 + 1 = 33
    2.12 +//+1 was added for our header
    2.13 +const int KFutabaMaxCommandOutputReport = 33;
    2.14 +//TODO: Get ride of that constant once we figure out a way to get it from hidapi
    2.15 +const int KFutabaOutputReportLength = 65;
    2.16 +
    2.17 +
    2.18 +/**
    2.19 +Define a generic Futaba VFD command.
    2.20 +*/
    2.21 +class FutabaVfdCommand
    2.22 +    {
    2.23 +public:
    2.24 +    FutabaVfdCommand();
    2.25 +    ~FutabaVfdCommand();
    2.26 +    //
    2.27 +    //void Create(int aMaxSize);
    2.28 +    //void Delete();
    2.29 +
    2.30 +    //inline unsigned char& operator[](int aIndex){return iBuffer[aIndex];}
    2.31 +
    2.32 +    void Reset();
    2.33 +
    2.34 +private:
    2.35 +    //unsigned char* iBuffer;
    2.36 +    unsigned char iReports[KFutabaMaxCommandOutputReport][KFutabaOutputReportLength];
    2.37 +    int iSize;
    2.38 +    int iMaxSize;
    2.39 +    };
    2.40 +
    2.41 +
    2.42 +#endif
    2.43 \ No newline at end of file
     3.1 --- a/FutabaVfd.vcxproj	Wed May 21 10:19:22 2014 +0200
     3.2 +++ b/FutabaVfd.vcxproj	Wed May 21 16:11:09 2014 +0200
     3.3 @@ -104,11 +104,12 @@
     3.4    </ItemDefinitionGroup>
     3.5    <ItemGroup>
     3.6      <ClCompile Include="..\hidapi\windows\hid.c" />
     3.7 +    <ClCompile Include="FutabaVfd.cpp" />
     3.8      <ClCompile Include="Main.cpp" />
     3.9      <ClCompile Include="test.cpp" />
    3.10    </ItemGroup>
    3.11    <ItemGroup>
    3.12 -    <ClInclude Include="..\hidapi\hidapi.h" />
    3.13 +    <ClInclude Include="FutabaVfd.h" />
    3.14      <ClInclude Include="MainWindow.h" />
    3.15    </ItemGroup>
    3.16    <ItemGroup>
     4.1 --- a/MainWindow.h	Wed May 21 10:19:22 2014 +0200
     4.2 +++ b/MainWindow.h	Wed May 21 16:11:09 2014 +0200
     4.3 @@ -9,10 +9,7 @@
     4.4  #include <string.h>
     4.5  #include <stdlib.h>
     4.6  #include <limits.h>
     4.7 -
     4.8 -
     4.9 -//TODO: Get ride of that constant once we figure out a way to get it from hidapi
    4.10 -const int KFutabaOutputReportLength = 65;
    4.11 +#include "FutabaVfd.h"
    4.12  
    4.13  #ifdef _WIN32
    4.14  // Thanks Microsoft, but I know how to use strncpy().
     5.1 --- a/test.cpp	Wed May 21 10:19:22 2014 +0200
     5.2 +++ b/test.cpp	Wed May 21 16:11:09 2014 +0200
     5.3 @@ -574,6 +574,12 @@
     5.4  	}
     5.5  
     5.6  /**
     5.7 +Set the defined pixel block to the given value.
     5.8 +@param X coordinate of our pixel block starting point.
     5.9 +@param Y coordinate of our pixel block starting point.
    5.10 +@param The height of our pixel block.
    5.11 +@param The size of our pixel data. Number of pixels divided by 8.
    5.12 +@param The value set to 8 pixels.
    5.13  */
    5.14  void MainWindow::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue)
    5.15  	{
    5.16 @@ -594,6 +600,30 @@
    5.17  	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
    5.18  	}
    5.19  
    5.20 +/**
    5.21 +Send an output report to a Futaba VFD device.
    5.22 +*/
    5.23 +/*
    5.24 +void MainWindow::SendFutabaOutputReport(unsigned char* aReportData, unsigned char aSize)
    5.25 +    {
    5.26 +    //
    5.27 +    memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength);
    5.28 +    iOutputReportBuffer[0]=0x00; //Report ID is always null
    5.29 +    iOutputReportBuffer[1]=0x08+aSize; //Report length
    5.30 +    iOutputReportBuffer[2]=0x1B; //
    5.31 +    iOutputReportBuffer[3]=0x5B; //
    5.32 +    iOutputReportBuffer[4]=0xF0; //
    5.33 +    iOutputReportBuffer[5]=aX; //X
    5.34 +    iOutputReportBuffer[6]=aY; //Y
    5.35 +    iOutputReportBuffer[7]=aHeight; //Y length before return. Though outside the specs, setting this to zero apparently allows us to modify a single pixel without touching any other.
    5.36 +    iOutputReportBuffer[8]=0x00; //Size of pixel data in bytes (MSB)
    5.37 +    iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB)
    5.38 +    memset(iOutputReportBuffer+10, aValue, KFutabaOutputReportLength);
    5.39 +    //iOutputReportBuffer[10]=aValue; //Pixel data
    5.40 +    int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
    5.41 +    }
    5.42 +*/
    5.43 +
    5.44  
    5.45  /**
    5.46  */