# HG changeset patch # User sl # Date 1400602402 -7200 # Node ID 50a4b94dafe68252721e0b7168eb3b846e70c206 # Parent d57fa1211bb054a5ec412c5ec4977b64108fb5f9 Adding button to reset a defined pixel. Slow implementation for setting all pixels. diff -r d57fa1211bb0 -r 50a4b94dafe6 test.cpp --- a/test.cpp Tue May 20 17:04:50 2014 +0200 +++ b/test.cpp Tue May 20 18:13:22 2014 +0200 @@ -52,6 +52,7 @@ ID_FUTABA_READ_FIRMWARE_REVISION, ID_FUTABA_POWER_SUPPLY_MONITOR, ID_FUTABA_SET_PIXEL, + ID_FUTABA_RESET_PIXEL, ID_FUTABA_SET_ALL_PIXELS, ID_LAST, }; @@ -82,6 +83,7 @@ FXTextField *iTextFieldX; FXTextField *iTextFieldY; FXButton *iButtonSetPixel; + FXButton *iButtonResetPixel; FXButton *iButtonSetAllPixels; @@ -122,10 +124,14 @@ long onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr); long onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr); long onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr); + long onFutabaResetPixel(FXObject *sender, FXSelector sel, void *ptr); // - + // long onTimeout(FXObject *sender, FXSelector sel, void *ptr); long onMacTimeout(FXObject *sender, FXSelector sel, void *ptr); + // + void SetPixel(int aX, int aY, unsigned char aValue); + }; // FOX 1.7 changes the timeouts to all be nanoseconds. @@ -154,6 +160,7 @@ FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_FIRMWARE_REVISION, MainWindow::onFutabaReadFirmwareRevision ), FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_POWER_SUPPLY_MONITOR, MainWindow::onFutabaPowerSupplyMonitor ), FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_PIXEL, MainWindow::onFutabaSetPixel ), + FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_RESET_PIXEL, MainWindow::onFutabaResetPixel ), FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_ALL_PIXELS, MainWindow::onFutabaSetAllPixels ), FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_TIMER, MainWindow::onTimeout ), FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_MAC_TIMER, MainWindow::onMacTimeout ), @@ -219,7 +226,8 @@ new FXLabel(matrix, "",NULL,LABEL_NORMAL|LAYOUT_FILL_X); iTextFieldX = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X); iTextFieldY = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X); - iButtonSetPixel = new FXButton(matrix, "SetPixel", NULL, this, ID_FUTABA_SET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X); + iButtonSetPixel = new FXButton(matrix, "Set Pixel", NULL, this, ID_FUTABA_SET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X); + iButtonResetPixel = new FXButton(matrix, "Reset Pixel", NULL, this, ID_FUTABA_RESET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X); // iButtonSetAllPixels = new FXButton(matrix, "Set All Pixels", NULL, this, ID_FUTABA_SET_ALL_PIXELS, BUTTON_NORMAL|LAYOUT_FILL_X); // @@ -232,6 +240,7 @@ iTextFieldX->disable(); iTextFieldY->disable(); iButtonSetPixel->disable(); + iButtonResetPixel->disable(); iButtonSetAllPixels->disable(); // @@ -347,6 +356,7 @@ iTextFieldX->enable(); iTextFieldY->enable(); iButtonSetPixel->enable(); + iButtonResetPixel->enable(); iButtonSetAllPixels->enable(); // @@ -379,6 +389,7 @@ iTextFieldX->disable(); iTextFieldY->disable(); iButtonSetPixel->disable(); + iButtonResetPixel->disable(); iButtonSetAllPixels->disable(); // @@ -637,8 +648,8 @@ iOutputReportBuffer[2]=0x1B; // iOutputReportBuffer[3]=0x5B; // iOutputReportBuffer[4]=0xF0; // - iOutputReportBuffer[5]=0x00; // - iOutputReportBuffer[6]=0x00; // + iOutputReportBuffer[5]=0x00; //X + iOutputReportBuffer[6]=0x00; //Y iOutputReportBuffer[7]=0x07; // iOutputReportBuffer[8]=0x00; // iOutputReportBuffer[9]=0x01; // @@ -649,6 +660,63 @@ return 1; } +/** +*/ +void MainWindow::SetPixel(int aX, int aY, unsigned char aValue) + { + memset(iOutputReportBuffer, 0x0, KFutabaOutputReportLength); + iOutputReportBuffer[0]=0x00; //Report ID + iOutputReportBuffer[1]=0x09; //Report length + iOutputReportBuffer[2]=0x1B; // + iOutputReportBuffer[3]=0x5B; // + iOutputReportBuffer[4]=0xF0; // + iOutputReportBuffer[5]=aX; //X + iOutputReportBuffer[6]=aY; //Y + 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. + iOutputReportBuffer[8]=0x00; //Size of pixel data in bytes (MSB) + iOutputReportBuffer[9]=0x01; //Size of pixel data in bytes (LSB) + iOutputReportBuffer[10]=aValue; //Pixel data + int res = hid_write(connected_device, iOutputReportBuffer, KFutabaOutputReportLength); + } + +/** +*/ +long MainWindow::onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr) +{ + int x=0; + int y=0; + iTextFieldX->getText().scan("%d",&x); + iTextFieldY->getText().scan("%d",&y); + SetPixel(x,y,0x01); + return 1; +} + +/** +*/ +long MainWindow::onFutabaResetPixel(FXObject *sender, FXSelector sel, void *ptr) +{ + int x=0; + int y=0; + iTextFieldX->getText().scan("%d",&x); + iTextFieldY->getText().scan("%d",&y); + SetPixel(x,y,0x00); + return 1; +} + +long MainWindow::onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr) + { + for (int i=0;i<256;i++) + { + for (int j=0;j<64;j++) + { + SetPixel(i,j,0x01); + } + + } + + return 1; + } + long MainWindow::onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr) { @@ -700,17 +768,6 @@ return 1; } -long MainWindow::onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr) -{ - return 1; - -} - - -long MainWindow::onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr) -{ - return 1; -} long