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