src/test.cpp
author sl
Thu, 22 May 2014 07:30:05 +0200
changeset 13 69f1fcfdf6a5
parent 12 7268128148b8
child 15 e5b84f315be7
permissions -rw-r--r--
Fixing crash on stratup if no Futaba VFD connected.
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@0
    32
	FXMAPFUNC(SEL_COMMAND, MainWindow::ID_RESCAN, MainWindow::onRescan ),
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@0
    93
	rescan_button = new FXButton(buttonVF, "Re-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@2
   125
	//
sl@2
   126
	iButtonClearDisplay->disable();
sl@2
   127
	iButtonDimming->disable();
sl@2
   128
	iButtonDisplayDataInput->disable();
sl@2
   129
	iButtonReadId->disable();
sl@2
   130
	iButtonReadFirmwareRevision->disable();
sl@2
   131
	iButtonPowerSupplyMonitor->disable();
sl@3
   132
    iTextFieldX->disable();
sl@3
   133
    iTextFieldY->disable();
sl@3
   134
    iButtonSetPixel->disable();
sl@4
   135
	iButtonResetPixel->disable();
sl@3
   136
    iButtonSetAllPixels->disable();
sl@2
   137
	//
sl@2
   138
sl@0
   139
	// Output Group Box
sl@3
   140
	new FXHorizontalFrame(vf);
sl@2
   141
	gb = new FXGroupBox(vf, "Output", FRAME_GROOVE|LAYOUT_FILL_X);
sl@2
   142
	matrix = new FXMatrix(gb, 3, MATRIX_BY_COLUMNS|LAYOUT_FILL_X);
sl@0
   143
	new FXLabel(matrix, "Data");
sl@0
   144
	new FXLabel(matrix, "Length");
sl@0
   145
	new FXLabel(matrix, "");
sl@0
   146
sl@0
   147
	//hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X);
sl@0
   148
	output_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
sl@0
   149
	output_text->setText("1 0x81 0");
sl@0
   150
	output_len = new FXTextField(matrix, 5, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
sl@0
   151
	output_button = new FXButton(matrix, "Send Output Report", NULL, this, ID_SEND_OUTPUT_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@0
   152
	output_button->disable();
sl@0
   153
	//new FXHorizontalFrame(matrix, LAYOUT_FILL_X);
sl@0
   154
sl@0
   155
	//hf = new FXHorizontalFrame(gb, LAYOUT_FILL_X);
sl@0
   156
	feature_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
sl@0
   157
	feature_len = new FXTextField(matrix, 5, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
sl@0
   158
	feature_button = new FXButton(matrix, "Send Feature Report", NULL, this, ID_SEND_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@0
   159
	feature_button->disable();
sl@0
   160
sl@0
   161
	get_feature_text = new FXTextField(matrix, 30, NULL, 0, TEXTFIELD_NORMAL|LAYOUT_FILL_X|LAYOUT_FILL_COLUMN);
sl@0
   162
	new FXWindow(matrix);
sl@0
   163
	get_feature_button = new FXButton(matrix, "Get Feature Report", NULL, this, ID_GET_FEATURE_REPORT, BUTTON_NORMAL|LAYOUT_FILL_X);
sl@0
   164
	get_feature_button->disable();
sl@0
   165
sl@0
   166
sl@0
   167
	// Input Group Box
sl@0
   168
	gb = new FXGroupBox(vf, "Input", FRAME_GROOVE|LAYOUT_FILL_X|LAYOUT_FILL_Y);
sl@0
   169
	FXVerticalFrame *innerVF = new FXVerticalFrame(gb, LAYOUT_FILL_X|LAYOUT_FILL_Y);
sl@0
   170
	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
   171
	input_text->setEditable(false);
sl@0
   172
	new FXButton(innerVF, "Clear", NULL, this, ID_CLEAR, BUTTON_NORMAL|LAYOUT_RIGHT);
sl@3
   173
sl@0
   174
sl@0
   175
}
sl@0
   176
sl@0
   177
MainWindow::~MainWindow()
sl@0
   178
{
sl@7
   179
    delete iCurrentFont;
sl@7
   180
    iCurrentFont = NULL;
sl@7
   181
sl@8
   182
    delete iFontImage;
sl@8
   183
    iFontImage = NULL;
sl@8
   184
sl@0
   185
	if (connected_device)
sl@0
   186
		hid_close(connected_device);
sl@0
   187
	hid_exit();
sl@0
   188
	delete title_font;
sl@0
   189
}
sl@0
   190
sl@0
   191
void
sl@0
   192
MainWindow::create()
sl@0
   193
{
sl@0
   194
	FXMainWindow::create();
sl@0
   195
	show();
sl@0
   196
sl@0
   197
	onRescan(NULL, 0, NULL);
sl@3
   198
sl@11
   199
	//Just testing our new VFD class
sl@13
   200
	if (iVfd01.Open())
sl@13
   201
        {
sl@13
   202
	    iVfd01.SetAllPixels(true);
sl@13
   203
	    iVfd01.Close();
sl@13
   204
        }
sl@0
   205
sl@0
   206
#ifdef __APPLE__
sl@0
   207
	init_apple_message_system();
sl@0
   208
#endif
sl@3
   209
sl@0
   210
	getApp()->addTimeout(this, ID_MAC_TIMER,
sl@0
   211
		50 * timeout_scalar /*50ms*/);
sl@0
   212
}
sl@0
   213
sl@0
   214
long
sl@0
   215
MainWindow::onConnect(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   216
{
sl@0
   217
	if (connected_device != NULL)
sl@0
   218
		return 1;
sl@3
   219
sl@0
   220
	FXint cur_item = device_list->getCurrentItem();
sl@0
   221
	if (cur_item < 0)
sl@0
   222
		return -1;
sl@0
   223
	FXListItem *item = device_list->getItem(cur_item);
sl@0
   224
	if (!item)
sl@0
   225
		return -1;
sl@0
   226
	struct hid_device_info *device_info = (struct hid_device_info*) item->getData();
sl@0
   227
	if (!device_info)
sl@0
   228
		return -1;
sl@3
   229
sl@0
   230
	connected_device =  hid_open_path(device_info->path);
sl@3
   231
sl@0
   232
	if (!connected_device) {
sl@0
   233
		FXMessageBox::error(this, MBOX_OK, "Device Error", "Unable To Connect to Device");
sl@0
   234
		return -1;
sl@0
   235
	}
sl@3
   236
sl@0
   237
	hid_set_nonblocking(connected_device, 1);
sl@0
   238
sl@0
   239
	getApp()->addTimeout(this, ID_TIMER,
sl@0
   240
		5 * timeout_scalar /*5ms*/);
sl@3
   241
sl@0
   242
	FXString s;
sl@0
   243
	s.format("Connected to: %04hx:%04hx -", device_info->vendor_id, device_info->product_id);
sl@0
   244
	s += FXString(" ") + device_info->manufacturer_string;
sl@0
   245
	s += FXString(" ") + device_info->product_string;
sl@0
   246
	connected_label->setText(s);
sl@0
   247
	output_button->enable();
sl@0
   248
	feature_button->enable();
sl@0
   249
	get_feature_button->enable();
sl@0
   250
	connect_button->disable();
sl@0
   251
	disconnect_button->enable();
sl@0
   252
	input_text->setText("");
sl@2
   253
	//
sl@2
   254
	iButtonClearDisplay->enable();
sl@2
   255
	iButtonDimming->enable();
sl@2
   256
	iButtonDisplayDataInput->enable();
sl@2
   257
	iButtonReadId->enable();
sl@2
   258
	iButtonReadFirmwareRevision->enable();
sl@2
   259
	iButtonPowerSupplyMonitor->enable();
sl@3
   260
    iTextFieldX->enable();
sl@3
   261
    iTextFieldY->enable();
sl@3
   262
    iButtonSetPixel->enable();
sl@4
   263
	iButtonResetPixel->enable();
sl@3
   264
    iButtonSetAllPixels->enable();
sl@3
   265
sl@2
   266
	//
sl@10
   267
	iOutputReportBuffer=new unsigned char[KFutabaMaxHidReportSize]; //TODO: use connected_device->output_report_length
sl@0
   268
sl@0
   269
	return 1;
sl@0
   270
}
sl@0
   271
sl@0
   272
long
sl@0
   273
MainWindow::onDisconnect(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   274
{
sl@0
   275
	hid_close(connected_device);
sl@0
   276
	connected_device = NULL;
sl@0
   277
	connected_label->setText("Disconnected");
sl@0
   278
	output_button->disable();
sl@0
   279
	feature_button->disable();
sl@0
   280
	get_feature_button->disable();
sl@0
   281
	connect_button->enable();
sl@0
   282
	disconnect_button->disable();
sl@0
   283
sl@0
   284
	getApp()->removeTimeout(this, ID_TIMER);
sl@2
   285
sl@2
   286
	//
sl@2
   287
	iButtonClearDisplay->disable();
sl@2
   288
	iButtonDimming->disable();
sl@2
   289
	iButtonDisplayDataInput->disable();
sl@2
   290
	iButtonReadId->disable();
sl@2
   291
	iButtonReadFirmwareRevision->disable();
sl@2
   292
	iButtonPowerSupplyMonitor->disable();
sl@3
   293
    iTextFieldX->disable();
sl@3
   294
    iTextFieldY->disable();
sl@3
   295
    iButtonSetPixel->disable();
sl@4
   296
	iButtonResetPixel->disable();
sl@3
   297
    iButtonSetAllPixels->disable();
sl@2
   298
	//
sl@2
   299
sl@2
   300
sl@2
   301
	delete iOutputReportBuffer;
sl@2
   302
	iOutputReportBuffer=NULL;
sl@3
   303
sl@0
   304
	return 1;
sl@0
   305
}
sl@0
   306
sl@0
   307
long
sl@0
   308
MainWindow::onRescan(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   309
{
sl@0
   310
	struct hid_device_info *cur_dev;
sl@0
   311
sl@0
   312
	device_list->clearItems();
sl@3
   313
sl@0
   314
	// List the Devices
sl@0
   315
	hid_free_enumeration(devices);
sl@0
   316
	devices = hid_enumerate(0x0, 0x0);
sl@3
   317
	cur_dev = devices;
sl@0
   318
	while (cur_dev) {
sl@2
   319
		// Add it to the List Box only if it is a Futaba device
sl@3
   320
		if (cur_dev->vendor_id == KFutabaVendorId)
sl@2
   321
			{
sl@2
   322
			FXString s;
sl@2
   323
			FXString usage_str;
sl@2
   324
			s.format("%04hx:%04hx -", cur_dev->vendor_id, cur_dev->product_id);
sl@2
   325
			s += FXString(" ") + cur_dev->manufacturer_string;
sl@2
   326
			s += FXString(" ") + cur_dev->product_string;
sl@2
   327
			usage_str.format(" (usage: %04hx:%04hx) ", cur_dev->usage_page, cur_dev->usage);
sl@2
   328
			s += usage_str;
sl@2
   329
			FXListItem *li = new FXListItem(s, NULL, cur_dev);
sl@2
   330
			device_list->appendItem(li);
sl@2
   331
			}
sl@3
   332
sl@0
   333
		cur_dev = cur_dev->next;
sl@0
   334
	}
sl@0
   335
sl@0
   336
	if (device_list->getNumItems() == 0)
sl@0
   337
		device_list->appendItem("*** No Devices Connected ***");
sl@0
   338
	else {
sl@0
   339
		device_list->selectItem(0);
sl@0
   340
	}
sl@0
   341
sl@0
   342
	return 1;
sl@0
   343
}
sl@0
   344
sl@0
   345
size_t
sl@0
   346
MainWindow::getDataFromTextField(FXTextField *tf, char *buf, size_t len)
sl@0
   347
{
sl@0
   348
	const char *delim = " ,{}\t\r\n";
sl@0
   349
	FXString data = tf->getText();
sl@0
   350
	const FXchar *d = data.text();
sl@0
   351
	size_t i = 0;
sl@3
   352
sl@0
   353
	// Copy the string from the GUI.
sl@0
   354
	size_t sz = strlen(d);
sl@0
   355
	char *str = (char*) malloc(sz+1);
sl@0
   356
	strcpy(str, d);
sl@3
   357
sl@0
   358
	// For each token in the string, parse and store in buf[].
sl@0
   359
	char *token = strtok(str, delim);
sl@0
   360
	while (token) {
sl@0
   361
		char *endptr;
sl@0
   362
		long int val = strtol(token, &endptr, 0);
sl@0
   363
		buf[i++] = val;
sl@0
   364
		token = strtok(NULL, delim);
sl@0
   365
	}
sl@3
   366
sl@0
   367
	free(str);
sl@0
   368
	return i;
sl@0
   369
}
sl@0
   370
sl@0
   371
/* getLengthFromTextField()
sl@0
   372
   Returns length:
sl@0
   373
	 0: empty text field
sl@0
   374
	>0: valid length
sl@0
   375
	-1: invalid length */
sl@0
   376
int
sl@0
   377
MainWindow::getLengthFromTextField(FXTextField *tf)
sl@0
   378
{
sl@0
   379
	long int len;
sl@0
   380
	FXString str = tf->getText();
sl@0
   381
	size_t sz = str.length();
sl@0
   382
sl@0
   383
	if (sz > 0) {
sl@0
   384
		char *endptr;
sl@0
   385
		len = strtol(str.text(), &endptr, 0);
sl@0
   386
		if (endptr != str.text() && *endptr == '\0') {
sl@0
   387
			if (len <= 0) {
sl@0
   388
				FXMessageBox::error(this, MBOX_OK, "Invalid length", "Enter a length greater than zero.");
sl@0
   389
				return -1;
sl@0
   390
			}
sl@0
   391
			return len;
sl@0
   392
		}
sl@0
   393
		else
sl@0
   394
			return -1;
sl@0
   395
	}
sl@0
   396
sl@0
   397
	return 0;
sl@0
   398
}
sl@0
   399
sl@0
   400
long
sl@0
   401
MainWindow::onSendOutputReport(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   402
{
sl@0
   403
	char buf[256];
sl@0
   404
	size_t data_len, len;
sl@0
   405
	int textfield_len;
sl@0
   406
sl@0
   407
	memset(buf, 0x0, sizeof(buf));
sl@0
   408
	textfield_len = getLengthFromTextField(output_len);
sl@0
   409
	data_len = getDataFromTextField(output_text, buf, sizeof(buf));
sl@0
   410
sl@0
   411
	if (textfield_len < 0) {
sl@0
   412
		FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is invalid. Please enter a number in hex, octal, or decimal.");
sl@0
   413
		return 1;
sl@0
   414
	}
sl@0
   415
sl@0
   416
	if (textfield_len > sizeof(buf)) {
sl@0
   417
		FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long.");
sl@0
   418
		return 1;
sl@0
   419
	}
sl@0
   420
sl@0
   421
	len = (textfield_len)? textfield_len: data_len;
sl@0
   422
sl@0
   423
	int res = hid_write(connected_device, (const unsigned char*)buf, len);
sl@0
   424
	if (res < 0) {
sl@0
   425
		FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not write to device. Error reported was: %ls", hid_error(connected_device));
sl@0
   426
	}
sl@3
   427
sl@0
   428
	return 1;
sl@0
   429
}
sl@0
   430
sl@0
   431
long
sl@0
   432
MainWindow::onSendFeatureReport(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   433
{
sl@0
   434
	char buf[256];
sl@0
   435
	size_t data_len, len;
sl@0
   436
	int textfield_len;
sl@0
   437
sl@0
   438
	memset(buf, 0x0, sizeof(buf));
sl@0
   439
	textfield_len = getLengthFromTextField(feature_len);
sl@0
   440
	data_len = getDataFromTextField(feature_text, buf, sizeof(buf));
sl@0
   441
sl@0
   442
	if (textfield_len < 0) {
sl@0
   443
		FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is invalid. Please enter a number in hex, octal, or decimal.");
sl@0
   444
		return 1;
sl@0
   445
	}
sl@0
   446
sl@0
   447
	if (textfield_len > sizeof(buf)) {
sl@0
   448
		FXMessageBox::error(this, MBOX_OK, "Invalid length", "Length field is too long.");
sl@0
   449
		return 1;
sl@0
   450
	}
sl@0
   451
sl@0
   452
	len = (textfield_len)? textfield_len: data_len;
sl@0
   453
sl@3
   454
	int res = hid_send_feature_report(connected_device, (const unsigned char*)buf, len);
sl@0
   455
	if (res < 0) {
sl@0
   456
		FXMessageBox::error(this, MBOX_OK, "Error Writing", "Could not send feature report to device. Error reported was: %ls", hid_error(connected_device));
sl@0
   457
	}
sl@0
   458
sl@0
   459
	return 1;
sl@0
   460
}
sl@0
   461
sl@0
   462
long
sl@0
   463
MainWindow::onGetFeatureReport(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   464
{
sl@0
   465
	char buf[256];
sl@0
   466
	size_t len;
sl@0
   467
sl@0
   468
	memset(buf, 0x0, sizeof(buf));
sl@0
   469
	len = getDataFromTextField(get_feature_text, buf, sizeof(buf));
sl@0
   470
sl@0
   471
	if (len != 1) {
sl@0
   472
		FXMessageBox::error(this, MBOX_OK, "Too many numbers", "Enter only a single report number in the text field");
sl@0
   473
	}
sl@0
   474
sl@0
   475
	int res = hid_get_feature_report(connected_device, (unsigned char*)buf, sizeof(buf));
sl@0
   476
	if (res < 0) {
sl@0
   477
		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
   478
	}
sl@0
   479
sl@0
   480
	if (res > 0) {
sl@0
   481
		FXString s;
sl@0
   482
		s.format("Returned Feature Report. %d bytes:\n", res);
sl@0
   483
		for (int i = 0; i < res; i++) {
sl@0
   484
			FXString t;
sl@0
   485
			t.format("%02hhx ", buf[i]);
sl@0
   486
			s += t;
sl@0
   487
			if ((i+1) % 4 == 0)
sl@0
   488
				s += " ";
sl@0
   489
			if ((i+1) % 16 == 0)
sl@0
   490
				s += "\n";
sl@0
   491
		}
sl@0
   492
		s += "\n";
sl@0
   493
		input_text->appendText(s);
sl@0
   494
		input_text->setBottomLine(INT_MAX);
sl@0
   495
	}
sl@3
   496
sl@0
   497
	return 1;
sl@0
   498
}
sl@0
   499
sl@0
   500
long
sl@0
   501
MainWindow::onClear(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   502
{
sl@0
   503
	input_text->setText("");
sl@0
   504
	return 1;
sl@0
   505
}
sl@0
   506
sl@2
   507
sl@2
   508
long
sl@2
   509
MainWindow::onFutabaClearDisplay(FXObject *sender, FXSelector sel, void *ptr)
sl@2
   510
{
sl@10
   511
	memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@2
   512
	iOutputReportBuffer[0]=0x00; //Report ID
sl@2
   513
	iOutputReportBuffer[1]=0x04; //Report length
sl@2
   514
	iOutputReportBuffer[2]=0x1B; //
sl@2
   515
	iOutputReportBuffer[3]=0x5B; //
sl@2
   516
	iOutputReportBuffer[4]=0x32; //
sl@2
   517
	iOutputReportBuffer[5]=0x4A; //
sl@10
   518
	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@2
   519
sl@2
   520
	return 1;
sl@2
   521
}
sl@2
   522
sl@2
   523
long
sl@2
   524
MainWindow::onFutabaDimming(FXObject *sender, FXSelector sel, void *ptr)
sl@2
   525
{
sl@10
   526
	memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@2
   527
	iOutputReportBuffer[0]=0x00; //Report ID
sl@2
   528
	iOutputReportBuffer[1]=0x06; //Report length
sl@2
   529
	iOutputReportBuffer[2]=0x1B; //
sl@2
   530
	iOutputReportBuffer[3]=0x5C; //
sl@2
   531
	iOutputReportBuffer[4]=0x3F; //
sl@2
   532
	iOutputReportBuffer[5]=0x4C; //
sl@2
   533
	iOutputReportBuffer[6]=0x44; //
sl@2
   534
	iDimming = (iDimming==0x35?0x30:++iDimming);
sl@2
   535
	iOutputReportBuffer[7]=iDimming;
sl@10
   536
	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@2
   537
sl@2
   538
	return 1;
sl@2
   539
}
sl@2
   540
sl@2
   541
long
sl@2
   542
MainWindow::onFutabaDisplayDataInput(FXObject *sender, FXSelector sel, void *ptr)
sl@2
   543
{
sl@2
   544
	//@1B 5B F0 00 00 07 00 01 FF
sl@2
   545
sl@10
   546
	memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@2
   547
	iOutputReportBuffer[0]=0x00; //Report ID
sl@2
   548
	iOutputReportBuffer[1]=0x09; //Report length
sl@2
   549
	iOutputReportBuffer[2]=0x1B; //
sl@2
   550
	iOutputReportBuffer[3]=0x5B; //
sl@2
   551
	iOutputReportBuffer[4]=0xF0; //
sl@4
   552
	iOutputReportBuffer[5]=0x00; //X
sl@4
   553
	iOutputReportBuffer[6]=0x00; //Y
sl@2
   554
	iOutputReportBuffer[7]=0x07; //
sl@2
   555
	iOutputReportBuffer[8]=0x00; //
sl@2
   556
	iOutputReportBuffer[9]=0x01; //
sl@2
   557
	iOutputReportBuffer[10]=0xFF; //
sl@10
   558
	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@2
   559
sl@3
   560
sl@2
   561
	return 1;
sl@2
   562
}
sl@2
   563
sl@5
   564
sl@5
   565
sl@5
   566
sl@4
   567
/**
sl@5
   568
Set a single pixel to the specified value.
sl@5
   569
@param X coordinate of our pixel.
sl@5
   570
@param Y coordinate of our pixel.
sl@5
   571
@param The LSB defines our pixel value.
sl@4
   572
*/
sl@4
   573
void MainWindow::SetPixel(int aX, int aY, unsigned char aValue)
sl@4
   574
	{
sl@5
   575
	//Just specify a one pixel block
sl@5
   576
	SetPixelBlock(aX,aY,0x00,0x01,aValue);
sl@5
   577
	}
sl@5
   578
sl@5
   579
/**
sl@9
   580
Set the defined pixel block to the given value.
sl@9
   581
@param X coordinate of our pixel block starting point.
sl@9
   582
@param Y coordinate of our pixel block starting point.
sl@9
   583
@param The height of our pixel block.
sl@9
   584
@param The size of our pixel data. Number of pixels divided by 8.
sl@9
   585
@param The value set to 8 pixels.
sl@5
   586
*/
sl@5
   587
void MainWindow::SetPixelBlock(int aX, int aY, int aHeight, int aSize, unsigned char aValue)
sl@5
   588
	{
sl@5
   589
	//Size must be 63 or below
sl@10
   590
	memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@4
   591
	iOutputReportBuffer[0]=0x00; //Report ID
sl@5
   592
	iOutputReportBuffer[1]=0x08+aSize; //Report length
sl@4
   593
	iOutputReportBuffer[2]=0x1B; //
sl@4
   594
	iOutputReportBuffer[3]=0x5B; //
sl@4
   595
	iOutputReportBuffer[4]=0xF0; //
sl@4
   596
	iOutputReportBuffer[5]=aX; //X
sl@4
   597
	iOutputReportBuffer[6]=aY; //Y
sl@6
   598
	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
   599
	iOutputReportBuffer[8]=0x00; //Size of pixel data in bytes (MSB)
sl@5
   600
	iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB)
sl@10
   601
	memset(iOutputReportBuffer+10, aValue, KFutabaMaxHidReportSize);
sl@5
   602
	//iOutputReportBuffer[10]=aValue; //Pixel data
sl@10
   603
	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@4
   604
	}
sl@4
   605
sl@9
   606
/**
sl@9
   607
Send an output report to a Futaba VFD device.
sl@9
   608
*/
sl@9
   609
/*
sl@9
   610
void MainWindow::SendFutabaOutputReport(unsigned char* aReportData, unsigned char aSize)
sl@9
   611
    {
sl@9
   612
    //
sl@10
   613
    memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@9
   614
    iOutputReportBuffer[0]=0x00; //Report ID is always null
sl@9
   615
    iOutputReportBuffer[1]=0x08+aSize; //Report length
sl@9
   616
    iOutputReportBuffer[2]=0x1B; //
sl@9
   617
    iOutputReportBuffer[3]=0x5B; //
sl@9
   618
    iOutputReportBuffer[4]=0xF0; //
sl@9
   619
    iOutputReportBuffer[5]=aX; //X
sl@9
   620
    iOutputReportBuffer[6]=aY; //Y
sl@9
   621
    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
   622
    iOutputReportBuffer[8]=0x00; //Size of pixel data in bytes (MSB)
sl@9
   623
    iOutputReportBuffer[9]=aSize; //Size of pixel data in bytes (LSB)
sl@10
   624
    memset(iOutputReportBuffer+10, aValue, KFutabaMaxHidReportSize);
sl@9
   625
    //iOutputReportBuffer[10]=aValue; //Pixel data
sl@10
   626
    int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@9
   627
    }
sl@9
   628
*/
sl@9
   629
sl@5
   630
sl@4
   631
/**
sl@4
   632
*/
sl@4
   633
long MainWindow::onFutabaSetPixel(FXObject *sender, FXSelector sel, void *ptr)
sl@4
   634
{
sl@4
   635
	int x=0;
sl@4
   636
	int y=0;
sl@4
   637
	iTextFieldX->getText().scan("%d",&x);
sl@4
   638
	iTextFieldY->getText().scan("%d",&y);
sl@4
   639
    SetPixel(x,y,0x01);
sl@4
   640
	return 1;
sl@4
   641
}
sl@4
   642
sl@4
   643
/**
sl@4
   644
*/
sl@4
   645
long MainWindow::onFutabaResetPixel(FXObject *sender, FXSelector sel, void *ptr)
sl@4
   646
{
sl@4
   647
	int x=0;
sl@4
   648
	int y=0;
sl@4
   649
	iTextFieldX->getText().scan("%d",&x);
sl@4
   650
	iTextFieldY->getText().scan("%d",&y);
sl@4
   651
    SetPixel(x,y,0x00);
sl@4
   652
    return 1;
sl@4
   653
}
sl@4
   654
sl@4
   655
long MainWindow::onFutabaSetAllPixels(FXObject *sender, FXSelector sel, void *ptr)
sl@4
   656
	{
sl@5
   657
	//One pixel at a time
sl@5
   658
	/*
sl@4
   659
	for (int i=0;i<256;i++)
sl@4
   660
		{
sl@4
   661
		for (int j=0;j<64;j++)
sl@4
   662
			{
sl@4
   663
			SetPixel(i,j,0x01);
sl@4
   664
			}
sl@5
   665
		}
sl@5
   666
	*/
sl@5
   667
	//16x16=256 pixels at a time goes much faster
sl@5
   668
	for (int i=0;i<256;i+=16)
sl@5
   669
		{
sl@5
   670
		for (int j=0;j<64;j+=16)
sl@5
   671
			{
sl@5
   672
			SetPixelBlock(i,j,15,32,0xFF);
sl@5
   673
			//FXThread::sleep(1000000000);
sl@5
   674
			}
sl@4
   675
		}
sl@4
   676
sl@4
   677
    return 1;
sl@4
   678
	}
sl@4
   679
sl@2
   680
long
sl@2
   681
MainWindow::onFutabaReadId(FXObject *sender, FXSelector sel, void *ptr)
sl@2
   682
{
sl@2
   683
	//1BH,5BH,63H,49H,44H
sl@10
   684
	memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@2
   685
	iOutputReportBuffer[0]=0x00; //Report ID
sl@2
   686
	iOutputReportBuffer[1]=0x05; //Report length
sl@2
   687
	iOutputReportBuffer[2]=0x1B; //
sl@2
   688
	iOutputReportBuffer[3]=0x5B; //
sl@2
   689
	iOutputReportBuffer[4]=0x63; //
sl@2
   690
	iOutputReportBuffer[5]=0x49; //
sl@2
   691
	iOutputReportBuffer[6]=0x44; //
sl@10
   692
	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@2
   693
sl@2
   694
	return 1;
sl@2
   695
}
sl@2
   696
sl@2
   697
long
sl@2
   698
MainWindow::onFutabaReadFirmwareRevision(FXObject *sender, FXSelector sel, void *ptr)
sl@2
   699
{
sl@2
   700
	//1BH,5BH,63H,46H,52H
sl@10
   701
	memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@2
   702
	iOutputReportBuffer[0]=0x00; //Report ID
sl@2
   703
	iOutputReportBuffer[1]=0x05; //Report length
sl@2
   704
	iOutputReportBuffer[2]=0x1B; //
sl@2
   705
	iOutputReportBuffer[3]=0x5B; //
sl@2
   706
	iOutputReportBuffer[4]=0x63; //
sl@2
   707
	iOutputReportBuffer[5]=0x46; //
sl@2
   708
	iOutputReportBuffer[6]=0x52; //
sl@10
   709
	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@2
   710
sl@2
   711
	return 1;
sl@2
   712
}
sl@2
   713
sl@2
   714
long
sl@2
   715
MainWindow::onFutabaPowerSupplyMonitor(FXObject *sender, FXSelector sel, void *ptr)
sl@2
   716
{
sl@2
   717
	//1BH,5BH,63H,50H,4DH
sl@10
   718
	memset(iOutputReportBuffer, 0x0, KFutabaMaxHidReportSize);
sl@2
   719
	iOutputReportBuffer[0]=0x00; //Report ID
sl@2
   720
	iOutputReportBuffer[1]=0x05; //Report length
sl@2
   721
	iOutputReportBuffer[2]=0x1B; //
sl@2
   722
	iOutputReportBuffer[3]=0x5B; //
sl@2
   723
	iOutputReportBuffer[4]=0x63; //
sl@2
   724
	iOutputReportBuffer[5]=0x50; //
sl@2
   725
	iOutputReportBuffer[6]=0x4D; //
sl@10
   726
	int res = hid_write(connected_device, iOutputReportBuffer, KFutabaMaxHidReportSize);
sl@2
   727
sl@2
   728
	return 1;
sl@2
   729
}
sl@2
   730
sl@2
   731
sl@2
   732
sl@0
   733
long
sl@0
   734
MainWindow::onTimeout(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   735
{
sl@0
   736
	unsigned char buf[256];
sl@0
   737
	int res = hid_read(connected_device, buf, sizeof(buf));
sl@3
   738
sl@0
   739
	if (res > 0) {
sl@0
   740
		FXString s;
sl@0
   741
		s.format("Received %d bytes:\n", res);
sl@0
   742
		for (int i = 0; i < res; i++) {
sl@0
   743
			FXString t;
sl@0
   744
			t.format("%02hhx ", buf[i]);
sl@0
   745
			s += t;
sl@0
   746
			if ((i+1) % 4 == 0)
sl@0
   747
				s += " ";
sl@0
   748
			if ((i+1) % 16 == 0)
sl@0
   749
				s += "\n";
sl@0
   750
		}
sl@0
   751
		s += "\n";
sl@0
   752
		input_text->appendText(s);
sl@0
   753
		input_text->setBottomLine(INT_MAX);
sl@0
   754
	}
sl@0
   755
	if (res < 0) {
sl@0
   756
		input_text->appendText("hid_read() returned error\n");
sl@0
   757
		input_text->setBottomLine(INT_MAX);
sl@0
   758
	}
sl@0
   759
sl@0
   760
	getApp()->addTimeout(this, ID_TIMER,
sl@0
   761
		5 * timeout_scalar /*5ms*/);
sl@0
   762
	return 1;
sl@0
   763
}
sl@0
   764
sl@0
   765
long
sl@0
   766
MainWindow::onMacTimeout(FXObject *sender, FXSelector sel, void *ptr)
sl@0
   767
{
sl@0
   768
#ifdef __APPLE__
sl@0
   769
	check_apple_events();
sl@3
   770
sl@0
   771
	getApp()->addTimeout(this, ID_MAC_TIMER,
sl@0
   772
		50 * timeout_scalar /*50ms*/);
sl@0
   773
#endif
sl@0
   774
sl@0
   775
	return 1;
sl@0
   776
}
sl@0
   777
sl@6
   778
/**
sl@6
   779
sl@6
   780
*/
sl@6
   781
long MainWindow::onSelectFont(FXObject *sender, FXSelector sel, void *ptr)
sl@7
   782
    {
sl@6
   783
    FXFontDialog* dlg=new FXFontDialog(this,"Pick a font");
sl@7
   784
    if (dlg->execute())
sl@7
   785
        {
sl@7
   786
        dlg->getFontSelection(iCurrentFontDesc);
sl@7
   787
        delete iCurrentFont;
sl@7
   788
        iCurrentFont = NULL;
sl@7
   789
        iCurrentFont = new FXFont(getApp(),iCurrentFontDesc);
sl@8
   790
        iCurrentFont->create();
sl@8
   791
        //
sl@8
   792
        delete iFontImage;
sl@8
   793
        iFontImage = NULL;
sl@8
   794
        //
sl@8
   795
        FXString text="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-[]{}();%$£&~#|_";
sl@8
   796
        //Create an image the proper size for our text
sl@8
   797
        iFontImage = new FXTGAImage(getApp(),NULL,IMAGE_SHMI|IMAGE_SHMP,iCurrentFont->getTextWidth(text),iCurrentFont->getFontHeight());
sl@8
   798
        iFontImage->create();
sl@8
   799
        //Perform our drawing
sl@8
   800
            {
sl@8
   801
            FXDCWindow dc(iFontImage);
sl@8
   802
            //dc.begin(iFontImage);
sl@8
   803
            dc.setFont(iCurrentFont);
sl@8
   804
            dc.setForeground(0xFFFFFFFF);
sl@8
   805
            //dc.setBackground(0xFF000000);
sl@8
   806
            //dc.setFillStyle(FILL_SOLID);
sl@8
   807
            dc.fillRectangle(0,0,iFontImage->getWidth(),iFontImage->getHeight());
sl@8
   808
            dc.setForeground(0xFF000000);
sl@8
   809
            dc.drawText(0,iCurrentFont->getFontAscent(),text);
sl@8
   810
            //dc.end();
sl@8
   811
            }
sl@8
   812
        FXFileStream file;
sl@8
   813
        file.open("fonttest.tga",FXStreamSave);
sl@8
   814
        iFontImage->restore();
sl@8
   815
        iFontImage->savePixels(file);
sl@8
   816
        file.close();
sl@8
   817
sl@8
   818
        //
sl@7
   819
sl@7
   820
        }
sl@7
   821
sl@6
   822
    delete dlg;
sl@6
   823
    return 1;
sl@7
   824
    }
sl@6
   825
sl@6
   826
sl@6
   827