Adding button to reset a defined pixel.
authorsl
Tue, 20 May 2014 18:13:22 +0200
changeset 450a4b94dafe6
parent 3 d57fa1211bb0
child 5 4cb67272815c
Adding button to reset a defined pixel.
Slow implementation for setting all pixels.
test.cpp
     1.1 --- a/test.cpp	Tue May 20 17:04:50 2014 +0200
     1.2 +++ b/test.cpp	Tue May 20 18:13:22 2014 +0200
     1.3 @@ -52,6 +52,7 @@
     1.4  		ID_FUTABA_READ_FIRMWARE_REVISION,
     1.5  		ID_FUTABA_POWER_SUPPLY_MONITOR,
     1.6          ID_FUTABA_SET_PIXEL,
     1.7 +		ID_FUTABA_RESET_PIXEL,
     1.8          ID_FUTABA_SET_ALL_PIXELS,
     1.9  		ID_LAST,
    1.10  	};
    1.11 @@ -82,6 +83,7 @@
    1.12      FXTextField *iTextFieldX;
    1.13      FXTextField *iTextFieldY;
    1.14      FXButton *iButtonSetPixel;
    1.15 +	FXButton *iButtonResetPixel;
    1.16      FXButton *iButtonSetAllPixels;
    1.17  
    1.18  
    1.19 @@ -122,10 +124,14 @@
    1.20  	long onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr);
    1.21      long onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr);
    1.22      long onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr);
    1.23 +	long onFutabaResetPixel(FXObject *sender, FXSelector sel, void *ptr);
    1.24  	//
    1.25 -
    1.26 +	//
    1.27  	long onTimeout(FXObject *sender, FXSelector sel, void *ptr);
    1.28  	long onMacTimeout(FXObject *sender, FXSelector sel, void *ptr);
    1.29 +	//
    1.30 +	void SetPixel(int aX, int aY, unsigned char aValue);
    1.31 +
    1.32  };
    1.33  
    1.34  // FOX 1.7 changes the timeouts to all be nanoseconds.
    1.35 @@ -154,6 +160,7 @@
    1.36  	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_FIRMWARE_REVISION, MainWindow::onFutabaReadFirmwareRevision ),
    1.37  	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_POWER_SUPPLY_MONITOR, MainWindow::onFutabaPowerSupplyMonitor ),
    1.38      FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_PIXEL, MainWindow::onFutabaSetPixel ),
    1.39 +	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_RESET_PIXEL, MainWindow::onFutabaResetPixel ),
    1.40      FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_ALL_PIXELS, MainWindow::onFutabaSetAllPixels ),
    1.41  	FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_TIMER, MainWindow::onTimeout ),
    1.42  	FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_MAC_TIMER, MainWindow::onMacTimeout ),
    1.43 @@ -219,7 +226,8 @@
    1.44      new FXLabel(matrix, "",NULL,LABEL_NORMAL|LAYOUT_FILL_X);
    1.45      iTextFieldX = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X);
    1.46      iTextFieldY = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X);
    1.47 -    iButtonSetPixel = new FXButton(matrix, "SetPixel", NULL, this, ID_FUTABA_SET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X);
    1.48 +    iButtonSetPixel = new FXButton(matrix, "Set Pixel", NULL, this, ID_FUTABA_SET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X);
    1.49 +	iButtonResetPixel = new FXButton(matrix, "Reset Pixel", NULL, this, ID_FUTABA_RESET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X);
    1.50      //
    1.51      iButtonSetAllPixels = new FXButton(matrix, "Set All Pixels", NULL, this, ID_FUTABA_SET_ALL_PIXELS, BUTTON_NORMAL|LAYOUT_FILL_X);
    1.52  	//
    1.53 @@ -232,6 +240,7 @@
    1.54      iTextFieldX->disable();
    1.55      iTextFieldY->disable();
    1.56      iButtonSetPixel->disable();
    1.57 +	iButtonResetPixel->disable();
    1.58      iButtonSetAllPixels->disable();
    1.59  	//
    1.60  
    1.61 @@ -347,6 +356,7 @@
    1.62      iTextFieldX->enable();
    1.63      iTextFieldY->enable();
    1.64      iButtonSetPixel->enable();
    1.65 +	iButtonResetPixel->enable();
    1.66      iButtonSetAllPixels->enable();
    1.67  
    1.68  	//
    1.69 @@ -379,6 +389,7 @@
    1.70      iTextFieldX->disable();
    1.71      iTextFieldY->disable();
    1.72      iButtonSetPixel->disable();
    1.73 +	iButtonResetPixel->disable();
    1.74      iButtonSetAllPixels->disable();
    1.75  	//
    1.76  
    1.77 @@ -637,8 +648,8 @@
    1.78  	iOutputReportBuffer[2]=0x1B; //
    1.79  	iOutputReportBuffer[3]=0x5B; //
    1.80  	iOutputReportBuffer[4]=0xF0; //
    1.81 -	iOutputReportBuffer[5]=0x00; //
    1.82 -	iOutputReportBuffer[6]=0x00; //
    1.83 +	iOutputReportBuffer[5]=0x00; //X
    1.84 +	iOutputReportBuffer[6]=0x00; //Y
    1.85  	iOutputReportBuffer[7]=0x07; //
    1.86  	iOutputReportBuffer[8]=0x00; //
    1.87  	iOutputReportBuffer[9]=0x01; //
    1.88 @@ -649,6 +660,63 @@
    1.89  	return 1;
    1.90  }
    1.91  
    1.92 +/**
    1.93 +*/
    1.94 +void MainWindow::SetPixel(int aX, int aY, unsigned char aValue)
    1.95 +	{
    1.96 +	memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength);
    1.97 +	iOutputReportBuffer[0]=0x00; //Report ID
    1.98 +	iOutputReportBuffer[1]=0x09; //Report length
    1.99 +	iOutputReportBuffer[2]=0x1B; //
   1.100 +	iOutputReportBuffer[3]=0x5B; //
   1.101 +	iOutputReportBuffer[4]=0xF0; //
   1.102 +	iOutputReportBuffer[5]=aX; //X
   1.103 +	iOutputReportBuffer[6]=aY; //Y
   1.104 +	iOutputReportBuffer[7]=0x00; //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.105 +	iOutputReportBuffer[8]=0x00; //Size of pixel data in bytes (MSB)
   1.106 +	iOutputReportBuffer[9]=0x01; //Size of pixel data in bytes (LSB) 
   1.107 +	iOutputReportBuffer[10]=aValue; //Pixel data
   1.108 +	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength);
   1.109 +	}
   1.110 +
   1.111 +/**
   1.112 +*/
   1.113 +long MainWindow::onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr)
   1.114 +{
   1.115 +	int x=0;
   1.116 +	int y=0;
   1.117 +	iTextFieldX->getText().scan("%d",&x);
   1.118 +	iTextFieldY->getText().scan("%d",&y);
   1.119 +    SetPixel(x,y,0x01);
   1.120 +	return 1;
   1.121 +}
   1.122 +
   1.123 +/**
   1.124 +*/
   1.125 +long MainWindow::onFutabaResetPixel(FXObject *sender, FXSelector sel, void *ptr)
   1.126 +{
   1.127 +	int x=0;
   1.128 +	int y=0;
   1.129 +	iTextFieldX->getText().scan("%d",&x);
   1.130 +	iTextFieldY->getText().scan("%d",&y);
   1.131 +    SetPixel(x,y,0x00);
   1.132 +    return 1;
   1.133 +}
   1.134 +
   1.135 +long MainWindow::onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr)
   1.136 +	{
   1.137 +	for (int i=0;i<256;i++)
   1.138 +		{
   1.139 +		for (int j=0;j<64;j++)
   1.140 +			{
   1.141 +			SetPixel(i,j,0x01);
   1.142 +			}
   1.143 +
   1.144 +		}
   1.145 +
   1.146 +    return 1;
   1.147 +	}
   1.148 +
   1.149  long
   1.150  MainWindow::onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr)
   1.151  {
   1.152 @@ -700,17 +768,6 @@
   1.153  	return 1;
   1.154  }
   1.155  
   1.156 -long MainWindow::onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr)
   1.157 -{
   1.158 -    return 1;
   1.159 -
   1.160 -}
   1.161 -
   1.162 -
   1.163 -long MainWindow::onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr)
   1.164 -{
   1.165 -    return 1;
   1.166 -}
   1.167  
   1.168  
   1.169  long