src/test.cpp
author sl
Thu, 22 May 2014 09:12:31 +0200
changeset 17 63972dc16350
parent 15 e5b84f315be7
child 18 14662967f913
permissions -rw-r--r--
Adding read functionnality to our HidDevice.
Fixing some state issues upon connection.
sl@0
     1
/*******************************************************
sl@0
     2
 Demo Program for HIDAPI
sl@3
     3
sl@0
     4
 Alan Ott
sl@0
     5
 Signal 11 Software
sl@0
     6
sl@0
     7
 2010-07-20
sl@0
     8
sl@0
     9
 Copyright 2010, All Rights Reserved
sl@3
    10
sl@0
    11
 This contents of this file may be used by anyone
sl@0
    12
 for any reason without any conditions and may be
sl@0
    13
 used as a starting point for your own applications
sl@0
    14
 which use HIDAPI.
sl@0
    15
********************************************************/
sl@0
    16
sl@6
    17
#include "MainWindow.h"
sl@0
    18
sl@0
    19
sl@0
    20
// FOX 1.7 changes the timeouts to all be nanoseconds.
sl@0
    21
// Fox 1.6 had all timeouts as milliseconds.
sl@0
    22
#if (FOX_MINOR >= 7)
sl@0
    23
	const int timeout_scalar = 1000*1000;
sl@0
    24
#else
sl@0
    25
	const int timeout_scalar = 1;
sl@0
    26
#endif
sl@0
    27
sl@0
    28
sl@0
    29
FXDEFMAP(MainWindow) MainWindowMap [] = {
sl@0
    30
	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CONNECT, MainWindow::onConnect ),
sl@0
    31
	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_DISCONNECT, MainWindow::onDisconnect ),
sl@15
    32
	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_RESCAN, MainWindow::onScan ),
sl@0
    33
	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SEND_OUTPUT_REPORT, MainWindow::onSendOutputReport ),
sl@0
    34
	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SEND_FEATURE_REPORT, MainWindow::onSendFeatureReport ),
sl@0
    35
	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_GET_FEATURE_REPORT, MainWindow::onGetFeatureReport ),
sl@0
    36
	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_CLEAR, MainWindow::onClear ),
sl@2
    37
	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_CLEAR_DISPLAY, MainWindow::onFutabaClearDisplay ),
sl@2
    38
	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_DIMMING, MainWindow::onFutabaDimming ),
sl@2
    39
	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_DISPLAY_DATA_INPUT, MainWindow::onFutabaDisplayDataInput ),
sl@2
    40
	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_ID, MainWindow::onFutabaReadId ),
sl@2
    41
	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_READ_FIRMWARE_REVISION, MainWindow::onFutabaReadFirmwareRevision ),
sl@2
    42
	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_POWER_SUPPLY_MONITOR, MainWindow::onFutabaPowerSupplyMonitor ),
sl@3
    43
    FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_PIXEL, MainWindow::onFutabaSetPixel ),
sl@4
    44
	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_RESET_PIXEL, MainWindow::onFutabaResetPixel ),
sl@3
    45
    FXMAPFUNC(SEL_COMMAND, MainWindow::ID_FUTABA_SET_ALL_PIXELS, MainWindow::onFutabaSetAllPixels ),
sl@6
    46
    FXMAPFUNC(SEL_COMMAND, MainWindow::ID_SELECT_FONT, MainWindow::onSelectFont ),
sl@0
    47
	FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_TIMER, MainWindow::onTimeout ),
sl@0
    48
	FXMAPFUNC(SEL_TIMEOUT, MainWindow::ID_MAC_TIMER, MainWindow::onMacTimeout ),
sl@0
    49
};
sl@0
    50
sl@0
    51
FXIMPLEMENT(MainWindow, FXMainWindow, MainWindowMap, ARRAYNUMBER(MainWindowMap));
sl@0
    52
sl@0
    53
MainWindow::MainWindow(FXApp *app)
sl@7
    54
	: FXMainWindow(app, "HIDAPI Test Application", NULL, NULL, DECOR_ALL, 200,100, 600,900),
sl@8
    55
    iCurrentFont(NULL),
sl@8
    56
    iFontImage(NULL)
