FutabaVfd.cpp
changeset 12 7268128148b8
parent 11 11a0e8a2346e
child 13 69f1fcfdf6a5
     1.1 --- a/FutabaVfd.cpp	Wed May 21 22:55:14 2014 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,227 +0,0 @@
     1.4 -
     1.5 -#include "FutabaVfd.h"
     1.6 -//#include <stdlib.h>
     1.7 -#include <string.h>
     1.8 -
     1.9 -
    1.10 -//
    1.11 -//
    1.12 -//
    1.13 -
    1.14 -
    1.15 -
    1.16 -
    1.17 -
    1.18 -//
    1.19 -//
    1.20 -//
    1.21 -
    1.22 -FutabaVfdCommand::FutabaVfdCommand():/*iBuffer(NULL),*/iSize(0),iMaxSize(0)
    1.23 -    {
    1.24 -    }
    1.25 -
    1.26 -FutabaVfdCommand::~FutabaVfdCommand()
    1.27 -    {
    1.28 -    //Delete();
    1.29 -    }
    1.30 -
    1.31 -
    1.32 -/**
    1.33 -
    1.34 -*/
    1.35 -void FutabaVfdCommand::Reset()
    1.36 -    {
    1.37 -    memset(iReports,0,sizeof(iReports));
    1.38 -    }
    1.39 -
    1.40 -
    1.41 -
    1.42 -/**
    1.43 -
    1.44 -*/
    1.45 -/*
    1.46 -void FutabaVfdCommand::Create(int aMaxSize)
    1.47 -    {
    1.48 -    iBuffer=new unsigned char[aMaxSize];
    1.49 -    if (iBuffer)
    1.50 -        {
    1.51 -        iMaxSize = aMaxSize;
    1.52 -        iSize = 0;
    1.53 -        }
    1.54 -    }
    1.55 -*/
    1.56 -
    1.57 -/**
    1.58 -
    1.59 -*/
    1.60 -/*
    1.61 -void FutabaVfdCommand::Delete()
    1.62 -{
    1.63 -    delete[] iBuffer;
    1.64 -    iBuffer = NULL;
    1.65 -    iMaxSize = 0;
    1.66 -    iSize = 0;
    1.67 -}
    1.68 -*/
    1.69 -
    1.70 -
    1.71 -//
    1.72 -// class HidDevice
    1.73 -//
    1.74 -
    1.75 -/**
    1.76 -*/
    1.77 -int HidDevice::Open(const char* aPath)
    1.78 -	{
    1.79 -	Close();
    1.80 -
    1.81 -	iHidDevice =  hid_open_path(aPath);
    1.82 -
    1.83 -	if (!iHidDevice)
    1.84 -		{
    1.85 -		//Fail to connect our device
    1.86 -		return 0;
    1.87 -		}
    1.88 -
    1.89 -	return 1;
    1.90 -	}
    1.91 -
    1.92 -/**
    1.93 -See hidapi documentation.
    1.94 -*/
    1.95 -int HidDevice::Open(unsigned short aVendorId, unsigned short aProductId, const wchar_t* aSerialNumber)
    1.96 -	{
    1.97 -	iHidDevice = hid_open(aVendorId, aProductId, aSerialNumber);
    1.98 -
    1.99 -	if (!iHidDevice)
   1.100 -		{
   1.101 -		//Fail to connect our device
   1.102 -		return 0;
   1.103 -		}
   1.104 -
   1.105 -	return 1;
   1.106 -	}
   1.107 -
   1.108 -/**
   1.109 -*/
   1.110 -void HidDevice::Close()
   1.111 -	{
   1.112 -	hid_close(iHidDevice);
   1.113 -	iHidDevice=NULL;
   1.114 -	}
   1.115 -
   1.116 -
   1.117 -/**
   1.118 -*/
   1.119 -const wchar_t* HidDevice::Error()
   1.120 -	{
   1.121 -	return hid_error(iHidDevice);
   1.122 -	}
   1.123 -
   1.124 -/**
   1.125 -*/
   1.126 -int HidDevice::SetNonBlocking(int aNonBlocking)
   1.127 -	{
   1.128 -	//Success we are now connected to our HID device 
   1.129 -	//Set read operation as non blocking
   1.130 -	return hid_set_nonblocking(iHidDevice, aNonBlocking);
   1.131 -	}
   1.132 -
   1.133 -
   1.134 -//
   1.135 -// class GP1212A01A
   1.136 -//
   1.137 -
   1.138 -int GP1212A01A::Open()
   1.139 -	{
   1.140 -	int success = HidDevice::Open(KFutabaVendorId,KFutabaProductIdGP1212A01A,NULL);
   1.141 -	if (success)
   1.142 -		{
   1.143 -		SetNonBlocking(1);
   1.144 -		}
   1.145 -	return success;
   1.146 -	}
   1.147 -
   1.148 -/**
   1.149 -*/
   1.150 -void GP1212A01A::SetPixel(int aX, int aY, bool aOn)
   1.151 -	{
   1.152 -	//Just specify a one pixel block
   1.153 -	SetPixelBlock(aX,aY,0x00,0x01,aOn);
   1.154 -	}
   1.155 -
   1.156 -/**
   1.157 -*/
   1.158 -void GP1212A01A::SetAllPixels(bool aOn)
   1.159 -	{
   1.160 -	//One pixel at a time
   1.161 -	/*
   1.162 -	for (int i=0;i<256;i++)
   1.163 -		{
   1.164 -		for (int j=0;j<64;j++)
   1.165 -			{
   1.166 -			SetPixel(i,j,0x01);
   1.167 -			}
   1.168 -		}
   1.169 -	*/
   1.170 -
   1.171 -	//16x16=256 pixels at a time goes much faster
   1.172 -	//TODO: use even larger blocks
   1.173 -	for (int i=0;i<256;i+=16)
   1.174 -		{
   1.175 -		for (int j=0;j<64;j+=16)
   1.176 -			{
   1.177 -			SetPixelBlock(i,j,15,32,(aOn?0xFF:0x00));
   1.178 -			//FXThread::sleep(1000000000);
   1.179 -			}
   1.180 -		}
   1.181 -
   1.182 -	}
   1.183 -
   1.184 -/**
   1.185 -*/
   1.186 -void GP1212A01A::SetBrightness(int aBrightness)
   1.187 -	{
   1.188 -	}
   1.189 -
   1.190 -/**
   1.191 -Set the defined pixel block to the given value.
   1.192 -@param X coordinate of our pixel block starting point.
   1.193 -@param Y coordinate of our pixel block starting point.
   1.194 -@param The height of our pixel block.
   1.195 -@param The size of our pixel data. Number of pixels divided by 8.
   1.196 -@param The value set to 8 pixels.
   1.197 -*/
   1.198 -void GP1212A01A::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue)
   1.199 -	{
   1.200 -	//Size must be 63 or below
   1.201 -	FutabaVfdReport report;
   1.202 -	report[0]=0x00; //Report ID
   1.203 -	report[1]=0x08+aSize; //Report length
   1.204 -	report[2]=0x1B; //
   1.205 -	report[3]=0x5B; //
   1.206 -	report[4]=0xF0; //
   1.207 -	report[5]=aX; //X
   1.208 -	report[6]=aY; //Y
   1.209 -	report[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.
   1.210 -	report[8]=0x00; //Size of pixel data in bytes (MSB)
   1.211 -	report[9]=aSize; //Size of pixel data in bytes (LSB)
   1.212 -	memset(report.Buffer()+10, aValue, aSize);
   1.213 -	//iOutputReportBuffer[10]=aValue; //Pixel data
   1.214 -	Write(report);
   1.215 -	}
   1.216 -
   1.217 -
   1.218 -/**
   1.219 -*/
   1.220 -void GP1212A01A::Clear()
   1.221 -	{
   1.222 -	FutabaVfdReport report;
   1.223 -	report[0]=0x00; //Report ID
   1.224 -	report[1]=0x04; //Report length
   1.225 -	report[2]=0x1B; //
   1.226 -	report[3]=0x5B; //
   1.227 -	report[4]=0x32; //
   1.228 -	report[5]=0x4A; //
   1.229 -	Write(report);
   1.230 -	}
   1.231 \ No newline at end of file