sl@0
    57
{
sl@2
    58
	iDimming=0x35;
sl@0
    59
	devices = NULL;
sl@0
    60
	connected_device = NULL;
sl@0
    61
sl@0
    62
	FXVerticalFrame *vf = new FXVerticalFrame(this, LAYOUT_FILL_Y|LAYOUT_FILL_X);
sl@0
    63
sl@0
    64
	FXLabel *label = new FXLabel(vf, "HIDAPI Test Tool");
sl@0
    65
	title_font = new FXFont(getApp(), "Arial", 14, FXFont::Bold);
sl@0
    66
	label->setFont(title_font);
sl@3
    67
sl@0
    68
	new FXLabel(vf,
sl@0
    69
		"Select a device and press Connect.", NULL, JUSTIFY_LEFT);
sl@0
    70
	new FXLabel(vf,
sl@0
    71
		"Output data bytes can be entered in the Output section, \n"
sl@0
    72
		"separated by space, comma or brackets. Data starting with 0x\n"
sl@0
    73
		"is treated as hex. Data beginning with a 0 is treated as \n"
sl@0
    74
		"octal. All other data is treated as decimal.", NULL, JUSTIFY_LEFT);
sl@0
    75
	new FXLabel(vf,
sl@0
    76
		"Data received from the device appears in the Input section.",
sl@0
    77
		NULL, JUSTIFY_LEFT);
sl@0
    78
	new FXLabel(vf,
sl@0
    79
		"Optionally, a report length may be specified. Extra bytes are\n"
sl@0
    80
		"padded with zeros. If no length is specified, the length is \n"
sl@0
    81
		"inferred from the data.",
sl@0
    82
		NULL, JUSTIFY_LEFT);
sl@0
    83
	new FXLabel(vf, "");
sl@0
    84
sl@0
    85
	// Device List and Connect/Disconnect buttons
sl@0
    86
	FXHorizontalFrame *hf = new FXHorizontalFrame(vf, LAYOUT_FILL_X);
sl@0
    87
	//device_list = new FXList(new FXHorizontalFrame(hf,FRAME_SUNKEN|FRAME_THICK, 0,0,0,0, 0,0,0,0), NULL, 0, LISTBOX_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y|LAYOUT_FIX_WIDTH|LAYOUT_FIX_HEIGHT, 0,0,300,200);
sl@0
    88
	device_list = new FXList(new FXHorizontalFrame(hf,FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,0,0, 0,0,0,0), NULL, 0, LISTBOX_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0,0,300,200);
sl@0
    89
	FXVerticalFrame *buttonVF = new FXVerticalFrame(hf);
sl@0
    90
	connect_button = new FXButton(buttonVF, "Connect", NULL, this, ID_CONNECT, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@0
    91
	disconnect_button = new FXButton(buttonVF, "Disconnect", NULL, this, ID_DISCONNECT, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@0
    92
	disconnect_button->disable();
sl@17
    93
	rescan_button = new FXButton(buttonVF, "Scan devices", NULL, this, ID_RESCAN, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@0
    94
	new FXHorizontalFrame(buttonVF, 0, 0,0,0,0, 0,0,50,0);
sl@0
    95
sl@0
    96
	connected_label = new FXLabel(vf, "Disconnected");
sl@3
    97
sl@6
    98
    //Font group
sl@6
    99
    new FXHorizontalFrame(vf);
sl@6
   100
    FXGroupBox *gb = new FXGroupBox(vf, "Fonts", FRAME_GROOVE|LAYOUT_FILL_X);
sl@6
   101
    FXMatrix *matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
sl@6
   102
    iButtonSelectFont = new FXButton(matrix, "Select Font", NULL, this, ID_SELECT_FONT, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@6
   103
sl@2
   104
	//Futaba VFD commands
sl@0
   105
	new FXHorizontalFrame(vf);
sl@6
   106
	gb = new FXGroupBox(vf, "Futaba GP1212A01A", FRAME_GROOVE|LAYOUT_FILL_X);
sl@6
   107
	matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
sl@2
   108
	iButtonClearDisplay = new FXButton(matrix, "Clear Display", NULL, this, ID_FUTABA_CLEAR_DISPLAY, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@2
   109
	iButtonDimming = new FXButton(matrix, "Dimming", NULL, this, ID_FUTABA_DIMMING, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@2
   110
	iButtonDisplayDataInput = new FXButton(matrix, "Display Data Input", NULL, this, ID_FUTABA_DISPLAY_DATA_INPUT, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@2
   111
	iButtonReadId = new FXButton(matrix, "Read Id", NULL, this, ID_FUTABA_READ_ID, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@2
   112
	iButtonReadFirmwareRevision =  new FXButton(matrix, "Read Firmware Revision", NULL, this, ID_FUTABA_READ_FIRMWARE_REVISION, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@2
   113
	iButtonPowerSupplyMonitor = new FXButton(matrix, "Power Supply Monitor", NULL, this, ID_FUTABA_POWER_SUPPLY_MONITOR, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@3
   114
    new FXLabel(matrix, "X",NULL,LABEL_NORMAL|LAYOUT_FILL_X);
sl@3
   115
    new FXLabel(matrix, "Y",NULL,LABEL_NORMAL|LAYOUT_FILL_X);
sl@3
   116
    new FXLabel(matrix, "",NULL,LABEL_NORMAL|LAYOUT_FILL_X);
sl@3
   117
    iTextFieldX = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X);
sl@3
   118
    iTextFieldY = new FXTextField(matrix, 3, NULL, 0, TEXTFIELD_NORMAL|TEXTFIELD_INTEGER|LAYOUT_FILL_X);
sl@4
   119
    iButtonSetPixel = new FXButton(matrix, "Set Pixel", NULL, this, ID_FUTABA_SET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@4
   120
	iButtonResetPixel = new FXButton(matrix, "Reset Pixel", NULL, this, ID_FUTABA_RESET_PIXEL, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@3
   121
    //
sl@3
   122
    iButtonSetAllPixels = new FXButton(matrix, "Set All Pixels", NULL, this, ID_FUTABA_SET_ALL_PIXELS, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@6
   123
    //
sl@6
   124
sl@0
   125
	// Output Group Box
sl@3
   126
	new FXHorizontalFrame(vf);
sl@2
   127
	gb = new FXGroupBox(vf, "Output", FRAME_GROOVE|LAYOUT_FILL_X);
sl@2
   128
	matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
sl@0
   129
	new FXLabel(matrix, "Data");
sl@0
   130
	new FXLabel(matrix, "Length");
sl@0
   131
	new FXLabel(matrix, "");
sl@0
   132
sl@0
   133
	//hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X);
sl@0
   134
	output_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
sl@0
   135
	output_text->setText("1 0x81 0");
sl@0
   136
	output_len = new FXTextField(matrix, 5, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
sl@0
   137
	output_button = new FXButton(matrix, "Send Output Report", NULL, this, ID_SEND_OUTPUT_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@0
   138
	output_button->disable();
sl@0
   139
	//new FXHorizontalFrame(matrix, LAYOUT_FILL_X);
sl@0
   140
sl@0
   141
	//hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X);
sl@0
   142
	feature_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
sl@0
   143
	feature_len = new FXTextField(matrix, 5, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
sl@0
   144
	feature_button = new FXButton(matrix, "Send Feature Report", NULL, this, ID_SEND_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@0
   145
	feature_button->disable();
sl@0
   146
sl@0
   147
	get_feature_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
sl@0
   148
	new FXWindow(matrix);
sl@0
   149
	get_feature_button = new FXButton(matrix, "Get Feature Report", NULL, this, ID_GET_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@0
   150
	get_feature_button->disable();
sl@0
   151
sl@0
   152
sl@0
   153
	// Input Group Box
sl@0
   154
	gb = new FXGroupBox(vf, "Input", FRAME_GROOVE|LAYOUT_FILL_X|LAYOUT_FILL_Y);
sl@0
   155
	FXVerticalFrame *innerVF = new FXVerticalFrame(gb, LAYOUT_FILL_X|LAYOUT_FILL_Y);
sl@0
   156
	input_text = new FXText(new FXHorizontalFrame(innerVF,LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN|FRAME_THICK, 0,0,0,0, 0,0,0,0), NULL, 0, LAYOUT_FILL_X|LAYOUT_FILL_Y);
sl@0
   157
	input_text->setEditable(false);
sl@0
   158
	new FXButton(innerVF, "Clear", NULL, this, ID_CLEAR, BUTTON_NORMAL|LAYOUT_RIGHT);
sl@3
   159
sl@15
   160
    SetConnectedStates();
sl@0
   161
sl@0
   162
}
sl@0
   163
sl@0
   164
MainWindow::~MainWindow()
sl@0
   165
{
sl@7
   166
    delete iCurrentFont;
sl@7
   167
    iCurrentFont = NULL;
sl@7
   168
sl@8
   169
    delete iFontImage;
sl@8
   170
    iFontImage = NULL;
sl@8
   171
sl@0
   172
	if (connected_device)
sl@0
   173
		hid_close(connected_device);
sl@0
   174
	hid_exit();
sl@0
   175
	delete title_font;
sl@0
   176
}
sl@0
   177
sl@0
   178
void
sl@0
   179
MainWindow::create()
sl@0
   180
{
sl@0
   181
	FXMainWindow::create();
sl@0
   182
	show();
sl@0
   183
sl@15
   184
	onScan(NULL, 0, NULL);
sl@3
   185
sl@15
   186
	//Try to connect to our VFD from start-up
sl@13
   187
	if (iVfd01.Open())
sl@13
   188
        {
sl@13
   189
	    iVfd01.SetAllPixels(true);
sl@13
   190
	    iVfd01.Close();
sl@15
   191
        SetConnectedStates();
sl@13
   192
        }
sl@0
   193
sl@0
   194
#ifdef __APPLE__
sl@0
   195
	init_apple_message_system();
sl@0
   196
#endif
sl@3
   197
sl@0
   198
	getApp()->addTimeout(this, ID_MAC_TIMER,
sl@0
   199
		50 * timeout_scalar /*50ms*/);
sl@0
   200
}
sl@0
   201
sl@0
   202
long
sl@0
   203
MainWindow::onConnect(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   204
{
sl@0
   205
	if (connected_device != NULL)
sl@0
   206
		return 1;
sl@3
   207
sl@0
   208
	FXint cur_item = device_list->getCurrentItem();
sl@0
   209
	if (cur_item < 0)
sl@0
   210
		return -1;
sl@0
   211
	FXListItem *item = device_list->getItem(cur_item);
sl@0
   212
	if (!item)
sl@0
   213
		return -1;
sl@0
   214
	struct hid_device_info *device_info = (struct hid_device_info*) item->getData();
sl@0
   215
	if (!device_info)
sl@0
   216
		return -1;
sl@3
   217
sl@0
   218
	connected_device =  hid_open_path(device_info->path);
sl@3
   219
sl@0
   220
	if (!connected_device) {
sl@0
   221
		FXMessageBox::error(this, MBOX_OK, "Device Error", "Unable To Connect to Device");
sl@0
   222
		return -1;
sl@0
   223
	}
sl@3
   224
sl@0
   225
	hid_set_nonblocking(connected_device, 1);
sl@0
   226
sl@2
   227
	//
sl@15
   228
	iOutputReportBuffer=new unsigned char[KFutabaMaxHidReportSize];
sl@0
   229
sl@17
   230
    SetConnectedStates();
sl@17
   231
sl@0
   232
	return 1;
sl@0
   233
}
sl@0
   234
sl@15
   235
/**
sl@15
   236
Tell whether or not we are currently connected to an HID device.
sl@15
   237
*/
sl@15
   238
bool MainWindow::IsConnected()
sl@15
   239
    {
sl@15
   240
    return (connected_device||iVfd01.IsOpen());
sl@15
   241
    }
sl@15
   242
sl@15
   243
/**
sl@15
   244
Update our UI states depending on whether or not we are connected to a device
sl@15
   245
*/
sl@15
   246
void MainWindow::SetConnectedStates()
sl@15
   247
    {
sl@15
   248
    if (IsConnected())
sl@15
   249
        {
sl@15
   250
        //Start pulling for input report
sl@15
   251
        getApp()->addTimeout(this, ID_TIMER, 5 * timeout_scalar /*5ms*/);
sl@15
   252
sl@15
   253
        FXString s;
sl@15
   254
        //s.format("Connected to: %04hx:%04hx -", device_info->vendor_id, device_info->product_id);
sl@15
   255
        s.format("Connected to: ");
sl@15
   256
        if (connected_device)
sl@15
   257
            {
sl@15
   258
            wchar_t string[256];
sl@15
   259
            hid_get_manufacturer_string(connected_device,string,sizeof(string));
sl@15
   260
            s += FXString(" ") + string;
sl@15
   261
            hid_get_product_string(connected_device,string,sizeof(string));
sl@15
   262
            s += FXString(" ") + string;
sl@15
   263
            }
sl@15
   264
        else
sl@15
   265
            {
sl@15
   266
            //TODO: Missing function on our HidDevice class
sl@15
   267
            }
sl@15
   268
        connected_label->setText(s);
sl@15
   269
        output_button->enable();
sl@15
   270
        feature_button->enable();
sl@15
   271
        get_feature_button->enable();
sl@15
   272
        connect_button->disable();
sl@15
   273
        disconnect_button->enable();
sl@15
   274
        input_text->setText("");
sl@15
   275
        //
sl@17
   276
        if (iVfd01.IsOpen())
sl@17
   277
            {
sl@17
   278
            //Those widgets are specific to our VFD
sl@17
   279
            iButtonClearDisplay->enable();
sl@17
   280
            iButtonDimming->enable();
sl@17
   281
            iButtonDisplayDataInput->enable();
sl@17
   282
            iButtonReadId->enable();
sl@17
   283
            iButtonReadFirmwareRevision->enable();
sl@17
   284
            iButtonPowerSupplyMonitor->enable();
sl@17
   285
            iTextFieldX->enable();
sl@17
   286
            iTextFieldY->enable();
sl@17
   287
            iButtonSetPixel->enable();
sl@17
   288
            iButtonResetPixel->enable();
sl@17
   289
            iButtonSetAllPixels->enable();
sl@17
   290
            }
sl@15
   291
        }
sl@15
   292
    else
sl@15
   293
        {
sl@15
   294
        //Stop pulling for input report
sl@15
   295
        getApp()->removeTimeout(this, ID_TIMER);
sl@15
   296
        //
sl@15
   297
        connected_label->setText("Disconnected");
sl@15
   298
        output_button->disable();
sl@15
   299
        feature_button->disable();
sl@15
   300
        get_feature_button->disable();
sl@15
   301
        connect_button->enable();
sl@15
   302
        disconnect_button->disable();
sl@17
   303
sl@15
   304
        iButtonClearDisplay->disable();
sl@15
   305
        iButtonDimming->disable();
sl@15
   306
        iButtonDisplayDataInput->disable();
sl@15
   307
        iButtonReadId->disable();
sl@15
   308
        iButtonReadFirmwareRevision->disable();
sl@15
   309
        iButtonPowerSupplyMonitor->disable();
sl@15
   310
        iTextFieldX->disable();
sl@15
   311
        iTextFieldY->disable();
sl@15
   312
        iButtonSetPixel->disable();
sl@15
   313
        iButtonResetPixel->disable();
sl@15
   314
        iButtonSetAllPixels->disable();
sl@15
   315
        //
sl@15
   316
        }
sl@15
   317
sl@15
   318
    }
sl@15
   319
sl@0
   320
long
sl@0
   321
MainWindow::onDisconnect(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   322
{
sl@17
   323
    //Close all our devices.
sl@17
   324
    //Closing devices which are not open won't harm.
sl@0
   325
	hid_close(connected_device);
sl@0
   326
	connected_device = NULL;
sl@15
   327
    iVfd01.Close();
sl@2
   328
sl@2
   329
	delete iOutputReportBuffer;
sl@2
   330
	iOutputReportBuffer=NULL;
sl@3
   331
sl@15
   332
    SetConnectedStates();
sl@15
   333
sl@0
   334
	return 1;
sl@0
   335
}
sl@0
   336
sl@0
   337
long
sl@15
   338
MainWindow::onScan(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   339
{
sl@0
   340
	struct hid_device_info *cur_dev;
sl@0
   341
sl@0
   342
	device_list->clearItems();
sl@3
   343
sl@0
   344
	// List the Devices
sl@0
   345
	hid_free_enumeration(devices);
sl@0
   346
	devices = hid_enumerate(0x0, 0x0);
sl@3
   347
	cur_dev = devices;
sl@0
   348
	while (cur_dev) {
sl@2
   349
		// Add it to the List Box only if it is a Futaba device
sl@17
   350
		//if (cur_dev->vendor_id == KFutabaVendorId)
sl@2
   351
			{
sl@2
   352
			FXString s;
sl@2
   353
			FXString usage_str;
sl@2
   354
			s.format("%04hx:%04hx -", cur_dev->vendor_id, cur_dev->product_id);
sl@2
   355
			s += FXString(" ") + cur_dev->manufacturer_string;
sl@2
   356
			s += FXString(" ") + cur_dev->product_string;
sl@2
   357
			usage_str.format(" (usage: %04hx:%04hx) ", cur_dev->usage_page, cur_dev->usage);
sl@2
   358
			s += usage_str;
sl@2
   359
			FXListItem *li = new FXListItem(s, NULL, cur_dev);
sl@2
   360
			device_list->appendItem(li);
sl@2
   361
			}
sl@3
   362
sl@0
   363
		cur_dev = cur_dev->next;
sl@0
   364
	}
sl@0
   365
sl@0
   366
	if (device_list->getNumItems() == 0)
sl@0
   367
		device_list->appendItem("*** No Devices Connected ***");
sl@0
   368
	else {
sl@0
   369
		device_list->selectItem(0);
sl@0
   370
	}
sl@0
   371
sl@0
   372
	return 1;
sl@0
   373
}
sl@0
   374
sl@0
   375
size_t
sl@0
   376
MainWindow::getDataFromTextField(FXTextField *tf, char *buf, size_t len)
sl@0
   377
{
sl@0
   378
	const char *delim = " ,{}\t\r\n";
sl@0
   379
	FXString data = tf->getText();
sl@0
   380
	const FXchar *d = data.text();
sl@0
   381
	size_t i = 0;
sl@3
   382
sl@0
   383
	// Copy the string from the GUI.
sl@0
   384
	size_t sz = strlen(d);
sl@0
   385
	char *str = (char*) malloc(sz+1);
sl@0
   386
	strcpy(str, d);
sl@3
   387
sl@0
   388
	// For each token in the string, parse and store in buf[].
sl@0
   389
	char *token = strtok(str, delim);
sl@0
   390
	while (token) {
sl@0
   391
		char *endptr;
sl@0
   392
		long int val = strtol(token, &endptr, 0);
sl@0
   393
		buf[i++] = val;
sl@0
   394
		token = strtok(NULL, delim);
sl@0
   395
	}
sl@3
   396
sl@0
   397
	free(str);
sl@0
   398
	return i;
sl@0
   399
}
sl@0
   400
sl@0
   401
/* getLengthFromTextField()
sl@0
   402
   Returns length:
sl@0
   403
	 0: empty text field
sl@0
   404
	>0: valid length
sl@0
   405
	-1: invalid length */
sl@0
   406
int
sl@0
   407
MainWindow::getLengthFromTextField(FXTextField *tf)
sl@0
   408
{
sl@0
   409
	long int len;
sl@0
   410
	FXString str = tf->getText();
sl@0
   411
	size_t sz = str.length();
sl@0
   412
sl@0
   413
	if (sz > 0) {
sl@0
   414
		char *endptr;
sl@0
   415
		len = strtol(str.text(), &endptr, 0);
sl@0
   416
		if (endptr != str.text() && *endptr == '\0') {
sl@0
   417
			if (len <= 0) {
sl@0
   418
				FXMessageBox::error(this, MBOX_OK, "Invalid length", "Enter a length greater than zero.");
sl@0
   419
				return -1;
sl@0
   420
			}
sl@0
   421
			return len;
sl@0
   422
		}
sl@0
   423
		else
sl@0
   424
			return -1;
sl@0
   425
	}
sl@0
   426
sl@0
   427
	return 0;
sl@0
   428
}
sl@0
   429
sl@0
   430
long
sl@0
   431
MainWindow::onSendOutputReport(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   432
{
sl@0
   433
	char buf[256];
sl@0
   434
	size_t data_len, len;
sl@0
   435
	int textfield_len;
sl@0
   436
sl@0
   437
	memset(buf, 0x0, sizeof(buf));
sl@0
   438
	textfield_len = getLengthFromTextField(output_len);
sl@0
   439
	data_len = getDataFromTextField(output_text, buf, sizeof(buf));
sl@0
   440
sl@0
   441
	if (textfield_len < 0) {
sl@0
   442
		FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is invalid. Please enter a number in hex, octal, or decimal.");
sl@0
   443
		return 1;
sl@0
   444
	}
sl@0
   445
sl@0
   446
	if (textfield_len > sizeof(buf)) {
sl@0
   447
		FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long.");
sl@0
   448
		return 1;
sl@0
   449
	}
sl@0
   450
sl@0
   451
	len = (textfield_len)? textfield_len: data_len;
sl@0
   452
sl@0
   453
	int res = hid_write(connected_device, (const unsigned char*)buf, len);
sl@0
   454
	if (res < 0) {
sl@0
   455
		FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not write to device. Error reported was: %ls", hid_error(connected_device));
sl@0
   456
	}
sl@3
   457
sl@0
   458
	return 1;
sl@0
   459
}
sl@0
   460
sl@0
   461
long
sl@0
   462
MainWindow::onSendFeatureReport(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   463
{
sl@0
   464
	char buf[256];
sl@0
   465
	size_t data_len, len;
sl@0
   466
	int textfield_len;
sl@0
   467
sl@0
   468
	memset(buf, 0x0, sizeof(buf));
sl@0
   469
	textfield_len = getLengthFromTextField(feature_len);
sl@0
   470
	data_len = getDataFromTextField(feature_text, buf, sizeof(buf));
sl@0
   471
sl@0
   472
	if (textfield_len < 0) {
sl@0
   473
		FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is invalid. Please enter a number in hex, octal, or decimal.");
sl@0
   474
		return 1;
sl@0
   475
	}
sl@0
   476
sl@0
   477
	if (textfield_len > sizeof(buf)) {
sl@0
   478
		FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long.");
sl@0
   479
		return 1;
sl@0
   480
	}
sl@0
   481
sl@0
   482
	len = (textfield_len)? textfield_len: data_len;
sl@0
   483
sl@3
   484
	int res = hid_send_feature_report(connected_device, (const unsigned char*)buf, len);
sl@0
   485
	if (res < 0) {
sl@0
   486
		FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not send feature report to device. Error reported was: %ls", hid_error(connected_device));
sl@0
   487
	}
sl@0
   488
sl@0
   489
	return 1;
sl@0
   490
}
sl@0
   491
sl@0
   492
long
sl@0
   493
MainWindow::onGetFeatureReport(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   494
{
sl@0
   495
	char buf[256];
sl@0
   496
	size_t len;
sl@0
   497
sl@0
   498
	memset(buf, 0x0, sizeof(buf));
sl@0
   499
	len = getDataFromTextField(get_feature_text, buf, sizeof(buf));
sl@0
   500
sl@0
   501
	if (len != 1) {
sl@0
   502
		FXMessageBox::error(this, MBOX_OK, "Too many numbers", "Enter only a single report number in the text field");
sl@0
   503
	}
sl@0
   504
sl@0
   505
	int res = hid_get_feature_report(connected_device, (unsigned char*)buf, sizeof(buf));
sl@0
   506
	if (res < 0) {
sl@0
   507
		FXMessageBox::error(this, MBOX_OK, "Error Getting Report", "Could not get feature report from device. Error reported was: %ls", hid_error(connected_device));
sl@0
   508
	}
sl@0
   509
sl@0
   510
	if (res > 0) {
sl@0
   511
		FXString s;
sl@0
   512
		s.format("Returned Feature Report. %d bytes:\n", res);
sl@0
   513
		for (int i = 0; i < res; i++) {
sl@0
   514
			FXString t;
sl@0
   515
			t.format("%02hhx ", buf[i]);
sl@0
   516
			s += t;
sl@0
   517
			if ((i+1) % 4 == 0)
sl@0
   518
				s += " ";
sl@0
   519
			if ((i+1) % 16 == 0)
sl@0
   520
				s += "\n";
sl@0
   521
		}
sl@0
   522
		s += "\n";
sl@0
   523
		input_text->appendText(s);
sl@0
   524
		input_text->setBottomLine(INT_MAX);
sl@0
   525
	}
sl@3
   526
sl@0
   527
	return 1;
sl@0
   528
}
sl@0
   529
sl@0
   530
long
sl@0
   531
MainWindow::onClear(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   532
{
sl@0
   533
	input_text->setText("");
sl@0
   534
	return 1;
sl@0
   535
}
sl@0
   536
sl@2
   537
sl@2
   538
long
sl@2
   539
MainWindow::onFutabaClearDisplay(FXObject *sender, FXSelector sel, void *ptr)
sl@2
   540
{
sl@10
   541
	memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@2
   542
	iOutputReportBuffer[0]=0x00; //Report ID
sl@2
   543
	iOutputReportBuffer[1]=0x04; //Report length
sl@2
   544
	iOutputReportBuffer[2]=0x1B; //
sl@2
   545
	iOutputReportBuffer[3]=0x5B; //
sl@2
   546
	iOutputReportBuffer[4]=0x32; //
sl@2
   547
	iOutputReportBuffer[5]=0x4A; //
sl@10
   548
	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@2
   549
sl@2
   550
	return 1;
sl@2
   551
}
sl@2
   552
sl@2
   553
long
sl@2
   554
MainWindow::onFutabaDimming(FXObject *sender, FXSelector sel, void *ptr)
sl@2
   555
{
sl@10
   556
	memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@2
   557
	iOutputReportBuffer[0]=0x00; //Report ID
sl@2
   558
	iOutputReportBuffer[1]=0x06; //Report length
sl@2
   559
	iOutputReportBuffer[2]=0x1B; //
sl@2
   560
	iOutputReportBuffer[3]=0x5C; //
sl@2
   561
	iOutputReportBuffer[4]=0x3F; //
sl@2
   562
	iOutputReportBuffer[5]=0x4C; //
sl@2
   563
	iOutputReportBuffer[6]=0x44; //
sl@2
   564
	iDimming = (iDimming==0x35?0x30:++iDimming);
sl@2
   565
	iOutputReportBuffer[7]=iDimming;
sl@10
   566
	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@2
   567
sl@2
   568
	return 1;
sl@2
   569
}
sl@2
   570
sl@2
   571
long
sl@2
   572
MainWindow::onFutabaDisplayDataInput(FXObject *sender, FXSelector sel, void *ptr)
sl@2
   573
{
sl@2
   574
	//@1B 5B F0 00 00 07 00 01 FF
sl@2
   575
sl@10
   576
	memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@2
   577
	iOutputReportBuffer[0]=0x00; //Report ID
sl@2
   578
	iOutputReportBuffer[1]=0x09; //Report length
sl@2
   579
	iOutputReportBuffer[2]=0x1B; //
sl@2
   580
	iOutputReportBuffer[3]=0x5B; //
sl@2
   581
	iOutputReportBuffer[4]=0xF0; //
sl@4
   582
	iOutputReportBuffer[5]=0x00; //X
sl@4
   583
	iOutputReportBuffer[6]=0x00; //Y
sl@2
   584
	iOutputReportBuffer[7]=0x07; //
sl@2
   585
	iOutputReportBuffer[8]=0x00; //
sl@2
   586
	iOutputReportBuffer[9]=0x01; //
sl@2
   587
	iOutputReportBuffer[10]=0xFF; //
sl@10
   588
	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@2
   589
sl@3
   590
sl@2
   591
	return 1;
sl@2
   592
}
sl@2
   593
sl@5
   594
sl@5
   595
sl@5
   596
sl@4
   597
/**
sl@5
   598
Set a single pixel to the specified value.
sl@5
   599
@param X coordinate of our pixel.
sl@5
   600
@param Y coordinate of our pixel.
sl@5
   601
@param The LSB defines our pixel value.
sl@4
   602
*/
sl@4
   603
void MainWindow::SetPixel(int aX, int aY, unsigned char aValue)
sl@4
   604
	{
sl@5
   605
	//Just specify a one pixel block
sl@5
   606
	SetPixelBlock(aX,aY,0x00,0x01,aValue);
sl@5
   607
	}
sl@5
   608
sl@5
   609
/**
sl@9
   610
Set the defined pixel block to the given value.
sl@9
   611
@param X coordinate of our pixel block starting point.
sl@9
   612
@param Y coordinate of our pixel block starting point.
sl@9
   613
@param The height of our pixel block.
sl@9
   614
@param The size of our pixel data. Number of pixels divided by 8.
sl@9
   615
@param The value set to 8 pixels.
sl@5
   616
*/
sl@5
   617
void MainWindow::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue)
sl@5
   618
	{
sl@5
   619
	//Size must be 63 or below
sl@10
   620
	memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@4
   621
	iOutputReportBuffer[0]=0x00; //Report ID
sl@5
   622
	iOutputReportBuffer[1]=0x08+aSize; //Report length
sl@4
   623
	iOutputReportBuffer[2]=0x1B; //
sl@4
   624
	iOutputReportBuffer[3]=0x5B; //
sl@4
   625
	iOutputReportBuffer[4]=0xF0; //
sl@4
   626
	iOutputReportBuffer[5]=aX; //X
sl@4
   627
	iOutputReportBuffer[6]=aY; //Y
sl@6
   628
	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.
sl@4
   629
	iOutputReportBuffer[8]=0x00; //Size of pixel data in bytes (MSB)
sl@5
   630
	iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB)
sl@10
   631
	memset(iOutputReportBuffer+10, aValue, KFutabaMaxHidReportSize);
sl@5
   632
	//iOutputReportBuffer[10]=aValue; //Pixel data
sl@10
   633
	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@4
   634
	}
sl@4
   635
sl@9
   636
/**
sl@9
   637
Send an output report to a Futaba VFD device.
sl@9
   638
*/
sl@9
   639
/*
sl@9
   640
void MainWindow::SendFutabaOutputReport(unsigned char* aReportData, unsigned char aSize)
sl@9
   641
    {
sl@9
   642
    //
sl@10
   643
    memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@9
   644
    iOutputReportBuffer[0]=0x00; //Report ID is always null
sl@9
   645
    iOutputReportBuffer[1]=0x08+aSize; //Report length
sl@9
   646
    iOutputReportBuffer[2]=0x1B; //
sl@9
   647
    iOutputReportBuffer[3]=0x5B; //
sl@9
   648
    iOutputReportBuffer[4]=0xF0; //
sl@9
   649
    iOutputReportBuffer[5]=aX; //X
sl@9
   650
    iOutputReportBuffer[6]=aY; //Y
sl@9
   651
    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.
sl@9
   652
    iOutputReportBuffer[8]=0x00; //Size of pixel data in bytes (MSB)
sl@9
   653
    iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB)
sl@10
   654
    memset(iOutputReportBuffer+10, aValue, KFutabaMaxHidReportSize);
sl@9
   655
    //iOutputReportBuffer[10]=aValue; //Pixel data
sl@10
   656
    int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@9
   657
    }
sl@9
   658
*/
sl@9
   659
sl@5
   660
sl@4
   661
/**
sl@4
   662
*/
sl@4
   663
long MainWindow::onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr)
sl@4
   664
{
sl@4
   665
	int x=0;
sl@4
   666
	int y=0;
sl@4
   667
	iTextFieldX->getText().scan("%d",&x);
sl@4
   668
	iTextFieldY->getText().scan("%d",&y);
sl@4
   669
    SetPixel(x,y,0x01);
sl@4
   670
	return 1;
sl@4
   671
}
sl@4
   672
sl@4
   673
/**
sl@4
   674
*/
sl@4
   675
long MainWindow::onFutabaResetPixel(FXObject *sender, FXSelector sel, void *ptr)
sl@4
   676
{
sl@4
   677
	int x=0;
sl@4
   678
	int y=0;
sl@4
   679
	iTextFieldX->getText().scan("%d",&x);
sl@4
   680
	iTextFieldY->getText().scan("%d",&y);
sl@4
   681
    SetPixel(x,y,0x00);
sl@4
   682
    return 1;
sl@4
   683
}
sl@4
   684
sl@4
   685
long MainWindow::onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr)
sl@4
   686
	{
sl@5
   687
	//One pixel at a time
sl@5
   688
	/*
sl@4
   689
	for (int i=0;i<256;i++)
sl@4
   690
		{
sl@4
   691
		for (int j=0;j<64;j++)
sl@4
   692
			{
sl@4
   693
			SetPixel(i,j,0x01);
sl@4
   694
			}
sl@5
   695
		}
sl@5
   696
	*/
sl@5
   697
	//16x16=256 pixels at a time goes much faster
sl@5
   698
	for (int i=0;i<256;i+=16)
sl@5
   699
		{
sl@5
   700
		for (int j=0;j<64;j+=16)
sl@5
   701
			{
sl@5
   702
			SetPixelBlock(i,j,15,32,0xFF);
sl@5
   703
			//FXThread::sleep(1000000000);
sl@5
   704
			}
sl@4
   705
		}
sl@4
   706
sl@4
   707
    return 1;
sl@4
   708
	}
sl@4
   709
sl@2
   710
long
sl@2
   711
MainWindow::onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr)
sl@2
   712
{
sl@2
   713
	//1BH,5BH,63H,49H,44H
sl@10
   714
	memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@2
   715
	iOutputReportBuffer[0]=0x00; //Report ID
sl@2
   716
	iOutputReportBuffer[1]=0x05; //Report length
sl@2
   717
	iOutputReportBuffer[2]=0x1B; //
sl@2
   718
	iOutputReportBuffer[3]=0x5B; //
sl@2
   719
	iOutputReportBuffer[4]=0x63; //
sl@2
   720
	iOutputReportBuffer[5]=0x49; //
sl@2
   721
	iOutputReportBuffer[6]=0x44; //
sl@10
   722
	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@2
   723
sl@2
   724
	return 1;
sl@2
   725
}
sl@2
   726
sl@2
   727
long
sl@2
   728
MainWindow::onFutabaReadFirmwareRevision(FXObject *sender, FXSelector sel, void *ptr)
sl@2
   729
{
sl@2
   730
	//1BH,5BH,63H,46H,52H
sl@10
   731
	memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@2
   732
	iOutputReportBuffer[0]=0x00; //Report ID
sl@2
   733
	iOutputReportBuffer[1]=0x05; //Report length
sl@2
   734
	iOutputReportBuffer[2]=0x1B; //
sl@2
   735
	iOutputReportBuffer[3]=0x5B; //
sl@2
   736
	iOutputReportBuffer[4]=0x63; //
sl@2
   737
	iOutputReportBuffer[5]=0x46; //
sl@2
   738
	iOutputReportBuffer[6]=0x52; //
sl@10
   739
	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@2
   740
sl@2
   741
	return 1;
sl@2
   742
}
sl@2
   743
sl@2
   744
long
sl@2
   745
MainWindow::onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr)
sl@2
   746
{
sl@2
   747
	//1BH,5BH,63H,50H,4DH
sl@10
   748
	memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@2
   749
	iOutputReportBuffer[0]=0x00; //Report ID
sl@2
   750
	iOutputReportBuffer[1]=0x05; //Report length
sl@2
   751
	iOutputReportBuffer[2]=0x1B; //
sl@2
   752
	iOutputReportBuffer[3]=0x5B; //
sl@2
   753
	iOutputReportBuffer[4]=0x63; //
sl@2
   754
	iOutputReportBuffer[5]=0x50; //
sl@2
   755
	iOutputReportBuffer[6]=0x4D; //
sl@10
   756
	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@2
   757
sl@2
   758
	return 1;
sl@2
   759
}
sl@2
   760
sl@2
   761
sl@2
   762
sl@0
   763
long
sl@0
   764
MainWindow::onTimeout(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   765
{
sl@17
   766
    FutabaVfdReport report;
sl@17
   767
	unsigned char buffer[256];
sl@17
   768
    unsigned char* buf=NULL;
sl@17
   769
    int res = 0;
sl@17
   770
sl@17
   771
    //Use either our display or our generic device depending which one is connected
sl@17
   772
    if (connected_device)
sl@17
   773
        {
sl@17
   774
	    res = hid_read(connected_device, buffer, sizeof(buffer));
sl@17
   775
        buf=buffer;
sl@17
   776
        }
sl@17
   777
    else
sl@17
   778
        {
sl@17
   779
        res=iVfd01.Read(report);
sl@17
   780
        buf=report.Buffer();
sl@17
   781
        }
sl@3
   782
sl@0
   783
	if (res > 0) {
sl@0
   784
		FXString s;
sl@0
   785
		s.format("Received %d bytes:\n", res);
sl@0
   786
		for (int i = 0; i < res; i++) {
sl@0
   787
			FXString t;
sl@0
   788
			t.format("%02hhx ", buf[i]);
sl@0
   789
			s += t;
sl@0
   790
			if ((i+1) % 4 == 0)
sl@0
   791
				s += " ";
sl@0
   792
			if ((i+1) % 16 == 0)
sl@0
   793
				s += "\n";
sl@0
   794
		}
sl@0
   795
		s += "\n";
sl@0
   796
		input_text->appendText(s);
sl@0
   797
		input_text->setBottomLine(INT_MAX);
sl@0
   798
	}
sl@0
   799
	if (res < 0) {
sl@0
   800
		input_text->appendText("hid_read() returned error\n");
sl@0
   801
		input_text->setBottomLine(INT_MAX);
sl@0
   802
	}
sl@0
   803
sl@17
   804
    //Keep on reading
sl@0
   805
	getApp()->addTimeout(this, ID_TIMER,
sl@0
   806
		5 * timeout_scalar /*5ms*/);
sl@0
   807
	return 1;
sl@0
   808
}
sl@0
   809
sl@0
   810
long
sl@0
   811
MainWindow::onMacTimeout(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   812
{
sl@0
   813
#ifdef __APPLE__
sl@0
   814
	check_apple_events();
sl@3
   815
sl@0
   816
	getApp()->addTimeout(this, ID_MAC_TIMER,
sl@0
   817
		50 * timeout_scalar /*50ms*/);
sl@0
   818
#endif
sl@0
   819
sl@0
   820
	return 1;
sl@0
   821
}
sl@0
   822
sl@6
   823
/**
sl@6
   824
sl@6
   825
*/
sl@6
   826
long MainWindow::onSelectFont(FXObject *sender, FXSelector sel, void *ptr)
sl@7
   827
    {
sl@6
   828
    FXFontDialog* dlg=new FXFontDialog(this,"Pick a font");
sl@7
   829
    if (dlg->execute())
sl@7
   830
        {
sl@7
   831
        dlg->getFontSelection(iCurrentFontDesc);
sl@7
   832
        delete iCurrentFont;
sl@7
   833
        iCurrentFont = NULL;
sl@7
   834
        iCurrentFont = new FXFont(getApp(),iCurrentFontDesc);
sl@8
   835
        iCurrentFont->create();
sl@8
   836
        //
sl@8
   837
        delete iFontImage;
sl@8
   838
        iFontImage = NULL;
sl@8
   839
        //
sl@8
   840
        FXString text="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-[]{}();%$£&~#|_";
sl@8
   841
        //Create an image the proper size for our text
sl@8
   842
        iFontImage = new FXTGAImage(getApp(),NULL,IMAGE_SHMI|IMAGE_SHMP,iCurrentFont->getTextWidth(text),iCurrentFont->getFontHeight());
sl@8
   843
        iFontImage->create();
sl@8
   844
        //Perform our drawing
sl@8
   845
            {
sl@8
   846
            FXDCWindow dc(iFontImage);
sl@8
   847
            //dc.begin(iFontImage);
sl@8
   848
            dc.setFont(iCurrentFont);
sl@8
   849
            dc.setForeground(0xFFFFFFFF);
sl@8
   850
            //dc.setBackground(0xFF000000);
sl@8
   851
            //dc.setFillStyle(FILL_SOLID);
sl@8
   852
            dc.fillRectangle(0,0,iFontImage->getWidth(),iFontImage->getHeight());
sl@8
   853
            dc.setForeground(0xFF000000);
sl@8
   854
            dc.drawText(0,iCurrentFont->getFontAscent(),text);
sl@8
   855
            //dc.end();
sl@8
   856
            }
sl@8
   857
        FXFileStream file;
sl@8
   858
        file.open("fonttest.tga",FXStreamSave);
sl@8
   859
        iFontImage->restore();
sl@8
   860
        iFontImage->savePixels(file);
sl@8
   861
        file.close();
sl@8
   862
sl@8
   863
        //
sl@7
   864
sl@7
   865
        }
sl@7
   866
sl@6
   867
    delete dlg;
sl@6
   868
    return 1;
sl@7
   869
    }
sl@6
   870
sl@6
   871
sl@6
   872