libmoglk libMoGlk
A library to drive Matrix Orbital's GLK graphic LCD

Browse the code

Differences between 37 and 38 on /.
Number of edited files: 2 (0 added, 0 deleted and 2 modified)
Author: ematech
Log message: Indentation cleanup, no code change
Date: 2010-07-08 20:10:25

Added file(s) Deleted file(s) Modified file(s)

 

Old New Code
16 16

                                        
17 17
 You should have received a copy of the GNU General Public License
18 18
 along with libmoglk. If not, see <http://www.gnu.org/licenses/>.
19  
 */
  19
*/
20 20

                                        
21 21
// C headers
22 22
#include <termios.h>	// POSIX Terminal IOs
23  
#include <fcntl.h>	// POSIX File Control Operations
  23
#include <fcntl.h>		// POSIX File Control Operations
24 24

                                        
25 25
// C++ headers
26  
#include <cstring>      // ISO C99 String handling
27  
#include <cstdio>	// C++ standard IO
28  
#include <iostream>     // C++ input output stream
29  
#include <sstream>      // C++ string stream
  26
#include <cstring>		// ISO C99 String handling
  27
#include <cstdio>		// C++ standard IO
  28
#include <iostream>		// C++ input output stream
  29
#include <sstream>		// C++ string stream
30 30

                                        
31 31
// libmoglk header
32 32
#include "moglk.h"
33 33

                                        
34 34
//#define NDEBUG
35 35

                                        
36  
//Namespaces
  36
// Namespaces
37 37
using namespace std;
38 38

                                        
39 39
int serial_port;
44 44

                                        
45 45
Moglk::~Moglk()
46 46
{
47  
        close(serial_port);
  47
	close(serial_port);
48 48
}
49 49

                                        
50 50
//TODO: Autodetect device
53 53
                 unsigned long int baud_rate)
54 54
{
55 55

                                        
56  
    if (!baud_rate)
57  
    {
58  
        baud_rate = autodetectBaudRate(device_ptr);
59  
    }
  56
	if (!baud_rate)
  57
	{
  58
		baud_rate = autodetectBaudRate(device_ptr);
  59
	}
60 60

                                        
61  
    if(!openPort(device_ptr))
62  
    {
63  
        configurePort();
64  
        setPortBaudRate(baud_rate);
  61
	if(!openPort(device_ptr))
  62
	{
  63
		configurePort();
  64
		setPortBaudRate(baud_rate);
65 65
/*
66  
        setFlowControl(1,
67  
                       8,
68  
                       119);
  66
		setFlowControl(1,
  67
		               8,
  68
		               119);
69 69
*/
70 70

                                        
71 71
#ifndef NDEBUG
72  
        cout << "DEBUG init(): libmoglk initialized!" << endl;
  72
	cout &lt;< "DEBUG init(): libmoglk initialized!" << endl;
73 73
#endif /* #ifndef NDEBUG */
74 74

                                        
75  
        return false;
76  
    }
  75
		return false;
  76
	}
77 77

                                        
78  
    return true;
  78
	return true;
79 79

                                        
80 80
} /* init() */
81 81

                                        
82 82
unsigned long int Moglk::autodetectBaudRate(char * device_ptr)
83 83
{
84 84

                                        
85  
        unsigned long int detected_baud_rate = 0;
86  
        unsigned char module_type;
87  
        long int baud_rate[] = {B9600,
88  
                                B19200,
89  
                                B38400,
90  
                                B115200,
91  
                                EOF};
  85
	unsigned long int detected_baud_rate = 0;
  86
	unsigned char module_type;
  87
	long int baud_rate[] = {B9600,
  88
	                        B19200,
  89
	                        B38400,
  90
	                        B115200,
  91
	                        EOF};
92 92

                                        
93  
        for (unsigned char n = 0;baud_rate[n] != EOF;n++)
94  
        {
95  
                init(device_ptr,
96  
                     baud_rate[n]);
97  
                module_type = getModuleType();
98  
                if (module_type)
99  
                {
100  
                        detected_baud_rate = baud_rate[n];
101  
                }
102  
        }
  93
	for (unsigned char n = 0;baud_rate[n] != EOF;n++)
  94
	{
  95
		init(device_ptr,
  96
		     baud_rate[n]);
  97
		module_type = getModuleType();
  98
		if (module_type)
  99
		{
  100
			detected_baud_rate = baud_rate[n];
  101
		}
  102
	}
103 103

                                        
104 104
#ifndef NDEBUG
105  
	cout << "DEBUG autodetectBaudRate() : detectedBaudrate = " << dec << detected_baud_rate << endl;
  105
	cout << "DEBUG autodetectBaudRate() : detectedBaudrate = " << dec <<
  106
		detected_baud_rate << endl;
106 107
#endif /* #ifndef NDEBUG */
107 108

                                        
108  
        return detected_baud_rate;
  109
	return detected_baud_rate;
109 110

                                        
110 111
} /* autodetectBaudRate */
111 112

                                        
112 113
bool Moglk::openPort(char * device_ptr)
113 114
{
114  
        // Open serial port:
  115
	// Open serial port:
115 116
	// read/write, no control terminal
116 117
	serial_port = open(device_ptr,
117  
                           O_RDWR | O_NOCTTY);
  118
	                   O_RDWR | O_NOCTTY);
118 119

                                        
119  
        // Handle errors
  120
	// Handle errors
120 121
	if (serial_port < 0)
121 122
	{
122  
		cerr << "ERROR openPort(): can't open serial port on " << device_ptr << endl;
  123
		cerr << "ERROR openPort(): can't open serial port on " << device_ptr <<
  124
			endl;
123 125
		return true;
124 126
	}
125  
        else
126  
        {
  127
	else
  128
	{
127 129
#ifndef NDEBUG
128  
        cout << "DEBUG openPort(): sucessfully opened serial port on " << device_ptr << endl;
  130
		cout << "DEBUG openPort(): sucessfully opened serial port on " <<
  131
			device_ptr << endl;
129 132
#endif /* #ifndef NDEBUG */
130  
                return false;
131  
        }
  133
		return false;
  134
	}
132 135

                                        
133  
        return true;
  136
	return true;
134 137

                                        
135 138
} /* openPort() */
136 139

                                        
137 140
void Moglk::configurePort(void)
138 141
{
139  
        // Port options
  142
	// Port options
140 143
	struct termios options;
141 144

                                        
142 145
	// Get current port options
143 146
	tcgetattr(serial_port,
144  
                  &options);
  147
	          &options);
145 148

                                        
146 149
	// Control options:
147 150
	// 8 data bits, no parity, 1 stopbit, local line, enable receiver
155 158
	// Raw output
156 159
	options.c_oflag &= ~OPOST;
157 160

                                        
158  
        // Character control options:
159  
        // Timeout after X*0.1 sec
160  
        options.c_cc[VTIME] = 1;
161  
        // No minimum number of bytes received
162  
        options.c_cc[VMIN] = 0;
  161
	// Character control options:
  162
	// Timeout after X*0.1 sec
  163
	options.c_cc[VTIME] = 1;
  164
	// No minimum number of bytes received
  165
	options.c_cc[VMIN] = 0;
163 166

                                        
164 167
	// Flush line
165 168
	tcflush(serial_port,
166  
                TCIFLUSH);
  169
	        TCIFLUSH);
167 170

                                        
168 171
	// Set port options
169 172
	tcsetattr(serial_port,
170  
                  TCSANOW,
171  
                  &options);
  173
	          TCSANOW,
  174
	          &options);
172 175

                                        
173 176
#ifndef NDEBUG
174  
        cout << "DEBUG configurePort()" << endl;
  177
	cout &lt;< "DEBUG configurePort()" << endl;
175 178
#endif /* #ifndef NDEBUG */
176 179

                                        
177 180
} /* configurePort() */
178 181

                                        
179 182
void Moglk::setPortBaudRate(unsigned long int baud_rate)
180 183
{
181  
        // Port rate flag
  184
	// Port rate flag
182 185
	tcflag_t port_rate;
183 186

                                        
184 187
	// baudrate to rate flag
215 218
		}
216 219
	} /* switch(baud_rate) */
217 220

                                        
218  
        // Port options
  221
	// Port options
219 222
	struct termios options;
220 223

                                        
221 224
	// Get current port options
222 225
	tcgetattr(serial_port,
223  
                  &options);
  226
	          &options);
224 227

                                        
225 228
	// Control options:
226 229
	// global baud rate
227 230
	options.c_cflag |= (port_rate);
228 231

                                        
229  
        // Set input baud rate
  232
	// Set input baud rate
230 233
	cfsetispeed(&options,
231  
                    port_rate);
  234
	            port_rate);
232 235

                                        
233 236
	// Set output baud rate
234 237
	cfsetospeed(&options,
235  
                    port_rate);
  238
	            port_rate);
236 239

                                        
237 240
	// Flush line
238 241
	tcflush(serial_port,
239  
                TCIFLUSH);
  242
	        TCIFLUSH);
240 243

                                        
241 244
	// Set port options
242 245
	tcsetattr(serial_port,
243  
                  TCSANOW,
244  
                  &options);
  246
	          TCSANOW,
  247
	          &options);
245 248

                                        
246 249
#ifndef NDEBUG
247  
        cout << "DEBUG setPortBaudRate(): " << dec << baud_rate << " bauds" << endl;
  250
	cout << "DEBUG setPortBaudRate(): " << dec << baud_rate << " bauds" <<
  251
		endl;
248 252
#endif /* #ifndef NDEBUG */
249 253

                                        
250 254
} /* setPortBaudRate() */
251 255

                                        
252 256
void Moglk::setPortFlowControl(bool state)
253 257
{
254  
        // Port options
  258
	// Port options
255 259
	struct termios options;
256 260

                                        
257 261
	// Get current port options
258 262
	tcgetattr(serial_port,
259  
                  &options);
  263
	          &options);
260 264

                                        
261 265
	if (state)
262 266
	{
263  
        // Input options:
264  
        // enable flow control
265  
        options.c_iflag |= (IXON | IXOFF);
  267
		// Input options:
  268
		// enable flow control
  269
		options.c_iflag |= (IXON | IXOFF);
266 270

                                        
267  
        // Control characters for flow control
268  
        options.c_cc[VSTART] = RET_ALMOST_EMPTY; // XON
269  
        options.c_cc[VSTOP] = RET_ALMOST_FULL; // XOFF
  271
		// Control characters for flow control
  272
		options.c_cc[VSTART] = RET_ALMOST_EMPTY;	// XON
  273
		options.c_cc[VSTOP] = RET_ALMOST_FULL;		// XOFF
270 274

                                        
271 275
#ifndef NDEBUG
272  
        cout << "DEBUG setPortFlowControl(): enabled" << endl;
  276
	cout &lt;< "DEBUG setPortFlowControl(): enabled" << endl;
273 277
#endif /* #ifndef NDEBUG */
274 278

                                        
275 279
	}
277 281
	{
278 282
		// Input options:
279 283
		// disable flow control
280  
                options.c_iflag &= ~(IXON | IXOFF | IXANY);
  284
		options.c_iflag &= ~(IXON | IXOFF | IXANY);
281 285

                                        
282 286
#ifndef NDEBUG
283  
                cout << "DEBUG setPortFlowControl(): disabled" << endl;
  287
	cout << &quot;DEBUG setPortFlowControl(): disabled" << endl;
284 288
#endif /* #ifndef NDEBUG */
285 289

                                        
286 290
	}
287 291

                                        
288  
        // Flush line
  292
	// Flush line
289 293
	tcflush(serial_port,
290  
                TCIFLUSH);
  294
	        TCIFLUSH);
291 295

                                        
292 296
	// Set port options
293 297
	tcsetattr(serial_port,
294  
                  TCSANOW,
295  
                  &options);
  298
	          TCSANOW,
  299
	          &options);
296 300

                                        
297 301
} /* setPortFlowControl() */
298 302

                                        
299 303
void Moglk::transmit(int * data_ptr)
300 304
{
301  
        ssize_t retval = 0;
  305
	ssize_t retval = 0;
302 306

                                        
303  
        // Write data to the serial port
  307
	// Write data to the serial port
304 308
	while (retval <= 0)
305 309
	{
306  
	    retval = write(serial_port,
307  
                           data_ptr,
308  
                           1);
  310
		retval = write(serial_port,
  311
		               data_ptr,
  312
		               1);
309 313
	}
310 314

                                        
311 315
#ifndef NDEBUG
312  
        cout << "DEBUG transmit(): transmited 0x" << hex << (int)*data_ptr << endl;
  316
	cout << "DEBUG transmit(): transmited 0x" << hex << (int)*data_ptr <<
  317
		endl;
313 318
#endif /* #ifndef NDEBUG */
314 319

                                        
315 320
} /* transmit() */
316 321

                                        
317 322
bool Moglk::receive(unsigned char * data_ptr)
318 323
{
319  
        unsigned char byte;
  324
	unsigned char byte;
320 325

                                        
321  
        ssize_t retval = -1;
  326
	ssize_t retval = -1;
322 327

                                        
323  
        retval = read(serial_port,
324  
                      &byte,
325  
                      1);
  328
	retval = read(serial_port,
  329
	              &byte,
  330
	              1);
326 331

                                        
327 332

                                        
328  
        if (!retval) 
329  
        {
330  
                clog << "WARNING receive(): read timed out" << endl;
331  
                return true;
332  
        }
  333
	if (!retval) 
  334
	{
  335
		clog << "WARNING receive(): read timed out" << endl;
  336
		return true;
  337
	}
333 338
	else
334  
        {
  339
	{
335 340
#ifndef NDEBUG
336  
                cout << "DEBUG receive(): received 0x" << hex << (int)byte << endl;
  341
		cout << "DEBUG receive(): received 0x" << hex << (int)byte << endl;
337 342
#endif /* #ifndef NDEBUG */
338  
                *data_ptr = byte;
339  
                return false;
340  
        }
  343
		*data_ptr = byte;
  344
		return false;
  345
	}
341 346

                                        
342  
return true;
  347
	return true;
343 348

                                        
344 349
} /* receive() */
345 350

                                        
346 351
void Moglk::send(int * message_ptr)
347 352
{
348  
        unsigned int n = 0;
  353
	unsigned int n = 0;
349 354
	int value = *(message_ptr + n);
350 355

                                        
351 356
	while (value != EOF)
352 357
	{
353  
                int * data_ptr;
354  
                data_ptr = &value;
355  
                transmit(data_ptr);
356  
                n++;
357  
                value = *(message_ptr + n);
  358
		int * data_ptr;
  359
		data_ptr = &value;
  360
		transmit(data_ptr);
  361
		n++;
  362
		value = *(message_ptr + n);
358 363
	}
359 364

                                        
360 365
#ifndef NDEBUG
365 370

                                        
366 371
bool Moglk::receiveFile(int * file_ptr)
367 372
{
368  
    unsigned char size[3];
  373
	unsigned char size[3];
369 374

                                        
370  
    unsigned int n = 0;
371  
    while (n < 4)
372  
    {
373  
        receive(&size[n]);
374  
        n++;
375  
    }
  375
	unsigned int n = 0;
  376
	while (n < 4)
  377
	{
  378
		receive(&size[n]);
  379
		n++;
  380
	}
376 381

                                        
377  
    unsigned int file_size = size[0] + size[1] * 256 + size[2] * 65536 + size[3] * 16777216;
  382
	unsigned int file_size = size[0] + size[1] * 256 + size[2] * 65536 +
  383
		size[3] * 16777216;
378 384

                                        
379 385
#ifndef NDEBUG
380  
    cout << "DEBUG receiveFile(): file size = " << dec << file_size << "B" << endl;
  386
	cout << "DEBUG receiveFile(): file size = " << dec << file_size << "B" <<
  387
		endl;
381 388
#endif /* #ifndef NDEBUG */
382 389

                                        
383  
        if (file_size)
384  
        {
385  
            int file[file_size + 1];
  390
	if (file_size)
  391
	{
  392
		int file[file_size + 1];
386 393

                                        
387  
            file_ptr = &file[0];
  394
		file_ptr = &file[0];
388 395

                                        
389  
            unsigned long int i = 0;
390  
            while (i < (file_size + 1))
391  
            {
  396
		unsigned long int i = 0;
  397
		while (i < (file_size + 1))
  398
		{
392 399
#ifndef NDEBUG
393  
            cout << "DEBUG receiveFile(): receiving byte #" << dec << i << " : ";
  400
			cout << "DEBUG receiveFile(): receiving byte #" << dec << i <<
  401
				" : ";
394 402
#endif /* #ifndef NDEBUG */
395 403

                                        
396  
                unsigned char * byte_ptr;
397  
                receive(byte_ptr);
398  
                file[i] = *byte_ptr;
399  
                i++;
400  
            }
401  
            file[i] = EOF;
  404
			unsigned char * byte_ptr;
  405
			receive(byte_ptr);
  406
			file[i] = *byte_ptr;
  407
			i++;
  408
		}
  409
		file[i] = EOF;
402 410

                                        
403 411
#ifndef NDEBUG
404  
            cout << "DEBUG receiveFile(): received file data = ";
405  
            unsigned long int k = 0;
406  
            while (file[k] != EOF)
407  
            {
408  
                cout << hex << (int)file[k];
409  
                k++;
410  
            }
411  
            cout << endl;
412  
            cout << "DEBUG receiveFile(): received " << dec << k - 1 << "B" << endl;
  412
		cout << "DEBUG receiveFile(): received file data = ";
  413
		unsigned long int k = 0;
  414
		while (file[k] != EOF)
  415
		{
  416
			cout << hex << (int)file[k];
  417
			k++;
  418
		}
  419
		cout << endl;
  420
		cout << "DEBUG receiveFile(): received " << dec << k - 1 << "B" <<
  421
				endl;
413 422
#endif /* #ifndef NDEBUG */
414  
            return false;
415  
        }
416  
        else
417  
        {
418  
                cerr << "ERROR receiveFile(): file doesn't exist" << endl;
419  
                return true;
420  
        }
  423
		return false;
  424
		}
  425
		else
  426
		{
  427
			cerr << "ERROR receiveFile(): file doesn't exist" << endl;
  428
			return true;
  429
		}
421 430

                                        
422  
        return true;
  431
		return true;
423 432

                                        
424 433
} /* receiveFile() */
425 434

                                        
433 442

                                        
434 443
	switch (baud_rate)
435 444
	{
436  
                case 0:
437  
                {
438  
                        device_rate = BAUD_RATE_DEFAULT;
439  
                        break;
440  
                }
  445
		case 0:
  446
		{
  447
				device_rate = BAUD_RATE_DEFAULT;
  448
				break;
  449
		}
441 450
		case 9600:
442 451
		{
443 452
			device_rate = BAUD_RATE_9600;
447 456
		case 14400:
448 457
		{
449 458
			device_rate = BAUD_RATE_14400;
450  
			clog << "WARNING Linux host doesn't support "<< baud_rate << "bauds rate" << endl;
  459
			clog << "WARNING Linux host doesn't support "<< baud_rate <<
  460
				"bauds rate" << endl;
451 461
			break;
452 462
		}
453 463

                                        
460 470
		case 28800:
461 471
		{
462 472
			device_rate = BAUD_RATE_28800;
463  
			clog << "WARNING Linux host doesn't support "<< baud_rate << "bauds rate" << endl;
  473
			clog << "WARNING Linux host doesn't support "<< baud_rate <<
  474
				"bauds rate" << endl;
464 475
			break;
465 476
		}
466 477

                                        
473 484
		case 57600:
474 485
		{
475 486
			device_rate = BAUD_RATE_57600;
476  
			clog << "WARNING Linux host doesn't support "<< baud_rate << "bauds rate" << endl;
  487
			clog << "WARNING Linux host doesn't support "<< baud_rate <<
  488
				"bauds rate" << endl;
477 489
			break;
478 490
		}
479 491

                                        
480 492
		case 76800:
481 493
		{
482 494
			device_rate = BAUD_RATE_76800;
483  
			clog << "WARNING Linux host doesn't support "<< baud_rate << "bauds rate" << endl;
  495
			clog << "WARNING Linux host doesn't support "<< baud_rate <<
  496
				"bauds rate" << endl;
484 497
			break;
485 498
		}
486 499

                                        
491 504
		}
492 505
		default:
493 506
		{
494  
                        standard = 0;
495  
                        if (baud_rate >= 977 && baud_rate <= 153800)
496  
                        {
497  
                                unsigned short int non_standard_rate = (16000000 / 8 * baud_rate) - 1;
498  
                                clog << "WARNING Linux host doesn't support custom rates (" << baud_rate << ")" << endl;
499  
                                non_standard_rate_lsb = non_standard_rate;
500  
                                non_standard_rate_msb = non_standard_rate / 256;
501  
                        }
502  
                        else
503  
                        {
504  
                                clog << "WARNING Device doesn't support " << dec << baud_rate << " bauds rate" << endl;
505  
                        }
  507
			standard = 0;
  508
			if (baud_rate >= 977 && baud_rate <= 153800)
  509
			{
  510
					unsigned short int non_standard_rate =
  511
						(16000000 / 8 * baud_rate) - 1;
  512
					clog <<
  513
						"WARNING Linux host doesn't support custom rates (" <<
  514
						baud_rate << ")" << endl;
  515
					non_standard_rate_lsb = non_standard_rate;
  516
					non_standard_rate_msb = non_standard_rate / 256;
  517
			}
  518
			else
  519
			{
  520
				clog << "WARNING Device doesn't support " << dec <<	baud_rate <<
  521
				" bauds rate" << endl;
  522
			}
506 523
			break;
507 524
		}
508 525

                                        
509 526
	} /* switch(baud_rate) */
510 527

                                        
511  
        if (!standard)
512  
        {
  528
	if (!standard)
  529
	{
513 530
#ifndef NDEBUG
514  
                cout << "DEBUG setBaudRate(): non-standard "<< dec << baud_rate << " (0x" << hex << (int)device_rate << ")" << endl;
  531
		cout << "DEBUG setBaudRate(): non-standard "<< dec << baud_rate <<
  532
			" (0x" << hex << (int)device_rate << ")" << endl;
515 533
#endif /* #ifndef NDEBUG */
516  
                if ((non_standard_rate_lsb < 12 && non_standard_rate_msb == 0) || (non_standard_rate_lsb == 0xFF && non_standard_rate_msb > 0x07))
517  
                {
518  
                        int message[] = {CMD_INIT,
519  
                                         CMD_NON_STANDARD_BAUD_RATE,
520  
                                         non_standard_rate_lsb,
521  
                                         non_standard_rate_msb,
522  
                                         EOF};
523  
                        send(&message[0]);
524  
                }
525  
                else
526  
                {
527  
                        cerr << "ERROR setBaudRate(): command ignored" << endl;
528  
                        return true;
529  
                }
530  
        }
531  
        else
532  
        {
  534
		if ((non_standard_rate_lsb < 12 && non_standard_rate_msb == 0) ||
  535
			(non_standard_rate_lsb == 0xFF && non_standard_rate_msb > 0x07))
  536
		{
  537
			int message[] = {CMD_INIT,
  538
			                 CMD_NON_STANDARD_BAUD_RATE,
  539
			                 non_standard_rate_lsb,
  540
			                 non_standard_rate_msb,
  541
			                 EOF};
  542
			send(&message[0]);
  543
		}
  544
		else
  545
		{
  546
			cerr << "ERROR setBaudRate(): command ignored" << endl;
  547
			return true;
  548
		}
  549
	}
  550
	else
  551
	{
533 552
#ifndef NDEBUG
534  
                cout << "DEBUG setBaudRate(): " << dec << baud_rate << " (0x" << hex << (int)device_rate << ")" << endl;
  553
		cout << "DEBUG setBaudRate(): " << dec << baud_rate << " (0x" <<
  554
			hex << (int)device_rate << ")" << endl;
535 555
#endif /* #ifndef NDEBUG */
536 556

                                        
537  
                int message[] = {CMD_INIT,
538  
                                 CMD_BAUD_RATE,
539  
                                 device_rate,
540  
                                 EOF};
541  
                send(&message[0]);
542  
        }
  557
		int message[] = {CMD_INIT,
  558
		                 CMD_BAUD_RATE,
  559
		                 device_rate,
  560
		                 EOF};
  561
		send(&message[0]);
  562
	}
543 563

                                        
544  
        setPortBaudRate(baud_rate);
  564
	setPortBaudRate(baud_rate);
545 565

                                        
546  
        return false;
  566
	return false;
547 567

                                        
548 568
} /* setBaudRate */
549 569

                                        
555 575
	if (state)
556 576
	{
557 577
#ifndef NDEBUG
558  
		cout << "DEBUG setFlowControl(): on, full at "<< dec << (int)full << " byte(s), empty at " << (int)empty << " bytes(s)" << endl;
  578
		cout << "DEBUG setFlowControl(): on, full at "<< dec << (int)full <<
  579
			" byte(s), empty at " << (int)empty << " bytes(s)" << endl;
559 580
#endif /* #ifndef NDEBUG */
560 581

                                        
561 582
		int message[] = {CMD_INIT,
562  
                                 CMD_FLOW_CONTROL_ON,
563  
                                 full,
564  
                                 empty,
565  
                                 EOF};
  583
		                 CMD_FLOW_CONTROL_ON,
  584
		                 full,
  585
		                 empty,
  586
		                 EOF};
566 587
		send(&message[0]);
567 588
	}
568  
    else
  589
	else
569 590
	{
570 591
#ifndef NDEBUG
571 592
		cout << "DEBUG setFlowControl(): off" << endl;
572 593
#endif /* #ifndef NDEBUG */
573 594

                                        
574 595
		int message[] = {CMD_INIT,
575  
                                 CMD_FLOW_CONTROL_OFF,
576  
                                 EOF};
  596
		                 CMD_FLOW_CONTROL_OFF,
  597
		                 EOF};
577 598
		send(&message[0]);
578 599
	}
579 600

                                        
580  
    setPortFlowControl(state);
  601
	setPortFlowControl(state);
581 602

                                        
582 603
} /* setFlowControl */
583 604

                                        
588 609
{
589 610

                                        
590 611

                                        
591  
    if (font != 0)
592  
    {
593  
        setFont(font);
594  
    }
  612
	if (font != 0)
  613
	{
  614
		setFont(font);
  615
	}
595 616

                                        
596  
    if (x != 255 && y != 255)
597  
    {
598  
        setCursor(x,
599  
                  y);
600  
    }
  617
	if (x != 255 && y != 255)
  618
	{
  619
		setCursor(x,
  620
		          y);
  621
	}
601 622

                                        
602  
    unsigned int n = 0;
603  
    unsigned int message_length = strlen(text);
604  
    int message[message_length + 1];
605  
    while (n < message_length + 1)
606  
    {
607  
        message[n] = text[n];
608  
        n++;
609  
    }
610  
    message[n] = EOF;
  623
	unsigned int n = 0;
  624
	unsigned int message_length = strlen(text);
  625
	int message[message_length + 1];
  626
	while (n < message_length + 1)
  627
	{
  628
		message[n] = text[n];
  629
		n++;
  630
	}
  631
	message[n] = EOF;
611 632

                                        
612 633
#ifndef NDEBUG
613  
	cout << "DEBUG display(): \"" << text << "\" of " << dec << n - 1 << " characters" << endl;
  634
	cout << "DEBUG display(): \"" << text << "\" of " << dec << n - 1 <<
  635
		" characters" << endl;
614 636
#endif /* #ifndef NDEBUG */
615 637

                                        
616 638
	send(&message[0]);
625 647
#endif /* #ifndef NDEBUG */
626 648

                                        
627 649
	int message[] = {CMD_INIT,
628  
                         CMD_CLEAR_SCREEN,
629  
                         EOF};
  650
	                 CMD_CLEAR_SCREEN,
  651
	                 EOF};
630 652
	send(&message[0]);
631 653

                                        
632 654
} /* clearScreen() */
639 661
#endif /* #ifndef NDEBUG */
640 662

                                        
641 663
	int message[] = {CMD_INIT,
642  
                         CMD_HOME,
643  
                         EOF};
  664
	                 CMD_HOME,
  665
	                 EOF};
644 666
	send(&message[0]);
645 667

                                        
646 668
} /* goHome() */
658 680
#endif /* #ifndef NDEBUG */
659 681

                                        
660 682
	int message[] = {CMD_INIT,
661  
                         CMD_USE_FONT,
662  
                         id,
663  
                         EOF};
  683
	                 CMD_USE_FONT,
  684
	                 id,
  685
	                 EOF};
664 686
	send(&message[0]);
665 687

                                        
666 688
	//Don't forget to set the font metrics
667 689
	setFontMetrics(lm,
668  
                       tm,
669  
                       csp,
670  
                       lsp,
671  
                       srow);
  690
	               tm,
  691
	               csp,
  692
	               lsp,
  693
	               srow);
672 694

                                        
673 695
} /* setFont() */
674 696

                                        
688 710
#endif /* #ifndef NDEBUG */
689 711

                                        
690 712
	int message[] = {CMD_INIT,
691  
                         CMD_FONT_METRICS,
692  
                         lm,
693  
                         tm,
694  
                         csp,
695  
                         lsp,
696  
                         srow,
697  
                         EOF};
  713
	                 CMD_FONT_METRICS,
  714
	                 lm,
  715
	                 tm,
  716
	                 csp,
  717
	                 lsp,
  718
	                 srow,
  719
	                 EOF};
698 720
	send(&message[0]);
699 721

                                        
700 722
} /* setFontMetrics() */
703 725
{
704 726

                                        
705 727
#ifndef NDEBUG
706  
    cout << "DEBUG setBoxSpace(): ";
  728
	cout << "DEBUG setBoxSpace(): ";
707 729
	if (!mode)
708 730
	{
709 731
		cout << "off";
716 738
#endif /* #ifndef NDEBUG */
717 739

                                        
718 740
	int message[] = {CMD_INIT,
719  
                         CMD_BOX_SPACE_MODE,
720  
                         mode,
721  
                         EOF};
  741
	                 CMD_BOX_SPACE_MODE,
  742
	                 mode,
  743
	                 EOF};
722 744
	send(&message[0]);
723 745

                                        
724 746
} /* setBoxSpace() */
733 755
#endif /* #ifndef NDEBUG */
734 756

                                        
735 757
		int message[] = {CMD_INIT,
736  
                                 CMD_AUTO_SCROLL_OFF,
737  
                                 EOF};
  758
		                 CMD_AUTO_SCROLL_OFF,
  759
		                 EOF};
738 760
		send(&message[0]);
739  
    }
740  
    else
741  
    {
  761
	}
  762
	else
  763
	{
742 764
#ifndef NDEBUG
743 765
		cout << "DEBUG setAutoScroll(): on" << endl;
744 766
#endif /* #ifndef NDEBUG */
745 767

                                        
746 768
		int message[] = {CMD_INIT,
747  
                                 CMD_AUTO_SCROLL_ON,
748  
                                 EOF};
  769
		                 CMD_AUTO_SCROLL_ON,
  770
		                 EOF};
749 771
		send(&message[0]);
750 772
	}
751 773

                                        
753 775

                                        
754 776
void Moglk::setCursor(unsigned char x,
755 777
                      unsigned char y,
756  
		      bool mode)
  778
                      bool mode)
757 779
{
758 780

                                        
759  
    if (x < 0 || y < 0)
760  
    {
761  
        cerr << "ERROR setCursor(): coodinates should be positive" << endl;
762  
    }
  781
	if (x < 0 || y < 0)
  782
	{
  783
		cerr << "ERROR setCursor(): coodinates should be positive" << endl;
  784
	}
763 785

                                        
764 786
	if (!mode)
765 787
	{
766 788
#ifndef NDEBUG
767  
		cout << "DEBUG setCursor(): absolute pixel mode, X=" << dec << (int)x << "px, Y=" << (int)y << "px" << endl;
  789
		cout << "DEBUG setCursor(): absolute pixel mode, X=" << dec << (int)x <<
  790
			"px, Y=" << (int)y << "px" << endl;
768 791
#endif /* #ifndef NDEBUG */
769 792

                                        
770 793
		int message[] = {CMD_INIT,
771  
                                 CMD_CURSOR_COORDINATE,
772  
                                 x,
773  
                                 y,
774  
                                 EOF};
  794
		                 CMD_CURSOR_COORDINATE,
  795
		                 x,
  796
		                 y,
  797
		                 EOF};
775 798
		send(&message[0]);
776  
    }
777  
    else
778  
    {
  799
	}
  800
	else
  801
	{
779 802
#ifndef NDEBUG
780  
			cout << "DEBUG setCursor(): absolute character size relative mode, X=" << dec << (int)x << ", Y=" << (int)y << endl;
  803
		cout <<
  804
			"DEBUG setCursor(): absolute character size relative mode, X=" <<
  805
			dec << (int)x << ", Y=" << (int)y << endl;
781 806
#endif /* #ifndef NDEBUG */
782 807

                                        
783 808
		int message[] = {CMD_INIT,
784  
                                 CMD_CURSOR_POSITION,
785  
                                 x,
786  
                                 y,
787  
                                 EOF};
  809
		                 CMD_CURSOR_POSITION,
  810
		                 x,
  811
		                 y,
  812
		                 EOF};
788 813
		send(&message[0]);
789 814
	}
790 815

                                        
797 822
#endif /* #ifndef NDEBUG */
798 823

                                        
799 824
	int message[] = {CMD_INIT,
800  
                         CMD_VERSION_NUMBER,
801  
                         EOF};
  825
	                 CMD_VERSION_NUMBER,
  826
	                 EOF};
802 827
	send(&message[0]);
803 828

                                        
804  
        unsigned char version;
  829
	unsigned char version;
805 830
	receive(&version);
806 831

                                        
807 832
#ifndef NDEBUG
808  
    stringstream tmp;
809  
    tmp << hex << (int)version;
810  
    unsigned char v[3];
811  
    tmp >> v;
812  
    v[2] = v[1]; // move second digit right
813  
    v[1] = '.'; // add dot between the two digits
814  
    v[3] = 0; // end string
  833
	stringstream tmp;
  834
	tmp << hex << (int)version;
  835
	unsigned char v[3];
  836
	tmp >> v;
  837
	v[2] = v[1];	// move second digit right
  838
	v[1] = '.';		// add dot between the two digits
  839
	v[3] = 0;		// end string
815 840
	cout << "DEBUG getVersion(): " << v << endl;
816 841
#endif /* #ifndef NDEBUG */
817 842

                                        
823 848
{
824 849

                                        
825 850
#ifndef NDEBUG
826  
    cout << "DEBUG getModuleType()" << endl;
  851
	cout << "DEBUG getModuleType()" << endl;
827 852
#endif /* #ifndef NDEBUG */
828 853

                                        
829 854
	int message[] = {CMD_INIT,
830  
                         CMD_MODULE_TYPE,
831  
                         EOF};
  855
	                 CMD_MODULE_TYPE,
  856
	                 EOF};
832 857
	send(&message[0]);
833 858

                                        
834  
        unsigned char type;
  859
	unsigned char type;
835 860
	receive(&type);
836 861

                                        
837 862
#ifndef NDEBUG
838 863
	cout << "DEBUG getModuleType(): ";
839  
    switch (type)
840  
    {
841  
        case RET_LCD0821:
842  
        {
843  
            cout << "LCD0821";
844  
            break;
845  
        }
  864
	switch (type)
  865
	{
  866
		case RET_LCD0821:
  867
		{
  868
			cout << "LCD0821";
  869
			break;
  870
		}
846 871

                                        
847  
        case RET_LCD2021:
848  
        {
849  
            cout << "LCD2021";
850  
            break;
851  
        }
  872
		case RET_LCD2021:
  873
		{
  874
			cout << "LCD2021";
  875
			break;
  876
		}
852 877

                                        
853  
        case RET_LCD2041:
854  
        {
855  
            cout << "LCD2041";
856  
            break;
857  
        }
  878
		case RET_LCD2041:
  879
		{
  880
			cout << "LCD2041";
  881
			break;
  882
		}
858 883

                                        
859  
        case RET_LCD4021:
860  
        {
861  
            cout << "LCD4021";
862  
            break;
863  
        }
  884
		case RET_LCD4021:
  885
		{
  886
			cout << "LCD4021";
  887
			break;
  888
		}
864 889

                                        
865  
        case RET_LCD4041:
866  
        {
867  
            cout << "LCD4041";
868  
            break;
869  
        }
  890
		case RET_LCD4041:
  891
		{
  892
			cout << "LCD4041";
  893
			break;
  894
		}
870 895

                                        
871  
        case RET_LK202_25:
872  
        {
873  
            cout << "LK202-25";
874  
            break;
875  
        }
  896
		case RET_LK202_25:
  897
		{
  898
			cout << "LK202-25";
  899
			break;
  900
		}
876 901

                                        
877 902

                                        
878  
        case RET_LK204_25:
879  
        {
880  
            cout << "LK204-25";
881  
            break;
882  
        }
  903
		case RET_LK204_25:
  904
		{
  905
			cout << "LK204-25";
  906
			break;
  907
		}
883 908

                                        
884  
        case RET_LK404_55:
885  
        {
886  
            cout << "LK404-55";
887  
            break;
888  
        }
  909
		case RET_LK404_55:
  910
		{
  911
			cout << "LK404-55";
  912
			break;
  913
		}
889 914

                                        
890  
        case RET_VFD2021:
891  
        {
892  
            cout << "VFD2021";
893  
            break;
894  
        }
  915
		case RET_VFD2021:
  916
		{
  917
			cout << "VFD2021";
  918
			break;
  919
		}
895 920

                                        
896  
        case RET_VFD2041:
897  
        {
898  
            cout << "VFD2041";
899  
            break;
900  
        }
901  
        case RET_VFD4021:
902  
        {
903  
            cout << "VFD4021";
904  
            break;
905  
        }
  921
		case RET_VFD2041:
  922
		{
  923
			cout << "VFD2041";
  924
			break;
  925
		}
  926
		case RET_VFD4021:
  927
		{
  928
			cout << "VFD4021";
  929
			break;
  930
		}
906 931

                                        
907  
        case RET_VK202_25:
908  
        {
909  
            cout << "VK202-25";
910  
            break;
911  
        }
  932
		case RET_VK202_25:
  933
		{
  934
			cout << "VK202-25";
  935
			break;
  936
		}
912 937

                                        
913  
        case RET_VK204_25:
914  
        {
915  
            cout << "VK204-25";
916  
            break;
917  
        }
  938
		case RET_VK204_25:
  939
		{
  940
			cout << "VK204-25";
  941
			break;
  942
		}
918 943

                                        
919  
        case RET_GLC12232:
920  
        {
921  
            cout << "GLC12232";
922  
            break;
923  
        }
  944
		case RET_GLC12232:
  945
		{
  946
			cout << "GLC12232";
  947
			break;
  948
		}
924 949

                                        
925  
        case RET_GLC24064:
926  
        {
927  
            cout << "GLC24064";
928  
            break;
929  
        }
  950
		case RET_GLC24064:
  951
		{
  952
			cout << "GLC24064";
  953
			break;
  954
		}
930 955

                                        
931  
        case RET_GLK24064_25:
932  
        {
933  
            cout << "GLK24064-25";
934  
            break;
935  
        }
  956
		case RET_GLK24064_25:
  957
		{
  958
			cout << "GLK24064-25";
  959
			break;
  960
		}
936 961

                                        
937  
        case RET_GLK12232_25:
938  
        {
939  
            cout << "GLK12232-25";
940  
            break;
941  
        }
  962
		case RET_GLK12232_25:
  963
		{
  964
			cout << "GLK12232-25";
  965
			break;
  966
		}
942 967

                                        
943  
        case RET_GLK12232_25_SM:
944  
        {
945  
            cout << "GLK12232-25-SM";
946  
            break;
947  
        }
  968
		case RET_GLK12232_25_SM:
  969
		{
  970
			cout << "GLK12232-25-SM";
  971
			break;
  972
		}
948 973

                                        
  974
		case RET_GLK24064_16_1U_USB:
  975
		{
  976
			cout << "GLK24064-16-1U-USB";
  977
			break;
  978
		}
949 979

                                        
950  
        case RET_GLK24064_16_1U_USB:
951  
        {
952  
            cout << "GLK24064-16-1U-USB";
953  
            break;
954  
        }
  980
		case RET_GLK24064_16_1U:
  981
		{
  982
			cout << "GLK24064-16-1U";
  983
			break;
  984
		}
955 985

                                        
956  
        case RET_GLK24064_16_1U:
957  
        {
958  
            cout << "GLK24064-16-1U";
959  
            break;
960  
        }
  986
		case RET_GLK19264_7T_1U_USB:
  987
		{
  988
			cout << "GLK19264-7T-1U-USB";
  989
			break;
  990
		}
961 991

                                        
962  
        case RET_GLK19264_7T_1U_USB:
963  
        {
964  
            cout << "GLK19264-7T-1U-USB";
965  
            break;
966  
        }
  992
		case RET_GLK12236_16:
  993
		{
  994
			cout << "GLK12236-16";
  995
			break;
  996
		}
967 997

                                        
968  
        case RET_GLK12236_16:
969  
        {
970  
            cout << "GLK12236-16";
971  
            break;
972  
        }
  998
		case RET_GLK12232_16_SM:
  999
		{
  1000
			cout << "GLK12232-16-SM";
  1001
			break;
  1002
		}
973 1003

                                        
974  
        case RET_GLK12232_16_SM:
975  
        {
976  
            cout << "GLK12232-16-SM";
977  
            break;
978  
        }
  1004
		case RET_GLK19264_7T_1U:
  1005
		{
  1006
			cout << "GLK19264-7T-1U";
  1007
			break;
  1008
		}
979 1009

                                        
980  
        case RET_GLK19264_7T_1U:
981  
        {
982  
            cout << "GLK19264-7T-1U";
983  
            break;
984  
        }
  1010
		case RET_LK204_7T_1U:
  1011
		{
  1012
			cout << "LK204-7T-1U";
  1013
			break;
  1014
		}
985 1015

                                        
986  
        case RET_LK204_7T_1U:
987  
        {
988  
            cout << "LK204-7T-1U";
989  
            break;
990  
        }
  1016
		case RET_LK204_7T_1U_USB:
  1017
		{
  1018
			cout << "LK204-7T-1U-USB";
  1019
			break;
  1020
		}
991 1021

                                        
992  
        case RET_LK204_7T_1U_USB:
993  
        {
994  
            cout << "LK204-7T-1U-USB";
995  
            break;
996  
        }
  1022
		case RET_LK404_AT:
  1023
		{
  1024
			cout << "LK404-AT";
  1025
			break;
  1026
		}
997 1027

                                        
998  
        case RET_LK404_AT:
999  
        {
1000  
            cout << "LK404-AT";
1001  
            break;
1002  
        }
  1028
		case RET_MOS_AV_162A:
  1029
		{
  1030
			cout << "MOS-AV-162A";
  1031
			break;
  1032
		}
1003 1033

                                        
1004  
        case RET_MOS_AV_162A:
1005  
        {
1006  
            cout << "MOS-AV-162A";
1007  
            break;
1008  
        }
  1034
		case RET_LK402_12:
  1035
		{
  1036
			cout << "LK402-12";
  1037
			break;
  1038
		}
1009 1039

                                        
1010  
        case RET_LK402_12:
1011  
        {
1012  
            cout << "LK402-12";
1013  
            break;
1014  
        }
  1040
		case RET_LK162_12:
  1041
		{
  1042
			cout << "LK162-12";
  1043
			break;
  1044
		}
1015 1045

                                        
1016  
        case RET_LK162_12:
1017  
        {
1018  
            cout << "LK162-12";
1019  
            break;
1020  
        }
  1046
		case RET_LK204_25PC:
  1047
		{
  1048
			cout << "LK204-25PC";
  1049
			break;
  1050
		}
1021 1051

                                        
1022  
        case RET_LK204_25PC:
1023  
        {
1024  
            cout << "LK204-25PC";
1025  
            break;
1026  
        }
  1052
		case RET_LK202_24_USB:
  1053
		{
  1054
			cout << "LK202-24-USB";
  1055
			break;
  1056
		}
1027 1057

                                        
1028  
        case RET_LK202_24_USB:
1029  
        {
1030  
            cout << "LK202-24-USB";
1031  
            break;
1032  
        }
  1058
		case RET_VK202_24_USB:
  1059
		{
  1060
			cout << "VK202-24-USB";
  1061
			break;
  1062
		}
1033 1063

                                        
1034  
        case RET_VK202_24_USB:
1035  
        {
1036  
            cout << "VK202-24-USB";
1037  
            break;
1038  
        }
  1064
		case RET_LK204_24_USB:
  1065
		{
  1066
			cout << "LK204-24-USB";
  1067
			break;
  1068
		}
1039 1069

                                        
1040  
        case RET_LK204_24_USB:
1041  
        {
1042  
            cout << "LK204-24-USB";
1043  
            break;
1044  
        }
  1070
		case RET_VK204_24_USB:
  1071
		{
  1072
			cout << "VK204-24-USB";
  1073
			break;
  1074
		}
1045 1075

                                        
1046  
        case RET_VK204_24_USB:
1047  
        {
1048  
            cout << "VK204-24-USB";
1049  
            break;
1050  
        }
  1076
		case RET_PK162_12:
  1077
		{
  1078
			cout << "PK162-12";
  1079
			break;
  1080
		}
1051 1081

                                        
1052  
        case RET_PK162_12:
1053  
        {
1054  
            cout << "PK162-12";
1055  
            break;
1056  
        }
  1082
		case RET_VK162_12:
  1083
		{
  1084
			cout << "VK162-12";
  1085
			break;
  1086
		}
1057 1087

                                        
1058  
        case RET_VK162_12:
1059  
        {
1060  
            cout << "VK162-12";
1061  
            break;
1062  
        }
  1088
		case RET_MOS_AP_162A:
  1089
		{
  1090
			cout << "MOS-AP-162A";
  1091
			break;
  1092
		}
1063 1093

                                        
1064  
        case RET_MOS_AP_162A:
1065  
        {
1066  
            cout << "MOS-AP-162A";
1067  
            break;
1068  
        }
  1094
		case RET_PK202_25:
  1095
		{
  1096
			cout << "PK202-25";
  1097
			break;
  1098
		}
1069 1099

                                        
1070  
        case RET_PK202_25:
1071  
        {
1072  
            cout << "PK202-25";
1073  
            break;
1074  
        }
  1100
		case RET_MOS_AL_162A:
  1101
		{
  1102
			cout << "MOS-AL-162A";
  1103
			break;
  1104
		}
1075 1105

                                        
1076  
        case RET_MOS_AL_162A:
1077  
        {
1078  
            cout << "MOS-AL-162A";
1079  
            break;
1080  
        }
  1106
		case RET_MOS_AL_202A:
  1107
		{
  1108
			cout << "MOS-AL-202A";
  1109
			break;
  1110
		}
1081 1111

                                        
1082  
        case RET_MOS_AL_202A:
1083  
        {
1084  
            cout << "MOS-AL-202A";
1085  
            break;
1086  
        }
  1112
		case RET_MOS_AV_202A:
  1113
		{
  1114
			cout << "MOS-AV-202A";
  1115
			break;
  1116
		}
1087 1117

                                        
1088  
        case RET_MOS_AV_202A:
1089  
        {
1090  
            cout << "MOS-AV-202A";
1091  
            break;
1092  
        }
  1118
		case RET_MOS_AP_202A:
  1119
		{
  1120
			cout << "MOS-AP-202A";
  1121
			break;
  1122
		}
1093 1123

                                        
1094  
        case RET_MOS_AP_202A:
1095  
        {
1096  
            cout << "MOS-AP-202A";
1097  
            break;
1098  
        }
  1124
		case RET_PK202_24_USB:
  1125
		{
  1126
			cout << "PK202-24-USB";
  1127
			break;
  1128
		}
1099 1129

                                        
1100  
        case RET_PK202_24_USB:
1101  
        {
1102  
            cout << "PK202-24-USB";
1103  
            break;
1104  
        }
  1130
		case RET_MOS_AL_082:
  1131
		{
  1132
			cout << "MOS-AL-082";
  1133
			break;
  1134
		}
1105 1135

                                        
1106  
        case RET_MOS_AL_082:
1107  
        {
1108  
            cout << "MOS-AL-082";
1109  
            break;
1110  
        }
  1136
		case RET_MOS_AL_204:
  1137
		{
  1138
			cout << "MOS-AL-204";
  1139
			break;
  1140
		}
1111 1141

                                        
1112  
        case RET_MOS_AL_204:
1113  
        {
1114  
            cout << "MOS-AL-204";
1115  
            break;
1116  
        }
  1142
		case RET_MOS_AV_204:
  1143
		{
  1144
			cout << "MOS-AV-204";
  1145
			break;
  1146
		}
1117 1147

                                        
1118  
        case RET_MOS_AV_204:
1119  
        {
1120  
            cout << "MOS-AV-204";
1121  
            break;
1122  
        }
  1148
		case RET_MOS_AL_402:
  1149
		{
  1150
			cout << "MOS-AL-402";
  1151
			break;
  1152
		}
1123 1153

                                        
1124  
        case RET_MOS_AL_402:
1125  
        {
1126  
            cout << "MOS-AL-402";
1127  
            break;
1128  
        }
  1154
		case RET_MOS_AV_402:
  1155
		{
  1156
			cout << "MOS-AV-402";
  1157
			break;
  1158
		}
1129 1159

                                        
1130  
        case RET_MOS_AV_402:
1131  
        {
1132  
            cout << "MOS-AV-402";
1133  
            break;
1134  
        }
  1160
		case RET_LK082_12:
  1161
		{
  1162
			cout << "LK082-12";
  1163
			break;
  1164
		}
1135 1165

                                        
1136  
        case RET_LK082_12:
1137  
        {
1138  
            cout << "LK082-12";
1139  
            break;
1140  
        }
  1166
		case RET_VK402_12:
  1167
		{
  1168
			cout << "VK402-12";
  1169
			break;
  1170
		}
1141 1171

                                        
1142  
        case RET_VK402_12:
1143  
        {
1144  
            cout << "VK402-12";
1145  
            break;
1146  
        }
  1172
		case RET_VK404_55:
  1173
		{
  1174
			cout << "VK404-55";
  1175
			break;
  1176
		}
1147 1177

                                        
1148  
        case RET_VK404_55:
1149  
        {
1150  
            cout << "VK404-55";
1151  
            break;
1152  
        }
  1178
		case RET_LK402_25:
  1179
		{
  1180
			cout << "LK402-25";
  1181
			break;
  1182
		}
1153 1183

                                        
1154  
        case RET_LK402_25:
1155  
        {
1156  
            cout << "LK402-25";
1157  
            break;
1158  
        }
  1184
		case RET_VK402_25:
  1185
		{
  1186
			cout << "VK402-25";
  1187
			break;
  1188
		}
1159 1189

                                        
1160  
        case RET_VK402_25:
1161  
        {
1162  
            cout << "VK402-25";
1163  
            break;
1164  
        }
  1190
		case RET_PK204_25:
  1191
		{
  1192
			cout << "PK204-25";
  1193
			break;
  1194
		}
1165 1195

                                        
1166  
        case RET_PK204_25:
1167  
        {
1168  
            cout << "PK204-25";
1169  
            break;
1170  
        }
  1196
		case RET_MOS:
  1197
		{
  1198
			cout << "MOS";
  1199
			break;
  1200
		}
1171 1201

                                        
1172  
        case RET_MOS:
1173  
        {
1174  
            cout << "MOS";
1175  
            break;
1176  
        }
  1202
		case RET_MOI:
  1203
		{
  1204
			cout << "MOI";
  1205
			break;
  1206
		}
1177 1207

                                        
1178  
        case RET_MOI:
1179  
        {
1180  
            cout << "MOI";
1181  
            break;
1182  
        }
  1208
		case RET_XBOARD_S:
  1209
		{
  1210
			cout << "XBOARD-S";
  1211
			break;
  1212
		}
1183 1213

                                        
1184  
        case RET_XBOARD_S:
1185  
        {
1186  
            cout << "XBOARD-S";
1187  
            break;
1188  
        }
  1214
		case RET_XBOARD_I:
  1215
		{
  1216
			cout << "XBOARD-I";
  1217
			break;
  1218
		}
1189 1219

                                        
1190  
        case RET_XBOARD_I:
1191  
        {
1192  
            cout << "XBOARD-I";
1193  
            break;
1194  
        }
  1220
		case RET_MOU:
  1221
		{
  1222
			cout << "MOU";
  1223
			break;
  1224
		}
1195 1225

                                        
1196  
        case RET_MOU:
1197  
        {
1198  
            cout << "MOU";
1199  
            break;
1200  
        }
  1226
		case RET_XBOARD_U:
  1227
		{
  1228
			cout << "XBOARD-U";
  1229
			break;
  1230
		}
1201 1231

                                        
1202  
        case RET_XBOARD_U:
1203  
        {
1204  
            cout << "XBOARD-U";
1205  
            break;
1206  
        }
  1232
		case RET_LK202_25_USB:
  1233
		{
  1234
			cout << "LK202-25-USB";
  1235
			break;
  1236
		}
1207 1237

                                        
1208  
        case RET_LK202_25_USB:
1209  
        {
1210  
            cout << "LK202-25-USB";
1211  
            break;
1212  
        }
  1238
		case RET_VK202_25_USB:
  1239
		{
  1240
			cout << "VK202-25-USB";
  1241
			break;
  1242
		}
1213 1243

                                        
1214  
        case RET_VK202_25_USB:
1215  
        {
1216  
            cout << "VK202-25-USB";
1217  
            break;
1218  
        }
  1244
		case RET_LK204_25_USB:
  1245
		{
  1246
			cout << "LK204-25-USB";
  1247
			break;
  1248
		}
1219 1249

                                        
1220  
        case RET_LK204_25_USB:
1221  
        {
1222  
            cout << "LK204-25-USB";
1223  
            break;
1224  
        }
  1250
		case RET_VK204_25_USB:
  1251
		{
  1252
			cout << "VK204-25-USB";
  1253
			break;
  1254
		}
1225 1255

                                        
1226  
        case RET_VK204_25_USB:
1227  
        {
1228  
            cout << "VK204-25-USB";
1229  
            break;
1230  
        }
  1256
		case RET_LK162_12_TC:
  1257
		{
  1258
			cout << "LK162-12-TC";
  1259
			break;
  1260
		}
1231 1261

                                        
1232  
        case RET_LK162_12_TC:
1233  
        {
1234  
            cout << "LK162-12-TC";
1235  
            break;
1236  
        }
  1262
		case RET_GLK240128_25:
  1263
		{
  1264
			cout << "GLK240128-25";
  1265
			break;
  1266
		}
1237 1267

                                        
1238  
        case RET_GLK240128_25:
1239  
        {
1240  
            cout << "GLK240128-25";
1241  
            break;
1242  
        }
  1268
		case RET_LK404_25:
  1269
		{
  1270
			cout << "LK404-25";
  1271
			break;
  1272
		}
1243 1273

                                        
1244  
        case RET_LK404_25:
1245  
        {
1246  
            cout << "LK404-25";
1247  
            break;
1248  
        }
  1274
		case RET_VK404_25:
  1275
		{
  1276
			cout << "VK404-25";
  1277
			break;
  1278
		}
1249 1279

                                        
1250  
        case RET_VK404_25:
1251  
        {
1252  
            cout << "VK404-25";
1253  
            break;
1254  
        }
  1280
		default:
  1281
		{
  1282
			cerr << "ERROR getModuleType: unknown module of type 0x" << hex << (int)type << endl;
  1283
			break;
  1284
		}
  1285
	} /* switch(type) */
1255 1286

                                        
1256  
        default:
1257  
        {
1258  
            cerr << "ERROR getModuleType: unknown module of type 0x" << hex << (int)type << endl;
1259  
            break;
1260  
        }
1261  
    } /* switch(type) */
1262  

                                    
1263  
    cout << " (0x" << hex << (int)type << ")" << endl;
  1287
	cout << " (0x" << hex << (int)type << ")" << endl;
1264 1288
#endif /* #ifndef NDEBUG */
1265 1289

                                        
1266 1290
	return type;
1274 1298
#endif /* #ifndef NDEBUG */
1275 1299

                                        
1276 1300
	int message[] = {CMD_INIT,
1277  
                         CMD_READ_CUSTOMER_DATA,
1278  
                         EOF};
  1301
	                 CMD_READ_CUSTOMER_DATA,
  1302
	                 EOF};
1279 1303
	send(&message[0]);
1280 1304

                                        
1281  
    unsigned int n = 0;
1282  
    while (n < 16)
1283  
    {
1284  
        receive((data + n));
1285  
        n++;
1286  
    }
1287  
    *(data + n) = EOF;
  1305
	unsigned int n = 0;
  1306
	while (n < 16)
  1307
	{
  1308
		receive((data + n));
  1309
		n++;
  1310
	}
  1311
	*(data + n) = EOF;
1288 1312

                                        
1289 1313
#ifndef NDEBUG
1290 1314
	cout << "DEBUG getCustomerData(): " << data << endl;
1297 1321
{
1298 1322

                                        
1299 1323
#ifndef NDEBUG
1300  
	cout << "DEBUG drawMemBmp(): bitmap #" << dec << (int)id << ", X=" << (int)x << "px ,Y=" << (int)y << "px"<< endl;
  1324
	cout << "DEBUG drawMemBmp(): bitmap #" << dec << (int)id << ", X=" <<
  1325
		(int)x << "px ,Y=" << (int)y << "px"<< endl;
1301 1326
#endif /* #ifndef NDEBUG */
1302 1327

                                        
1303 1328
	int message[] = {CMD_INIT,
1304  
                         CMD_DRAW_MEMORY_BMP,
1305  
                         id,
1306  
                         x,
1307  
                         y,
1308  
                         EOF};
  1329
	                 CMD_DRAW_MEMORY_BMP,
  1330
	                 id,
  1331
	                 x,
  1332
	                 y,
  1333
	                 EOF};
1309 1334
	send(&message[0]);
1310 1335

                                        
1311 1336
} /* drawMemBmp() */
1314 1339
{
1315 1340

                                        
1316 1341
#ifndef NDEBUG
1317  
    cout << "DEBUG setDrawingColor(): ";
  1342
	cout << "DEBUG setDrawingColor(): ";
1318 1343
	if (!color)
1319 1344
	{
1320  
        cout << "white";
1321  
    }
1322  
    else
1323  
    {
1324  
        cout << "black";
  1345
		cout << "white";
1325 1346
	}
  1347
	else
  1348
	{
  1349
		cout << "black";
  1350
	}
1326 1351
	cout << endl;
1327 1352

                                        
1328 1353
#endif /* #ifndef NDEBUG */
1329 1354

                                        
1330 1355
	int message[] = {CMD_INIT,
1331  
                         CMD_DRAWING_COLOR,
1332  
                         color,
1333  
                         EOF};
  1356
	                 CMD_DRAWING_COLOR,
  1357
 	                 color,
  1358
	                 EOF};
1334 1359
	send(&message[0]);
1335 1360

                                        
1336 1361
} /* setDrawingColor() */
1340 1365
                      bool color)
1341 1366
{
1342 1367

                                        
1343  
    setDrawingColor(color);
  1368
	setDrawingColor(color);
1344 1369

                                        
1345 1370
#ifndef NDEBUG
1346  
	cout << "DEBUG drawPixel(): X=" << dec << (int)x << "px, Y=" << (int)y << "px"<< endl;
  1371
	cout << "DEBUG drawPixel(): X=" << dec << (int)x << "px, Y=" << (int)y <<
  1372
		"px"<< endl;
1347 1373
#endif /* #ifndef NDEBUG */
1348 1374

                                        
1349  
    int message[] = {CMD_INIT,
1350  
                     CMD_DRAW_PIXEL,
1351  
                     x,
1352  
                     y,
1353  
                     EOF};
1354  
    send(&message[0]);
  1375
	int message[] = {CMD_INIT,
  1376
	             CMD_DRAW_PIXEL,
  1377
	             x,
  1378
	             y,
  1379
	             EOF};
  1380
	send(&message[0]);
1355 1381

                                        
1356 1382
} /* drawPixel() */
1357 1383

                                        
1362 1388
                     bool color)
1363 1389
{
1364 1390

                                        
1365  
    setDrawingColor(color);
  1391
	setDrawingColor(color);
1366 1392

                                        
1367  
    if (x2 < 255 && y2 < 255)
1368  
    {
  1393
	if (x2 < 255 && y2 < 255)
  1394
	{
1369 1395

                                        
1370 1396
#ifndef NDEBUG
1371  
        cout << "DEBUG drawLine(): X1=" << dec << (int)x1 << "px, Y1=" << (int)y1 << "px, X2=" << (int)x2 << "px, Y2=" << (int)y2 << "px" << endl;
  1397
		cout << "DEBUG drawLine(): X1=" << dec << (int)x1 << "px, Y1=" <<
  1398
			(int)y1 << "px, X2=" << (int)x2 << "px, Y2=" << (int)y2 << "px" <<
  1399
			endl;
1372 1400
#endif /* #ifndef NDEBUG */
1373 1401

                                        
1374  
        int message[] = {CMD_INIT,
1375  
                         CMD_DRAW_LINE,
1376  
                         x1,
1377  
                         y1,
1378  
                         x2,
1379  
                         y2,
1380  
                         EOF};
1381  
        send(&message[0]);
1382  
    }
1383  
    if (x2 == 255 || y2 == 255)
1384  
    {
1385  
            cerr << "ERROR drawLine(): command ignored, only one value of X2 or Y2 set!" << endl;
1386  
            return true;
1387  
    }
1388  
    if (x2 == 255 && y2 == 255)
1389  
    {
  1402
		int message[] = {CMD_INIT,
  1403
		                 CMD_DRAW_LINE,
  1404
		                 x1,
  1405
		                 y1,
  1406
		                 x2,
  1407
		                 y2,
  1408
		                 EOF};
  1409
		send(&message[0]);
  1410
	}
  1411
	if (x2 == 255 || y2 == 255)
  1412
	{
  1413
		cerr <<
  1414
			"ERROR drawLine(): command ignored," <<
  1415
			" only one value of X2 or Y2 set!" << endl;
  1416
		return true;
  1417
	}
  1418
	if (x2 == 255 && y2 == 255)
  1419
	{
1390 1420

                                        
1391 1421
#ifndef NDEBUG
1392  
        cout << "DEBUG drawLine(): continue previous line to X=" << dec << (int)x1 << "px, Y=" << (int)y1 << "px" << endl;
  1422
		cout << "DEBUG drawLine(): continue previous line to X=" << dec <<
  1423
			(int)x1 << "px, Y=" << (int)y1 << "px" << endl;
1393 1424
#endif /* #ifndef NDEBUG */
1394 1425

                                        
1395  
        int message[] = {CMD_INIT,
1396  
                         CMD_CONTINUE_LINE,
1397  
                         x1,
1398  
                         y1,
1399  
                         EOF};
1400  
        send(&message[0]);
1401  
    }
  1426
		int message[] = {CMD_INIT,
  1427
		                 CMD_CONTINUE_LINE,
  1428
		                 x1,
  1429
		                 y1,
  1430
		                 EOF};
  1431
		send(&message[0]);
  1432
	}
1402 1433

                                        
1403  
    return false;
  1434
	return false;
1404 1435

                                        
1405 1436
} /* drawLine() */
1406 1437

                                        
1412 1443
                          bool color)
1413 1444
{
1414 1445

                                        
1415  
    if (!mode)
1416  
    {
  1446
	if (!mode)
  1447
	{
1417 1448
#ifndef NDEBUG
1418  
        cout << "DEBUG drawRectangle(): empty, ";
1419  
        if (color) cout << "black";
1420  
        else cout << "white";
1421  
        cout << ", X1=" << dec << (int)x1 << "px, Y1=" << (int)y1 << "px, X2=" << (int)x2 << "px, Y2=" << (int)y2 << "px" << endl;
  1449
		cout << "DEBUG drawRectangle(): empty, ";
  1450
		if (color) cout << "black";
  1451
		else cout << "white";
  1452
		cout << ", X1=" << dec << (int)x1 << "px, Y1=" << (int)y1 <<
  1453
			"px, X2=" << (int)x2 << "px, Y2=" << (int)y2 << "px" << endl;
1422 1454
#endif /* #ifndef NDEBUG */
1423 1455

                                        
1424  
        int message[] = {CMD_INIT,
1425  
                         CMD_DRAW_RECTANGLE,
1426  
                         color,
1427  
                         x1,
1428  
                         y1,
1429  
                         x2,
1430  
                         y2,
1431  
                         EOF};
1432  
        send(&message[0]);
1433  
    }
1434  
    else
1435  
    {
  1456
		int message[] = {CMD_INIT,
  1457
		                 CMD_DRAW_RECTANGLE,
  1458
		                 color,
  1459
		                 x1,
  1460
		                 y1,
  1461
		                 x2,
  1462
		                 y2,
  1463
		                 EOF};
  1464
		send(&message[0]);
  1465
	}
  1466
	else
  1467
	{
1436 1468
#ifndef NDEBUG
1437  
        cout << "DEBUG drawRectangle(): solid, ";
1438  
        if (color) cout << "black";
1439  
        else cout << "white";
1440  
        cout << ", X1=" << dec << (int)x1 << "px, Y1=" << (int)y1 << "px, X2=" << (int)x2 << "px, Y2=" << (int)y2 << "px" << endl;
  1469
		cout << "DEBUG drawRectangle(): solid, ";
  1470
		if (color) cout << "black";
  1471
		else cout << "white";
  1472
		cout << ", X1=" << dec << (int)x1 << "px, Y1=" << (int)y1 <<
  1473
			"px, X2=" << (int)x2 << "px, Y2=" << (int)y2 << "px" << endl;
1441 1474
#endif /* #ifndef NDEBUG */
1442 1475

                                        
1443  
        int message[] = {CMD_INIT,
1444  
                         CMD_DRAW_SOLID_RECTANGLE,
1445  
                         color,
1446  
                         x1,
1447  
                         y1,
1448  
                         x2,
1449  
                         y2,
1450  
                         EOF};
1451  
        send(&message[0]);
1452  
    }
  1476
		int message[] = {CMD_INIT,
  1477
		                 CMD_DRAW_SOLID_RECTANGLE,
  1478
		                 color,
  1479
		                 x1,
  1480
		                 y1,
  1481
		                 x2,
  1482
		                 y2,
  1483
		                 EOF};
  1484
		send(&message[0]);
  1485
	}
1453 1486

                                        
1454 1487
} /* drawRectangle() */
1455 1488

                                        
1461 1494
                         unsigned char id)
1462 1495
{
1463 1496

                                        
1464  
    if (id > 15)
1465  
    {
1466  
        cerr << "ERROR initBarGraph(): id should be within 0-15" << endl;
1467  
        return true;
1468  
    }
  1497
	if (id > 15)
  1498
	{
  1499
		cerr << "ERROR initBarGraph(): id should be within 0-15" << endl;
  1500
		return true;
  1501
	}
1469 1502

                                        
1470  
    if (type > 3)
1471  
    {
1472  
        cerr << "ERROR initBarGraph(): type should be within 0-3" << endl;
1473  
        return true;
1474  
    }
  1503
	if (type > 3)
  1504
	{
  1505
		cerr << "ERROR initBarGraph(): type should be within 0-3" << endl;
  1506
		return true;
  1507
	}
1475 1508

                                        
1476  
    if (x1 > x2)
1477  
    {
1478  
        cerr << "ERROR initBarGraph(): x1 should be less than x2, please use type to choose the direction" << endl;
1479  
        return true;
1480  
    }
  1509
	if (x1 > x2)
  1510
	{
  1511
		cerr << "ERROR initBarGraph(): x1 should be less than x2," <<
  1512
			" please use type to choose the direction" << endl;
  1513
		return true;
  1514
	}
1481 1515

                                        
1482  
    if (y1 > y2)
1483  
    {
1484  
        cerr << "ERROR initBarGraph(): y1 should be less than y2, please use type to choose the direction" << endl;
1485  
        return true;
1486  
    }
  1516
	if (y1 > y2)
  1517
	{
  1518
		cerr << "ERROR initBarGraph(): y1 should be less than y2," <<
  1519
			" please use type to choose the direction" << endl;
  1520
		return true;
  1521
	}
1487 1522

                                        
1488  
#ifndef NDEBUG
1489  
    cout << "DEBUG initBarGraph(): bar graph #" << dec << (int)id << ", ";
1490  
    switch (type)
1491  
    {
1492  
        case 0:
1493  
        {
1494  
            cout << "vertical from bottom";
1495  
            break;
1496  
        }
  1523
	#ifndef NDEBUG
  1524
	cout << "DEBUG initBarGraph(): bar graph #" << dec << (int)id << ", ";
  1525
	switch (type)
  1526
	{
  1527
		case 0:
  1528
		{
  1529
			cout << "vertical from bottom";
  1530
			break;
  1531
		}
1497 1532

                                        
1498  
        case 1:
1499  
        {
1500  
            cout << "horizontal from left";
1501  
            break;
1502  
        }
  1533
		case 1:
  1534
		{
  1535
			cout << "horizontal from left";
  1536
			break;
  1537
		}
1503 1538

                                        
1504  
        case 2:
1505  
        {
1506  
            cout << "vertical from top";
1507  
            break;
1508  
        }
  1539
		case 2:
  1540
		{
  1541
			cout << "vertical from top";
  1542
			break;
  1543
		}
1509 1544

                                        
1510  
        case 3:
1511  
        {
1512  
            cout << "horizontal from right";
1513  
            break;
1514  
        }
1515  
    } /* switch(type) */
1516  
    cout << ", X1=" << dec << (int)x1 << "px, Y1=" << (int)y1 << "px, X2=" << (int)x2 << "px, Y2=" << (int)y2 << "px" << endl;
  1545
		case 3:
  1546
		{
  1547
			cout << "horizontal from right";
  1548
			break;
  1549
		}
  1550
	} /* switch(type) */
  1551
	cout << ", X1=" << dec << (int)x1 << "px, Y1=" << (int)y1 << "px, X2=" <<
  1552
		(int)x2 << "px, Y2=" << (int)y2 << "px" << endl;
1517 1553
#endif /* #ifndef NDEBUG */
1518 1554

                                        
1519  
    int message[] = {CMD_INIT,
1520  
                     CMD_INITIALIZE_BAR_GRAPH,
1521  
                     id,
1522  
                     type,
1523  
                     x1,
1524  
                     y1,
1525  
                     x2,
1526  
                     y2,
1527  
                     EOF};
1528  
    send(&message[0]);
  1555
	int message[] = {CMD_INIT,
  1556
	                 CMD_INITIALIZE_BAR_GRAPH,
  1557
	                 id,
  1558
	                 type,
  1559
	                 x1,
  1560
	                 y1,
  1561
	                 x2,
  1562
	                 y2,
  1563
	                 EOF};
  1564
	send(&message[0]);
1529 1565

                                        
1530  
    return false;
  1566
	return false;
1531 1567

                                        
1532 1568
} /* initBarGraph() */
1533 1569

                                        
1534 1570
bool Moglk::drawBarGraph(unsigned char value,
1535 1571
                         unsigned char id)
1536 1572
{
1537  
    if (id > 15)
1538  
    {
1539  
        cerr << "ERROR drawBarGraph(): id should be within 0-15" << endl;
1540  
        return true;
1541  
    }
  1573
	if (id > 15)
  1574
	{
  1575
		cerr << "ERROR drawBarGraph(): id should be within 0-15" << endl;
  1576
		return true;
  1577
	}
1542 1578

                                        
1543 1579
#ifndef NDEBUG
1544  
    cout << "DEBUG drawBarGraph(): bar graph #" << dec << (int)id << " to " << (int)value << "px" << endl;
  1580
	cout << "DEBUG drawBarGraph(): bar graph #" << dec << (int)id << " to " <<
  1581
		(int)value << "px" << endl;
1545 1582
#endif /* #ifndef NDEBUG */
1546 1583

                                        
1547  
    int message[] = {CMD_INIT,
1548  
                     CMD_DRAW_BAR_GRAPH,
1549  
                     id,
1550  
                     value,
1551  
                     EOF};
1552  
    send(&message[0]);
  1584
	int message[] = {CMD_INIT,
  1585
	                 CMD_DRAW_BAR_GRAPH,
  1586
	                 id,
  1587
	                 value,
  1588
	                 EOF};
  1589
	send(&message[0]);
1553 1590

                                        
1554  
    return false;
  1591
	return false;
1555 1592

                                        
1556 1593
} /* drawBarGraph() */
1557 1594

                                        
1562 1599
                           unsigned char id)
1563 1600
{
1564 1601

                                        
1565  
    if (id > 6)
1566  
    {
1567  
        cerr << "ERROR initStripChart(): id should be within 0-6" << endl;
1568  
        return true;
1569  
    }
  1602
	if (id > 6)
  1603
	{
  1604
		cerr << "ERROR initStripChart(): id should be within 0-6" << endl;
  1605
		return true;
  1606
	}
1570 1607

                                        
1571  
    if (x1 > x2)
1572  
    {
1573  
        cerr << "ERROR initStripChart(): x1 should be less than x2, please use type to choose the direction" << endl;
1574  
        return true;
1575  
    }
  1608
	if (x1 > x2)
  1609
	{
  1610
		cerr << "ERROR initStripChart(): x1 should be less than x2," <<
  1611
			" please use type to choose the direction" << endl;
  1612
		return true;
  1613
	}
1576 1614

                                        
1577  
    if (y1 > y2)
1578  
    {
1579  
        cerr << "ERROR initStripChart(): y1 should be less than y2, please use type to choose the direction" << endl;
1580  
        return true;
1581  
    }
  1615
	if (y1 > y2)
  1616
	{
  1617
		cerr << "ERROR initStripChart(): y1 should be less than y2," <<
  1618
			" please use type to choose the direction" << endl;
  1619
		return true;
  1620
	}
1582 1621

                                        
1583 1622
#ifndef NDEBUG
1584  
    cout << "DEBUG initStripChart(): strip chart #" << dec << (int)id << ", X1=" << (int)x1 << ", Y1=" << (int)y1 << ", X2=" << (int)x2 << ", Y2=" << (int)y2 << endl;
  1623
	cout << "DEBUG initStripChart(): strip chart #" << dec << (int)id <<
  1624
		", X1=" << (int)x1 << ", Y1=" << (int)y1 << ", X2=" << (int)x2 <<
  1625
		", Y2=" << (int)y2 << endl;
1585 1626
#endif /* #ifndef NDEBUG */
1586 1627

                                        
1587  
    int message[] = {CMD_INIT,
1588  
                     CMD_INITIALIZE_STRIP_CHART,
1589  
                     id,
1590  
                     x1,
1591  
                     y1,
1592  
                     x2,
1593  
                     y2,
1594  
                     EOF};
1595  
    send(&message[0]);
  1628
	int message[] = {CMD_INIT,
  1629
	                 CMD_INITIALIZE_STRIP_CHART,
  1630
	                 id,
  1631
	                 x1,
  1632
	                 y1,
  1633
	                 x2,
  1634
	                 y2,
  1635
	                 EOF};
  1636
	send(&message[0]);
1596 1637

                                        
1597  
    return false;
  1638
	return false;
1598 1639

                                        
1599 1640
} /* initStripChart() */
1600 1641

                                        
1602 1643
                            unsigned char id)
1603 1644
{
1604 1645

                                        
1605  
    if (id > 6)
1606  
    {
1607  
        cerr << "ERROR initStripChart(): id should be within 0-6" << endl;
1608  
        return true;
1609  
    }
  1646
	if (id > 6)
  1647
	{
  1648
		cerr << "ERROR initStripChart(): id should be within 0-6" << endl;
  1649
		return true;
  1650
	}
1610 1651

                                        
1611 1652

                                        
1612 1653
#ifndef NDEBUG
1613  
    cout << "DEBUG shiftStripChart(): strip chart #" << dec << (int)id << ", shifted";
1614  
    if (!direction)
1615  
    {
1616  
        cout << "left";
1617  
    }
1618  
    else
1619  
    {
1620  
        cout << "right";
1621  
    }
1622  
    cout << endl;
  1654
	cout << "DEBUG shiftStripChart(): strip chart #" << dec << (int)id <<;
  1655
		", shifted";
  1656
	if (!direction)
  1657
	{
  1658
		cout << "left";
  1659
	}
  1660
	else
  1661
	{
  1662
		cout << "right";
  1663
	}
  1664
	cout << endl;
1623 1665
#endif /* #ifndef NDEBUG */
1624 1666

                                        
1625  
    unsigned char ref = id + direction * 128;
  1667
	unsigned char ref = id + direction * 128;
1626 1668

                                        
1627  
    int message[] = {CMD_INIT,
1628  
                     CMD_SHIFT_STRIP_CHART,
1629  
                     ref,
1630  
                     EOF};
1631  
    send(&message[0]);
  1669
	int message[] = {CMD_INIT,
  1670
	                 CMD_SHIFT_STRIP_CHART,
  1671
	                 ref,
  1672
	                 EOF};
  1673
	send(&message[0]);
1632 1674

                                        
1633  
    return false;
  1675
	return false;
1634 1676

                                        
1635 1677
} /* shiftStripChart() */
1636 1678

                                        
1638 1680
                   bool state)
1639 1681
{
1640 1682

                                        
1641  
    if (id == 0 || id > 6)
1642  
    {
1643  
        cerr << "ERROR setGpo(): id should be within 1-6" << endl;
1644  
        return true;
1645  
    }
  1683
	if (id == 0 || id > 6)
  1684
	{
  1685
		cerr << "ERROR setGpo(): id should be within 1-6" << endl;
  1686
		return true;
  1687
	}
1646 1688

                                        
1647  
    if (!state)
1648  
    {
  1689
	if (!state)
  1690
	{
1649 1691
#ifndef NDEBUG
1650  
        cout << "DEBUG setGpo(): GPO #" << dec << (int)id << ", off" << endl;
  1692
		cout &lt;< "DEBUG setGpo(): GPO #" << dec << (int)id << ", off" << endl;
1651 1693
#endif /* #ifndef NDEBUG */
1652 1694

                                        
1653  
        int message[] = {CMD_INIT,
1654  
                         CMD_GPO_OFF,
1655  
                         id,
1656  
                         EOF};
1657  
        send(&message[0]);
1658  
    }
1659  
    else
1660  
    {
  1695
		int message[] = {CMD_INIT,
  1696
		                 CMD_GPO_OFF,
  1697
		                 id,
  1698
		                 EOF};
  1699
		send(&message[0]);
  1700
	}
  1701
	else
  1702
	{
1661 1703
#ifndef NDEBUG
1662  
        cout << "DEBUG setGpo(): GPO #" << dec << (int)id << ", on" << endl;
  1704
		cout &lt;< "DEBUG setGpo(): GPO #" << dec << (int)id << ", on" << endl;
1663 1705
#endif /* #ifndef NDEBUG */
1664 1706

                                        
1665  
        int message[] = {CMD_INIT,
1666  
                         CMD_GPO_ON,
1667  
                         id,
1668  
                         EOF};
1669  
        send(&message[0]);
1670  
    }
  1707
		int message[] = {CMD_INIT,
  1708
		                 CMD_GPO_ON,
  1709
		                 id,
  1710
		                 EOF};
  1711
		send(&message[0]);
  1712
	}
1671 1713

                                        
1672  
    return false;
  1714
	return false;
1673 1715

                                        
1674 1716
} /* setGpo() */
1675 1717

                                        
1677 1719
                   unsigned char state)
1678 1720
{
1679 1721

                                        
1680  
    if (id == 0 || id > 3)
1681  
    {
1682  
        cerr << "ERROR setLed(): id should be within 1-3" << endl;
1683  
        return true;
1684  
    };
  1722
	if (id == 0 || id > 3)
  1723
	{
  1724
		cerr << "ERROR setLed(): id should be within 1-3" << endl;
  1725
		return true;
  1726
	};
1685 1727

                                        
1686  
    if (state > 3)
1687  
    {
1688  
        cerr << "ERROR setLed(): state should be within 0-3" << endl;
1689  
        return true;
1690  
    }
  1728
	if (state > 3)
  1729
	{
  1730
		cerr << "ERROR setLed(): state should be within 0-3" << endl;
  1731
		return true;
  1732
	}
1691 1733

                                        
1692 1734
#ifndef NDEBUG
1693  
    cout << "DEBUG setLed(): ";
1694  
    switch (id)
1695  
    {
1696  
        case 1:
1697  
        {
1698  
            cout << "top LED";
1699  
            break;
1700  
        }
  1735
	cout << "DEBUG setLed(): ";
  1736
	switch (id)
  1737
	{
  1738
		case 1:
  1739
		{
  1740
			cout << "top LED";
  1741
			break;
  1742
		}
1701 1743

                                        
1702  
        case 2:
1703  
        {
1704  
            cout << "middle LED";
1705  
            break;
1706  
        }
  1744
		case 2:
  1745
		{
  1746
			cout << "middle LED";
  1747
			break;
  1748
		}
1707 1749

                                        
1708  
        case 3:
1709  
        {
1710  
            cout << "bottom LED";
1711  
            break;
1712  
        }
1713  
    } /* swicth(id) */
1714  
    cout << ", ";
  1750
		case 3:
  1751
		{
  1752
			cout << "bottom LED";
  1753
			break;
  1754
		}
  1755
	} /* swicth(id) */
  1756
	cout << ", ";
1715 1757
#endif /* #ifndef NDEBUG */
1716 1758

                                        
1717  
    switch (state)
1718  
    {
1719  
        case 0:
1720  
        {
  1759
	switch (state)
  1760
	{
  1761
		case 0:
  1762
		{
1721 1763
#ifndef NDEBUG
1722  
            cout << "yellow" << endl;
  1764
			cout << "yellow" << endl;
1723 1765
#endif /* #ifndef NDEBUG */
1724 1766

                                        
1725  
            setGpo(id * 2 - 1,
1726  
                   0);
1727  
            setGpo(id * 2,
1728  
                   0);
1729  
            break;
1730  
        }
  1767
			setGpo(id * 2 - 1,
  1768
			       0);
  1769
			setGpo(id * 2,
  1770
			       0);
  1771
			break;
  1772
		}
1731 1773

                                        
1732  
        case 1:
1733  
        {
  1774
		case 1:
  1775
		{
1734 1776
#ifndef NDEBUG
1735  
            cout << "green" << endl;
  1777
			cout << "green" << endl;
1736 1778
#endif /* #ifndef NDEBUG */
1737 1779

                                        
1738  
            setGpo(id * 2 - 1,
1739  
                   1);
1740  
            setGpo(id * 2,
1741  
                   0);
1742  
            break;
1743  
        }
  1780
			setGpo(id * 2 - 1,
  1781
			       1);
  1782
			setGpo(id * 2,
  1783
			       0);
  1784
			break;
  1785
		}
1744 1786

                                        
1745  
        case 2:
1746  
        {
  1787
		case 2:
  1788
		{
1747 1789
#ifndef NDEBUG
1748  
            cout << "red" << endl;
  1790
			cout << "red" << endl;
1749 1791
#endif /* #ifndef NDEBUG */
1750 1792

                                        
1751  
            setGpo(id * 2 - 1,
1752  
                   0);
1753  
            setGpo(id * 2,
1754  
                   1);
1755  
            break;
1756  
        }
  1793
			setGpo(id * 2 - 1,
  1794
			       0);
  1795
			setGpo(id * 2,
  1796
			       1);
  1797
			break;
  1798
		}
1757 1799

                                        
1758  
        case 3:
1759  
        {
  1800
		case 3:
  1801
		{
1760 1802
#ifndef NDEBUG
1761  
            cout << "off" << endl;
  1803
			cout << "off" << endl;
1762 1804
#endif /* #ifndef NDEBUG */
1763 1805

                                        
1764  
            setGpo(id * 2 - 1,
1765  
                   1);
1766  
            setGpo(id * 2,
1767  
                   1);
1768  
            break;
1769  
        }
1770  
    } /* switch (state)*/
  1806
			setGpo(id * 2 - 1,
  1807
			       1);
  1808
			setGpo(id * 2,
  1809
			       1);
  1810
			break;
  1811
		}
  1812
	} /* switch (state)*/
1771 1813

                                        
1772  
    return false;
  1814
	return false;
1773 1815

                                        
1774 1816
} /* setLed() */
1775 1817

                                        
1776 1818
bool Moglk::ledYellow(unsigned char id)
1777 1819
{
1778  
    if (id == 0 || id > 3)
1779  
    {
1780  
        cerr << "ERROR ledYellow(): id should be within 1-3" << endl;
1781  
        return true;
1782  
    }
  1820
	if (id == 0 || id > 3)
  1821
	{
  1822
		cerr << "ERROR ledYellow(): id should be within 1-3" << endl;
  1823
		return true;
  1824
	}
1783 1825

                                        
1784  
#ifndef NDEBUG
1785  
    cout << "DEBUG ledYellow(): ";
1786  
    switch (id)
1787  
    {
1788  
        case 1:
1789  
        {
1790  
            cout << "top LED";
1791  
            break;
1792  
        }
  1826
	#ifndef NDEBUG
  1827
	cout << "DEBUG ledYellow(): ";
  1828
	switch (id)
  1829
	{
  1830
		case 1:
  1831
		{
  1832
			cout << "top LED";
  1833
			break;
  1834
		}
1793 1835

                                        
1794  
        case 2:
1795  
        {
1796  
            cout << "middle LED";
1797  
            break;
1798  
        }
  1836
		case 2:
  1837
		{
  1838
			cout << "middle LED";
  1839
			break;
  1840
		}
1799 1841

                                        
1800  
        case 3:
1801  
        {
1802  
            cout << "bottom LED";
1803  
            break;
1804  
        }
1805  
    } /* switch(id) */
1806  
    cout << endl;
  1842
		case 3:
  1843
		{
  1844
			cout << "bottom LED";
  1845
			break;
  1846
		}
  1847
	} /* switch(id) */
  1848
	cout << endl;
1807 1849
#endif /* #ifndef NDEBUG */
1808 1850

                                        
1809  
    setLed(id,
1810  
           0);
  1851
	setLed(id,
  1852
		   0);
1811 1853

                                        
1812  
    return false;
  1854
	return false;
1813 1855

                                        
1814 1856
} /* ledYellow */
1815 1857

                                        
1816 1858
bool Moglk::ledGreen(unsigned char id)
1817 1859
{
1818  
    if (id == 0 || id > 3)
1819  
    {
1820  
        cerr << "ERROR ledGreen(): id should be within 1-3" << endl;
1821  
        return true;
1822  
    }
  1860
	if (id == 0 || id > 3)
  1861
	{
  1862
		cerr << "ERROR ledGreen(): id should be within 1-3" << endl;
  1863
		return true;
  1864
	}
1823 1865

                                        
1824 1866
#ifndef NDEBUG
1825  
    cout << "DEBUG ledGreen(): ";
1826  
    switch (id)
1827  
    {
1828  
        case 1:
1829  
        {
1830  
            cout << "top LED";
1831  
            break;
1832  
        }
  1867
	cout << "DEBUG ledGreen(): ";
  1868
	switch (id)
  1869
	{
  1870
		case 1:
  1871
		{
  1872
			cout << "top LED";
  1873
			break;
  1874
		}
1833 1875

                                        
1834  
        case 2:
1835  
        {
1836  
            cout << "middle LED";
1837  
            break;
1838  
        }
  1876
		case 2:
  1877
		{
  1878
			cout << "middle LED";
  1879
			break;
  1880
		}
1839 1881

                                        
1840  
        case 3:
1841  
        {
1842  
            cout << "bottom LED";
1843  
            break;
1844  
        }
1845  
    } /* switch(id) */
1846  
    cout << endl;
  1882
		case 3:
  1883
		{
  1884
			cout << "bottom LED";
  1885
			break;
  1886
		}
  1887
	} /* switch(id) */
  1888
	cout << endl;
1847 1889
#endif /* #ifndef NDEBUG */
1848 1890

                                        
1849  
    setLed(id,
1850  
           1);
  1891
	setLed(id,
  1892
		   1);
1851 1893

                                        
1852  
    return false;
  1894
	return false;
1853 1895

                                        
1854 1896
} /* ledGreen*/
1855 1897

                                        
1856 1898
bool Moglk::ledRed(unsigned char id)
1857 1899
{
1858  
    if (id == 0 || id > 3)
1859  
    {
1860  
        cerr << "ERROR ledRed(): id should be within 1-3" << endl;
1861  
        return true;
1862  
    }
  1900
	if (id == 0 || id > 3)
  1901
	{
  1902
		cerr << "ERROR ledRed(): id should be within 1-3" << endl;
  1903
		return true;
  1904
	}
1863 1905

                                        
1864 1906
#ifndef NDEBUG
1865  
    cout << "DEBUG ledRed(): ";
1866  
    switch (id)
1867  
    {
1868  
        case 1:
1869  
        {
1870  
            cout << "top LED";
1871  
            break;
1872  
        }
  1907
	cout << "DEBUG ledRed(): ";
  1908
	switch (id)
  1909
	{
  1910
		case 1:
  1911
		{
  1912
			cout << "top LED";
  1913
			break;
  1914
		}
1873 1915

                                        
1874  
        case 2:
1875  
        {
1876  
            cout << "middle LED";
1877  
            break;
1878  
        }
  1916
		case 2:
  1917
		{
  1918
			cout << "middle LED";
  1919
			break;
  1920
		}
1879 1921

                                        
1880  
        case 3:
1881  
        {
1882  
            cout << "bottom LED";
1883  
            break;
1884  
        }
1885  
    } /* switch(id) */
1886  
    cout << endl;
  1922
		case 3:
  1923
		{
  1924
			cout << "bottom LED";
  1925
			break;
  1926
		}
  1927
	} /* switch(id) */
  1928
	cout << endl;
1887 1929
#endif /* #ifndef NDEBUG */
1888 1930

                                        
1889  
    setLed(id,
1890  
           2);
  1931
	setLed(id,
  1932
		   2);
1891 1933

                                        
1892  
    return false;
  1934
	return false;
1893 1935

                                        
1894 1936
} /* ledRed */
1895 1937

                                        
1896 1938
bool Moglk::ledOff(unsigned char id)
1897 1939
{
1898  
    if (id == 0 || id > 3)
1899  
    {
1900  
        cerr << "ERROR ledOff(): id should be within 1-3" << endl;
1901  
        return true;
1902  
    }
  1940
	if (id == 0 || id > 3)
  1941
	{
  1942
		cerr << "ERROR ledOff(): id should be within 1-3" << endl;
  1943
		return true;
  1944
	}
1903 1945

                                        
1904 1946
#ifndef NDEBUG
1905  
    cout << "DEBUG ledOff(): ";
1906  
    switch (id)
1907  
    {
1908  
        case 1:
1909  
        {
1910  
            cout << "top LED";
1911  
            break;
1912  
        }
  1947
	cout << "DEBUG ledOff(): ";
  1948
	switch (id)
  1949
	{
  1950
		case 1:
  1951
		{
  1952
			cout << "top LED";
  1953
			break;
  1954
		}
1913 1955

                                        
1914  
        case 2:
1915  
        {
1916  
            cout << "middle LED";
1917  
            break;
1918  
        }
  1956
		case 2:
  1957
		{
  1958
			cout << "middle LED";
  1959
			break;
  1960
		}
1919 1961

                                        
1920  
        case 3:
1921  
        {
1922  
            cout << "bottom LED";
1923  
            break;
1924  
        }
1925  
    } /* switch(id) */
1926  
    cout << endl;
  1962
		case 3:
  1963
		{
  1964
			cout << "bottom LED";
  1965
			break;
  1966
		}
  1967
	} /* switch(id) */
  1968
	cout << endl;
1927 1969
#endif /* #ifndef NDEBUG */
1928 1970

                                        
1929  
    setLed(id,
1930  
           3);
  1971
	setLed(id,
  1972
		   3);
1931 1973

                                        
1932  
    return false;
  1974
	return false;
1933 1975

                                        
1934 1976
} /* ledOff */
1935 1977

                                        
1937 1979
                       bool state)
1938 1980
{
1939 1981

                                        
1940  
    if (id == 0 || id > 6)
1941  
    {
1942  
        cerr << "ERROR startupGpo(): id should be within 1-6" << endl;
1943  
        return true;
1944  
    }
  1982
	if (id == 0 || id > 6)
  1983
	{
  1984
		cerr << "ERROR startupGpo(): id should be within 1-6" << endl;
  1985
		return true;
  1986
	}
1945 1987

                                        
1946 1988
#ifndef NDEBUG
1947  
    cout << "DEBUG startupGpo(): GPO #" << dec << (int)id << ", ";
1948  
    if (!state)
1949  
    {
1950  
        cout << "off";
1951  
    }
1952  
    else
1953  
    {
1954  
        cout << "on";
1955  
    }
1956  
    cout << endl;
  1989
	cout << "DEBUG startupGpo(): GPO #" << dec << (int)id << ", ";
  1990
	if (!state)
  1991
	{
  1992
		cout << "off";
  1993
	}
  1994
	else
  1995
	{
  1996
		cout << "on";
  1997
	}
  1998
	cout << endl;
1957 1999
#endif /* #ifndef NDEBUG */
1958 2000

                                        
1959  
    int message[] = {CMD_INIT,
1960  
                     CMD_STARTUP_GPO_STATE,
1961  
                     id,
1962  
                     state,
1963  
                     EOF};
1964  
    send(&message[0]);
  2001
	int message[] = {CMD_INIT,
  2002
	                 CMD_STARTUP_GPO_STATE,
  2003
	                 id,
  2004
	                 state,
  2005
	                 EOF};
  2006
	send(&message[0]);
1965 2007

                                        
1966  
    return false;
  2008
	return false;
1967 2009

                                        
1968 2010
} /* startupGpo() */
1969 2011

                                        
1971 2013
{
1972 2014

                                        
1973 2015
#ifndef NDEBUG
1974  
    cout << "DEBUG setAutoTxKey(): ";
  2016
	cout << "DEBUG setAutoTxKey(): ";
1975 2017
#endif /* #ifndef NDEBUG */
1976 2018

                                        
1977  
    if (!state)
1978  
    {
  2019
	if (!state)
  2020
	{
1979 2021
#ifndef NDEBUG
1980  
        cout << "off" << endl;
  2022
		cout &lt;< "off" << endl;
1981 2023
#endif /* #ifndef NDEBUG */
1982 2024

                                        
1983  
        int message[] = {CMD_INIT,
1984  
                         CMD_AUTO_TRANSMIT_KEY_OFF,
1985  
                         EOF};
1986  
        send(&message[0]);
1987  
    }
1988  
    else
1989  
    {
  2025
		int message[] = {CMD_INIT,
  2026
		                 CMD_AUTO_TRANSMIT_KEY_OFF,
  2027
		                 EOF};
  2028
		send(&message[0]);
  2029
	}
  2030
	else
  2031
	{
1990 2032
#ifndef NDEBUG
1991  
       cout << "on" << endl;
  2033
		   cout << "on" << endl;
1992 2034
#endif /* #ifndef NDEBUG */
1993 2035

                                        
1994  
       int message[] = {CMD_INIT,
1995  
                        CMD_AUTO_TRANSMIT_KEY_ON,
1996  
                        EOF};
1997  
       send(&message[0]);
1998  
    }
  2036
		int message[] = {CMD_INIT,
  2037
		                 CMD_AUTO_TRANSMIT_KEY_ON,
  2038
		                 EOF};
  2039
		send(&message[0]);
  2040
	}
1999 2041

                                        
2000 2042
} /* setAutotxKey() */
2001 2043

                                        
2002 2044
bool Moglk::setBacklight(bool state,
2003 2045
                         unsigned char time)
2004 2046
{
2005  
    if (time > 90)
2006  
    {
2007  
        cerr << "ERROR setBacklight(): time must be less than 90 minutes" << endl;
2008  
        return true;
2009  
    }
  2047
	if (time > 90)
  2048
	{
  2049
		cerr << "ERROR setBacklight(): " <<
  2050
			"time must be less than 90 minutes" << endl;
  2051
		return true;
  2052
	}
2010 2053

                                        
2011 2054
#ifndef NDEBUG
2012  
    cout << "DEBUG setBacklight(): ";
  2055
	cout << "DEBUG setBacklight(): ";
2013 2056
#endif /* #ifndef NDEBUG */
2014 2057

                                        
2015  
    if (!state)
2016  
    {
  2058
	if (!state)
  2059
	{
2017 2060
#ifndef NDEBUG
2018  
        cout << "off" << endl;
  2061
		cout &lt;< "off" << endl;
2019 2062
#endif /* #ifndef NDEBUG */
2020  
        if (time)
2021  
        {
2022  
            clog << "WARNING setBacklight(): unused time value only available for set backlight on" << endl;
2023  
        };
  2063
		if (time)
  2064
		{
  2065
			clog << "WARNING setBacklight(): " <<
  2066
				"unused time value only available for set backlight on" << endl;
  2067
		};
2024 2068

                                        
2025  
        int message[] = {CMD_INIT,
2026  
                         CMD_DISPLAY_OFF,
2027  
                         EOF};
2028  
        send(&message[0]);
2029  
    }
2030  
    else
2031  
    {
  2069
		int message[] = {CMD_INIT,
  2070
		                 CMD_DISPLAY_OFF,
  2071
		                 EOF};
  2072
		send(&message[0]);
  2073
	}
  2074
	else
  2075
	{
2032 2076
#ifndef NDEBUG
2033  
        cout << "on in " << dec << (int)time << " minute(s)"<< endl;
  2077
		cout &lt;< "on in " << dec << (int)time << " minute(s)"<< endl;
2034 2078
#endif /* #ifndef NDEBUG */
2035 2079

                                        
2036  
        int message[] = {CMD_INIT,
2037  
                         CMD_DISPLAY_ON,
2038  
                         time,
2039  
                         EOF};
2040  
        send(&message[0]);
2041  
    }
  2080
		int message[] = {CMD_INIT,
  2081
		                 CMD_DISPLAY_ON,
  2082
		                 time,
  2083
		                 EOF};
  2084
		send(&message[0]);
  2085
	}
2042 2086

                                        
2043  
    return false;
  2087
	return false;
2044 2088

                                        
2045 2089
} /* setBacklight() */
2046 2090

                                        
2048 2092
{
2049 2093

                                        
2050 2094
#ifndef NDEBUG
2051  
    cout << "DEBUG clearKeyBuffer()" << endl;
  2095
	cout << "DEBUG clearKeyBuffer()" << endl;
2052 2096
#endif /* #ifndef NDEBUG */
2053 2097

                                        
2054  
    int message[] = {CMD_INIT,
2055  
                     CMD_CLEAR_KEY_BUFFER,
2056  
                     EOF};
2057  
    send(&message[0]);
  2098
	int message[] = {CMD_INIT,
  2099
	                 CMD_CLEAR_KEY_BUFFER,
  2100
	                 EOF};
  2101
	send(&message[0]);
2058 2102

                                        
2059 2103
} /* clearKeyBuffer() */
2060 2104

                                        
2061 2105
void Moglk::setDebounce(unsigned char time)
2062 2106
{
2063 2107
#ifndef NDEBUG
2064  
    cout << "DEBUG setDebounce(): " << dec << (int)time * 8 << "ms" << endl;
  2108
	cout << "DEBUG setDebounce(): " << dec << (int)time * 8 << "ms" << endl;
2065 2109
#endif /* #ifndef NDEBUG */
2066 2110

                                        
2067  
    int message[] = {CMD_INIT,
2068  
                     CMD_DEBOUNCE_TIME,
2069  
                     time,
2070  
                     EOF};
2071  
    send(&message[0]);
  2111
	int message[] = {CMD_INIT,
  2112
	                 CMD_DEBOUNCE_TIME,
  2113
	                 time,
  2114
	                 EOF};
  2115
	send(&message[0]);
2072 2116

                                        
2073 2117

                                        
2074 2118
} /* setDebounce() */
2076 2120
void Moglk::setAutoRepeat(bool mode)
2077 2121
{
2078 2122
#ifndef NDEBUG
2079  
    cout << "DEBUG setAutoRepeat(): ";
2080  
    if (!mode)
2081  
    {
2082  
        cout << "resend key";
2083  
    }
2084  
    else
2085  
    {
2086  
        cout << "key up/key down";
2087  
    }
2088  
    cout << endl;
  2123
	cout << "DEBUG setAutoRepeat(): ";
  2124
	if (!mode)
  2125
	{
  2126
		cout << "resend key";
  2127
	}
  2128
	else
  2129
	{
  2130
		cout << "key up/key down";
  2131
	}
  2132
	cout << endl;
2089 2133
#endif /* #ifndef NDEBUG */
2090 2134

                                        
2091  
    int message[] = {CMD_INIT,
2092  
                     CMD_AUTO_REPEAT_MODE,
2093  
                     mode,
2094  
                     EOF};
2095  
    send(&message[0]);
  2135
	int message[] = {CMD_INIT,
  2136
	                 CMD_AUTO_REPEAT_MODE,
  2137
	                 mode,
  2138
	                 EOF};
  2139
	send(&message[0]);
2096 2140

                                        
2097 2141
} /* setAutoRepeat() */
2098 2142

                                        
2099 2143
void Moglk::autoRepeatOff(void)
2100 2144
{
2101 2145
#ifndef NDEBUG
2102  
    cout << "DEBUG autoRepeatOff()" << endl;
  2146
	cout << "DEBUG autoRepeatOff()" << endl;
2103 2147
#endif /* #ifndef NDEBUG */
2104 2148

                                        
2105  
    int message[] = {CMD_INIT,
2106  
                     CMD_AUTO_REPEAT_OFF,
2107  
                     EOF};
2108  
    send(&message[0]);
  2149
	int message[] = {CMD_INIT,
  2150
	                 CMD_AUTO_REPEAT_OFF,
  2151
	                 EOF};
  2152
	send(&message[0]);
2109 2153

                                        
2110 2154
} /* autoRepeatOff() */
2111 2155

                                        
2112 2156
void Moglk::setBrightness(unsigned char value)
2113 2157
{
2114 2158
#ifndef NDEBUG
2115  
    cout << "DEBUG setBrightness(): " << dec << (int)value << endl;
  2159
	cout << "DEBUG setBrightness(): " << dec << (int)value << endl;
2116 2160
#endif /* #ifndef NDEBUG */
2117 2161

                                        
2118  
    int message[] = {CMD_INIT,
2119  
                     CMD_BRIGHTNESS,
2120  
                     value,
2121  
                     EOF};
2122  
    send(&message[0]);
  2162
	int message[] = {CMD_INIT,
  2163
	                 CMD_BRIGHTNESS,
  2164
	                 value,
  2165
	                 EOF};
  2166
	send(&message[0]);
2123 2167

                                        
2124 2168
} /* setBrightness() */
2125 2169

                                        
2126 2170
void Moglk::setDefaultBrightness(unsigned char value)
2127 2171
{
2128 2172
#ifndef NDEBUG
2129  
    cout << "DEBUG setDefaultBrightness(): " << dec << (int)value << endl;
  2173
	cout << "DEBUG setDefaultBrightness(): " << dec << (int)value << endl;
2130 2174
#endif /* #ifndef NDEBUG */
2131 2175

                                        
2132  
    int message[] = {CMD_INIT,
2133  
                     CMD_DEFAULT_BRIGHTNESS,
2134  
                     value,
2135  
                     EOF};
2136  
    send(&message[0]);
  2176
	int message[] = {CMD_INIT,
  2177
	                 CMD_DEFAULT_BRIGHTNESS,
  2178
	                 value,
  2179
	                 EOF};
  2180
	send(&message[0]);
2137 2181

                                        
2138 2182
} /* setDefaultBrightness() */
2139 2183

                                        
2140 2184
void Moglk::setContrast(unsigned char value)
2141 2185
{
2142 2186
#ifndef NDEBUG
2143  
    cout << "DEBUG setContrast(): " << dec << (int)value << endl;
  2187
	cout << "DEBUG setContrast(): " << dec << (int)value << endl;
2144 2188
#endif /* #ifndef NDEBUG */
2145 2189

                                        
2146  
    int message[] = {CMD_INIT,
2147  
                     CMD_CONTRAST,
2148  
                     value,
2149  
                     EOF};
2150  
    send(&message[0]);
  2190
	int message[] = {CMD_INIT,
  2191
	                 CMD_CONTRAST,
  2192
	                 value,
  2193
	                 EOF};
  2194
	send(&message[0]);
2151 2195

                                        
2152 2196
} /* setContrast() */
2153 2197

                                        
2154 2198
void Moglk::setDefaultContrast(unsigned char value)
2155 2199
{
2156 2200
#ifndef NDEBUG
2157  
    cout << "DEBUG setDefaultContrast(): " << dec << (int)value << endl;
  2201
	cout << "DEBUG setDefaultContrast(): " << dec << (int)value << endl;
2158 2202
#endif /* #ifndef NDEBUG */
2159 2203

                                        
2160  
    int message[] = {CMD_INIT,
2161  
                     CMD_DEFAULT_CONTRAST,
2162  
                     value,
2163  
                     EOF};
2164  
    send(&message[0]);
  2204
	int message[] = {CMD_INIT,
  2205
	                 CMD_DEFAULT_CONTRAST,
  2206
	                 value,
  2207
	                 EOF};
  2208
	send(&message[0]);
2165 2209

                                        
2166 2210
} /* setDefaultContrast() */
2167 2211

                                        
2168 2212
void Moglk::wipeFs(void)
2169 2213
{
2170 2214
#ifndef NDEBUG
2171  
    cout << "DEBUG wipeFs()" << endl;
  2215
	cout << "DEBUG wipeFs()" << endl;
2172 2216
#endif /* #ifndef NDEBUG */
2173 2217

                                        
2174  
    int message[] = {CMD_INIT,
2175  
                     CMD_WIPE_FILESYSTEM,
2176  
                     EOF};
2177  
    send(&message[0]);
  2218
	int message[] = {CMD_INIT,
  2219
	                 CMD_WIPE_FILESYSTEM,
  2220
	                 EOF};
  2221
	send(&message[0]);
2178 2222

                                        
2179 2223
} /* wipeFs() */
2180 2224

                                        
2181 2225
unsigned short int Moglk::getFreeSpace(void)
2182 2226
{
2183 2227
#ifndef NDEBUG
2184  
    cout << "DEBUG getFreeSpace()" << endl;
  2228
	cout << "DEBUG getFreeSpace()" << endl;
2185 2229
#endif /* #ifndef NDEBUG */
2186 2230

                                        
2187  
    int message[] = {CMD_INIT,
2188  
                     CMD_FREE_SPACE,
2189  
                     EOF};
2190  
    send(&message[0]);
  2231
	int message[] = {CMD_INIT,
  2232
	                 CMD_FREE_SPACE,
  2233
	                 EOF};
  2234
	send(&message[0]);
2191 2235

                                        
2192  
    unsigned char size[3];
  2236
	unsigned char size[3];
2193 2237

                                        
2194  
    unsigned int n = 0;
2195  
    while (n < 4)
2196  
    {
2197  
        receive(&size[n]);
2198  
        n++;
2199  
    }
  2238
	unsigned int n = 0;
  2239
	while (n < 4)
  2240
	{
  2241
		receive(&size[n]);
  2242
		n++;
  2243
	}
2200 2244

                                        
2201  
    unsigned short int free_space = size[0] + size[1] * 256 + size[2] * 65536 + size[3] * 16777216;
  2245
	unsigned short int free_space = size[0] + size[1] * 256 + size[2] * 65536
  2246
		+ size[3] * 16777216;
2202 2247

                                        
2203 2248
#ifndef NDEBUG
2204  
    cout << "DEBUG getFreeSpace(): " << dec << free_space << "B" << endl;
  2249
	cout << "DEBUG getFreeSpace(): " << dec << free_space << "B" << endl;
2205 2250
#endif /* #ifndef NDEBUG */
2206 2251

                                        
2207  
    return free_space;
  2252
	return free_space;
2208 2253

                                        
2209 2254
} /* getFreeSpace() */
2210 2255

                                        
2211 2256
void Moglk::setRemember(bool mode)
2212 2257
{
2213 2258
#ifndef NDEBUG
2214  
    cout << "DEBUG setRemember(): ";
2215  
    if (!mode)
2216  
    {
2217  
        cout << "off";
2218  
    }
2219  
    else
2220  
    {
2221  
        cout << "on";
2222  
    }
2223  
    cout << endl;
  2259
	cout << "DEBUG setRemember(): ";
  2260
	if (!mode)
  2261
	{
  2262
		cout << "off";
  2263
	}
  2264
	else
  2265
	{
  2266
		cout << "on";
  2267
	}
  2268
	cout << endl;
2224 2269
#endif /* #ifndef NDEBUG */
2225 2270

                                        
2226  
    int message[] = {CMD_INIT,
2227  
                     CMD_REMEMBER,
2228  
                     mode,
2229  
                     EOF};
2230  
    send(&message[0]);
  2271
	int message[] = {CMD_INIT,
  2272
	                 CMD_REMEMBER,
  2273
	                 mode,
  2274
	                 EOF};
  2275
	send(&message[0]);
2231 2276

                                        
2232 2277
} /* setRemember() */
2233 2278

                                        
2234 2279
void Moglk::setCustomerData(const char * data)
2235 2280
{
2236 2281
#ifndef NDEBUG
2237  
    cout << "DEBUG setCustomerData(): " << data << endl;
  2282
	cout << "DEBUG setCustomerData(): " << data << endl;
2238 2283
#endif /* #ifndef NDEBUG */
2239 2284

                                        
2240  
    int n = 0;
2241  
    int message_length = strlen(data);
2242  
    int message[message_length+1];
2243  
    while (n < message_length+1)
2244  
    {
2245  
        message[n] = *(data + n);
2246  
        n++;
2247  
    }
2248  
    message[n] = EOF;
2249  
    send(&message[0]);
  2285
	int n = 0;
  2286
	int message_length = strlen(data);
  2287
	int message[message_length+1];
  2288
	while (n < message_length+1)
  2289
	{
  2290
		message[n] = *(data + n);
  2291
		n++;
  2292
	}
  2293
	message[n] = EOF;
  2294
	send(&message[0]);
2250 2295

                                        
2251 2296
} /* setCustomerData() */
2252 2297

                                        
2254 2299
void Moglk::getDirectory(void)
2255 2300
{
2256 2301
#ifndef NDEBUG
2257  
    cout << "DEBUG getDirectory()" << endl;
  2302
	cout << "DEBUG getDirectory()" << endl;
2258 2303
#endif /* #ifndef NDEBUG */
2259 2304

                                        
2260  
    int message[] = {CMD_INIT,
2261  
                     CMD_DIRECTORY,
2262  
                     EOF};
2263  
    send(&message[0]);
  2305
	int message[] = {CMD_INIT,
  2306
	                 CMD_DIRECTORY,
  2307
	                 EOF};
  2308
	send(&message[0]);
2264 2309

                                        
2265  
    unsigned char entriesCount;
  2310
	unsigned char entriesCount;
2266 2311

                                        
2267  
    receive(&entriesCount);
  2312
	receive(&entriesCount);
2268 2313

                                        
2269 2314
#ifndef NDEBUG
2270  
    cout << "DEBUG getDirectory(): " << dec << (int)entriesCount << " files" << endl;
  2315
	cout << "DEBUG getDirectory(): " << dec << (int)entriesCount << " files"
  2316
		<< endl;
2271 2317
#endif /* #ifndef NDEBUG */
2272 2318

                                        
2273  
    for (unsigned int i = 0;i < entriesCount;i++)
2274  
    {
2275  
        unsigned char flag;
2276  
        bitset<8> id;
2277  
        unsigned char size_lsb;
2278  
        unsigned char size_msb;
  2319
	for (unsigned int i = 0;i < entriesCount;i++)
  2320
	{
  2321
		unsigned char flag;
  2322
		bitset<8> id;
  2323
		unsigned char size_lsb;
  2324
		unsigned char size_msb;
2279 2325

                                        
2280  
        // Get data
2281  
        receive(&flag);
2282  
        unsigned char * byte_ptr;
2283  
        receive(byte_ptr);
2284  
        id = *byte_ptr;
2285  
        receive(&size_lsb);
2286  
        receive(&size_msb);
  2326
		// Get data
  2327
		receive(&flag);
  2328
		unsigned char * byte_ptr;
  2329
		receive(byte_ptr);
  2330
		id = *byte_ptr;
  2331
		receive(&size_lsb);
  2332
		receive(&size_msb);
2287 2333

                                        
2288  
        // Extract type from id (first bit)
2289  
        bool type = id[7];
2290  
        // Strip type from id (first bit)
2291  
        id[7] = 0;
  2334
		// Extract type from id (first bit)
  2335
		bool type = id[7];
  2336
		// Strip type from id (first bit)
  2337
		id[7] = 0;
2292 2338

                                        
2293 2339
#ifndef NDEBUG
2294  
        cout << "DEBUG getDirectory(): file #" << dec << i << ", ";
2295  
        if (!flag)
2296  
        {
2297  
            cout << "unused" << endl;
2298  
        }
2299  
        else
2300  
        {
  2340
		cout << "DEBUG getDirectory(): file #" << dec << i << ", ";
  2341
		if (!flag)
  2342
		{
  2343
			cout << "unused" << endl;
  2344
		}
  2345
		else
  2346
		{
2301 2347

                                        
2302  
            if (!type)
2303  
            {
2304  
                cout << "font";
2305  
            }
2306  
            else
2307  
            {
2308  
                cout << "bitmap";
2309  
            }
  2348
			if (!type)
  2349
			{
  2350
				cout << "font";
  2351
			}
  2352
			else
  2353
			{
  2354
				cout << "bitmap";
  2355
			}
2310 2356

                                        
2311  
            cout << " #" << id.to_ulong() << ", " << dec << (int)size_lsb + (int)size_msb * 256 << "B" << endl;
2312  
        }
  2357
			cout << " #" << id.to_ulong() << ", " << dec << (int)size_lsb +
  2358
				(int)size_msb * 256 << "B" << endl;
  2359
		}
2313 2360
#endif /* #ifndef NDEBUG */
2314 2361

                                        
2315  
    }
  2362
	}
2316 2363

                                        
2317 2364
} /* getDirectory() */
2318 2365

                                        
2320 2367
                       unsigned char id)
2321 2368
{
2322 2369
#ifndef NDEBUG
2323  
    cout << "DEBUG deleteFile(): ";
2324  
    if (!type)
2325  
    {
2326  
        cout << "font";
2327  
    }
2328  
    else
2329  
    {
2330  
        cout << "bitmap";
2331  
    }
2332  
    cout << " #" << dec << (int)id << endl;
  2370
	cout << "DEBUG deleteFile(): ";
  2371
	if (!type)
  2372
	{
  2373
		cout << "font";
  2374
	}
  2375
	else
  2376
	{
  2377
		cout << "bitmap";
  2378
	}
  2379
	cout << " #" << dec << (int)id << endl;
2333 2380
#endif /* #ifndef NDEBUG */
2334 2381

                                        
2335  
    int message[] = {CMD_INIT,
2336  
                     CMD_DELETE_FILE,
2337  
                     type,
2338  
                     id,
2339  
                     EOF};
2340  
    send(&message[0]);
  2382
	int message[] = {CMD_INIT,
  2383
	                 CMD_DELETE_FILE,
  2384
	                 type,
  2385
	                 id,
  2386
	                 EOF};
  2387
	send(&message[0]);
2341 2388

                                        
2342 2389
} /* deleteFile() */
2343 2390

                                        
2348 2395
if (id)
2349 2396
{
2350 2397
#ifndef NDEBUG
2351  
    cout << "DEBUG downloadFile(): ";
2352  
    if (!type)
2353  
    {
2354  
        cout << "font";
2355  
    }
2356  
    else
2357  
    {
2358  
        cout << "bitmap";
2359  
    }
2360  
    cout << " #" << dec << (int)id << endl;
  2398
	cout << "DEBUG downloadFile(): ";
  2399
	if (!type)
  2400
	{
  2401
		cout << "font";
  2402
	}
  2403
	else
  2404
	{
  2405
		cout << "bitmap";
  2406
	}
  2407
	cout << " #" << dec << (int)id << endl;
2361 2408
#endif /* #ifndef NDEBUG */
2362 2409

                                        
2363  
    int message[] = {CMD_INIT,
2364  
                     CMD_DOWNLOAD_FILE,
2365  
                     type,
2366  
                     id,
2367  
                     EOF};
2368  
    send(&message[0]);
  2410
	int message[] = {CMD_INIT,
  2411
	                 CMD_DOWNLOAD_FILE,
  2412
	                 type,
  2413
	             id,
  2414
	                 EOF};
  2415
	send(&message[0]);
2369 2416

                                        
2370  
    receiveFile(file_ptr);
  2417
	receiveFile(file_ptr);
2371 2418
}
2372 2419
else
2373 2420
{
2374  
    cerr << "ERROR downloadFile(): ID should not be null";
  2421
	cerr << "ERROR downloadFile(): ID should not be null";
2375 2422
}
2376 2423

                                        
2377  
        return(file_ptr);
  2424
	return(file_ptr);
2378 2425

                                        
2379 2426
} /* downloadFile() */
2380 2427

                                        
2384 2431
                     unsigned char new_id)
2385 2432
{
2386 2433
#ifndef NDEBUG
2387  
    cout << "DEBUG moveFile(): ";
2388  
    if (!old_type)
2389  
    {
2390  
        cout << "font";
2391  
    }
2392  
    else
2393  
    {
2394  
        cout << "bitmap";
2395  
    }
2396  
    cout << " #" << dec << (int)old_id << " to ";
2397  
    if (!new_type)
2398  
    {
2399  
        cout << "font";
2400  
    }
2401  
    else
2402  
    {
2403  
        cout << "bitmap";
2404  
    }
2405  
    cout << " #" << dec << (int)new_id << endl;
  2434
	cout << "DEBUG moveFile(): ";
  2435
	if (!old_type)
  2436
	{
  2437
		cout << "font";
  2438
	}
  2439
	else
  2440
	{
  2441
		cout << "bitmap";
  2442
	}
  2443
	cout << " #" << dec << (int)old_id << " to ";
  2444
	if (!new_type)
  2445
	{
  2446
		cout << "font";
  2447
	}
  2448
	else
  2449
	{
  2450
		cout << "bitmap";
  2451
	}
  2452
	cout << " #" << dec << (int)new_id << endl;
2406 2453
#endif /* #ifndef NDEBUG */
2407 2454

                                        
2408  
    int message[] = {CMD_INIT,
2409  
                     CMD_MOVE_FILE,
2410  
                     old_type,
2411  
                     old_id,
2412  
                     new_type,
2413  
                     new_id,
2414  
                     EOF};
2415  
    send(&message[0]);
  2455
	int message[] = {CMD_INIT,
  2456
	                 CMD_MOVE_FILE,
  2457
	                 old_type,
  2458
	                 old_id,
  2459
	                 new_type,
  2460
	                 new_id,
  2461
	                 EOF};
  2462
	send(&message[0]);
2416 2463

                                        
2417 2464
} /* moveFile() */
2418 2465

                                        
2419 2466
//TODO: test!
2420 2467
void Moglk::setLock(bitset<8> level)
2421 2468
{
2422  
    // Bits reserved
2423  
    level[7] = 0;
2424  
    level[6] = 0;
2425  
    level[5] = 0;
  2469
	// Bits reserved
  2470
	level[7] = 0;
  2471
	level[6] = 0;
  2472
	level[5] = 0;
2426 2473

                                        
2427 2474
#ifndef NDEBUG
2428  
    cout << "DEBUG setLock(): ";
2429  
    if (level[4])
2430  
    {
2431  
        cout << "communication locked";
2432  
    }
2433  
    else
2434  
    {
2435  
        cout << "communication unlocked";
2436  
    }
2437  
    cout << ", ";
2438  
    if (level[3])
2439  
    {
2440  
        cout << "settings locked";
2441  
    }
2442  
    else
2443  
    {
2444  
        cout << "settings unlocked";
2445  
    }
2446  
    cout << ", ";
2447  
    if (level[2])
2448  
    {
2449  
        cout << "filesystem locked";
2450  
    }
2451  
    else
2452  
    {
2453  
        cout << "filesystem unlocked";
2454  
    }
2455  
    cout << ", ";
2456  
    if (level[1])
2457  
    {
2458  
        cout << "command locked";
2459  
    }
2460  
    else
2461  
    {
2462  
        cout << "command unlocked";
2463  
    }
2464  
    cout << ", ";
2465  
    if (level[0])
2466  
    {
2467  
        cout << "display locked";
2468  
    }
2469  
    else
2470  
    {
2471  
        cout << "display unlocked";
2472  
    }
2473  
    cout << endl;
  2475
	cout << "DEBUG setLock(): ";
  2476
	if (level[4])
  2477
	{
  2478
		cout << "communication locked";
  2479
	}
  2480
	else
  2481
	{
  2482
		cout << "communication unlocked";
  2483
	}
  2484
	cout << ", ";
  2485
	if (level[3])
  2486
	{
  2487
		cout << "settings locked";
  2488
	}
  2489
	else
  2490
	{
  2491
		cout << "settings unlocked";
  2492
	}
  2493
	cout << ", ";
  2494
	if (level[2])
  2495
	{
  2496
		cout << "filesystem locked";
  2497
	}
  2498
	else
  2499
	{
  2500
		cout << "filesystem unlocked";
  2501
	}
  2502
	cout << ", ";
  2503
	if (level[1])
  2504
	{
  2505
		cout << "command locked";
  2506
	}
  2507
	else
  2508
	{
  2509
		cout << "command unlocked";
  2510
	}
  2511
	cout << ", ";
  2512
	if (level[0])
  2513
	{
  2514
		cout << "display locked";
  2515
	}
  2516
	else
  2517
	{
  2518
		cout << "display unlocked";
  2519
	}
  2520
	cout << endl;
2474 2521
#endif /* #ifndef NDEBUG */
2475 2522

                                        
2476  
    int message[] = {CMD_INIT,
2477  
                     CMD_LOCK_LEVEL,
2478  
                     level.to_ulong(),
2479  
                     EOF};
2480  
    send(&message[0]);
  2523
	int message[] = {CMD_INIT,
  2524
	                 CMD_LOCK_LEVEL,
  2525
	                 level.to_ulong(),
  2526
	                 EOF};
  2527
	send(&message[0]);
2481 2528

                                        
2482 2529
} /* setLock() */
2483 2530

                                        
2484 2531
//TODO: test!
2485 2532
void Moglk::setDefaultLock(bitset<8> level)
2486 2533
{
2487  
    // Bits reserved
2488  
    level[7] = 0;
2489  
    level[6] = 0;
2490  
    level[5] = 0;
  2534
	// Bits reserved
  2535
	level[7] = 0;
  2536
	level[6] = 0;
  2537
	level[5] = 0;
2491 2538

                                        
2492 2539
#ifndef NDEBUG
2493  
    cout << "DEBUG setDefaultLock(): ";
2494  
    if (level[4])
2495  
    {
2496  
        cout << "communication locked";
2497  
    }
2498  
    else
2499  
    {
2500  
        cout << "communication unlocked";
2501  
    }
2502  
    cout << ", ";
2503  
    if (level[3])
2504  
    {
2505  
        cout << "settings locked";
2506  
    }
2507  
    else
2508  
    {
2509  
        cout << "settings unlocked";
2510  
    }
2511  
    cout << ", ";
2512  
    if (level[2])
2513  
    {
2514  
        cout << "filesystem locked";
2515  
    }
2516  
    else
2517  
    {
2518  
        cout << "filesystem unlocked";
2519  
    }
2520  
    cout << ", ";
2521  
    if (level[1])
2522  
    {
2523  
        cout << "command locked";
2524  
    }
2525  
    else
2526  
    {
2527  
        cout << "command unlocked";
2528  
    }
2529  
    cout << ", ";
2530  
    if (level[0])
2531  
    {
2532  
        cout << "display locked";
2533  
    }
2534  
    else
2535  
    {
2536  
        cout << "display unlocked";
2537  
    }
2538  
    cout << endl;
  2540
	cout << "DEBUG setDefaultLock(): ";
  2541
	if (level[4])
  2542
	{
  2543
		cout << "communication locked";
  2544
	}
  2545
	else
  2546
	{
  2547
		cout << "communication unlocked";
  2548
	}
  2549
	cout << ", ";
  2550
	if (level[3])
  2551
	{
  2552
		cout << "settings locked";
  2553
	}
  2554
	else
  2555
	{
  2556
		cout << "settings unlocked";
  2557
	}
  2558
	cout << ", ";
  2559
	if (level[2])
  2560
	{
  2561
		cout << "filesystem locked";
  2562
	}
  2563
	else
  2564
	{
  2565
		cout << "filesystem unlocked";
  2566
	}
  2567
	cout << ", ";
  2568
	if (level[1])
  2569
	{
  2570
		cout << "command locked";
  2571
	}
  2572
	else
  2573
	{
  2574
		cout << "command unlocked";
  2575
	}
  2576
	cout << ", ";
  2577
	if (level[0])
  2578
	{
  2579
		cout << "display locked";
  2580
	}
  2581
	else
  2582
	{
  2583
		cout << "display unlocked";
  2584
	}
  2585
	cout << endl;
2539 2586
#endif /* #ifndef NDEBUG */
2540 2587

                                        
2541  
    int message[] = {CMD_INIT,
2542  
                     CMD_DEFAULT_LOCK_LEVEL,
2543  
                     level.to_ulong(),
2544  
                     EOF};
2545  
    send(&message[0]);
  2588
	int message[] = {CMD_INIT,
  2589
	                 CMD_DEFAULT_LOCK_LEVEL,
  2590
	                 level.to_ulong(),
  2591
	                 EOF};
  2592
	send(&message[0]);
2546 2593

                                        
2547 2594
} /* setDefaultLock() */
2548 2595

                                        
2550 2597
unsigned char Moglk::pollKey(void)
2551 2598
{
2552 2599
#ifndef NDEBUG
2553  
    cout << "DEBUG pollKey()" << endl;
  2600
	cout << "DEBUG pollKey()" << endl;
2554 2601
#endif /* #ifndef NDEBUG */
2555 2602

                                        
2556  
    int message[] = {CMD_INIT,
2557  
                     CMD_POLL_KEY,
2558  
                     EOF};
2559  
    unsigned char key[10] = {0,
2560  
                             0,
2561  
                             0,
2562  
                             0,
2563  
                             0,
2564  
                             0,
2565  
                             0,
2566  
                             0,
2567  
                             0,
2568  
                             0};
  2603
	int message[] = {CMD_INIT,
  2604
	                 CMD_POLL_KEY,
  2605
	                 EOF};
  2606
	unsigned char key[10] = {0,
  2607
	                         0,
  2608
	                         0,
  2609
	                         0,
  2610
	                         0,
  2611
	                         0,
  2612
	                         0,
  2613
	                         0,
  2614
	                         0,
  2615
	                         0};
2569 2616

                                        
2570  
    bitset<8> more = 0x80;
2571  
    unsigned int n = 0;
2572  
    while (more[7])
2573  
    {
2574  
        send(&message[0]);
2575  
        receive(&key[n]);
2576  
        //Get more_key_presses_availables flag
2577  
        more = key[n];
2578  
        // Reset more_key_presses_availables flag to have a pure key descriptor
2579  
        if (more[7])
2580  
        {
2581  
            key[n] = key[n] - 0x80;
2582  
        }
2583  
        n++;
2584  
    }
  2617
	bitset<8> more = 0x80;
  2618
	unsigned int n = 0;
  2619
	while (more[7])
  2620
	{
  2621
		send(&message[0]);
  2622
		receive(&key[n]);
  2623
		//Get more_key_presses_availables flag
  2624
		more = key[n];
  2625
		// Reset more_key_presses_availables flag to have a pure key descriptor
  2626
		if (more[7])
  2627
		{
  2628
			key[n] = key[n] - 0x80;
  2629
		}
  2630
		n++;
  2631
	}
2585 2632

                                        
2586 2633
#ifndef NDEBUG
2587  
    unsigned int i = 0;
2588  
    while (i < n)
2589  
    {
2590  
        cout << "DEBUG pollKey(): ";
2591  
        switch (key[i])
2592  
        {
2593  
            case RET_UP:
2594  
            {
2595  
                cout << "up button pressed" << endl;
2596  
                break;
2597  
            }
  2634
	unsigned int i = 0;
  2635
	while (i < n)
  2636
	{
  2637
		cout << "DEBUG pollKey(): ";
  2638
		switch (key[i])
  2639
		{
  2640
			case RET_UP:
  2641
			{
  2642
				cout << "up button pressed" << endl;
  2643
				break;
  2644
			}
2598 2645

                                        
2599  
            case RET_DOWN:
2600  
            {
2601  
                cout << "down button pressed" << endl;
2602  
                break;
2603  
            }
  2646
			case RET_DOWN:
  2647
			{
  2648
				cout << "down button pressed" << endl;
  2649
				break;
  2650
			}
2604 2651

                                        
2605  
            case RET_LEFT:
2606  
            {
2607  
                cout << "left button pressed" << endl;
2608  
                break;
2609  
            }
  2652
			case RET_LEFT:
  2653
			{
  2654
				cout << "left button pressed" << endl;
  2655
				break;
  2656
			}
2610 2657

                                        
2611  
            case RET_RIGHT:
2612  
            {
2613  
                cout << "right button pressed" << endl;
2614  
                break;
2615  
            }
  2658
			case RET_RIGHT:
  2659
			{
  2660
				cout << "right button pressed" << endl;
  2661
				break;
  2662
			}
2616 2663

                                        
2617  
            case RET_CENTER:
2618  
            {
2619  
                cout << "center button pressed" << endl;
2620  
                break;
2621  
            }
  2664
			case RET_CENTER:
  2665
			{
  2666
				cout << "center button pressed" << endl;
  2667
				break;
  2668
			}
2622 2669

                                        
2623  
            case RET_TOP:
2624  
            {
2625  
                cout << "top button pressed" << endl;
2626  
                break;
2627  
            }
  2670
			case RET_TOP:
  2671
			{
  2672
				cout << "top button pressed" << endl;
  2673
				break;
  2674
			}
2628 2675

                                        
2629  
            case RET_BOTTOM:
2630  
            {
2631  
                cout << "bottom button pressed" << endl;
2632  
                break;
2633  
            }
  2676
			case RET_BOTTOM:
  2677
			{
  2678
				cout << "bottom button pressed" << endl;
  2679
				break;
  2680
			}
2634 2681

                                        
2635  
            case RET_RELEASE_UP:
2636  
            {
2637  
                cout << "up button released" << endl;
2638  
                break;
2639  
            }
  2682
			case RET_RELEASE_UP:
  2683
			{
  2684
				cout << "up button released" << endl;
  2685
				break;
  2686
			}
2640 2687

                                        
2641  
            case RET_RELEASE_DOWN:
2642  
            {
2643  
                cout << "down button released" << endl;
2644  
                break;
2645  
            }
  2688
			case RET_RELEASE_DOWN:
  2689
			{
  2690
				cout << "down button released" << endl;
  2691
				break;
  2692
			}
2646 2693

                                        
2647  
            case RET_RELEASE_LEFT:
2648  
            {
2649  
                cout << "left button released" << endl;
2650  
                break;
2651  
            }
  2694
			case RET_RELEASE_LEFT:
  2695
			{
  2696
				cout << "left button released" << endl;
  2697
				break;
  2698
			}
2652 2699

                                        
2653  
            case RET_RELEASE_RIGHT:
2654  
            {
2655  
                cout << "right button released" << endl;
2656  
                break;
2657  
            }
  2700
			case RET_RELEASE_RIGHT:
  2701
			{
  2702
				cout << "right button released" << endl;
  2703
				break;
  2704
			}
2658 2705

                                        
2659  
            case RET_RELEASE_CENTER:
2660  
            {
2661  
                cout << "center button released" << endl;
2662  
                break;
2663  
            }
  2706
			case RET_RELEASE_CENTER:
  2707
			{
  2708
				cout << "center button released" << endl;
  2709
				break;
  2710
			}
2664 2711

                                        
2665  
            case RET_RELEASE_TOP:
2666  
            {
2667  
                cout << "top button released" << endl;
2668  
                break;
2669  
            }
  2712
			case RET_RELEASE_TOP:
  2713
			{
  2714
				cout << "top button released" << endl;
  2715
				break;
  2716
			}
2670 2717

                                        
2671  
            case RET_RELEASE_BOTTOM:
2672  
            {
2673  
                cout << "bottom button released" << endl;
2674  
                break;
2675  
            }
  2718
			case RET_RELEASE_BOTTOM:
  2719
			{
  2720
				cout << "bottom button released" << endl;
  2721
				break;
  2722
			}
2676 2723

                                        
2677  
            case RET_NO_KEY:
2678  
            {
2679  
                cout << "no key pressed" << endl;
2680  
                break;
2681  
            }
2682  
        } /* switch(key) */
2683  
        i++;
2684  
    };
  2724
			case RET_NO_KEY:
  2725
			{
  2726
				cout << "no key pressed" << endl;
  2727
				break;
  2728
			}
  2729
		} /* switch(key) */
  2730
		i++;
  2731
	};
2685 2732
#endif /* #ifndef NDEBUG */
2686 2733

                                        
2687  
    return key[0];
  2734
	return key[0];
2688 2735

                                        
2689 2736
} /* pollKey() */
2690 2737

                                        
2704 2751
                              unsigned char kdown_down)
2705 2752
{
2706 2753
#ifndef NDEBUG
2707  
    cout << "DEBUG setCustomKeyCodes(): button top key up message " << hex << (int)kup_top << endl;
2708  
    cout << "DEBUG setCustomKeyCodes(): button up key up message " << hex << (int)kup_up << endl;
2709  
    cout << "DEBUG setCustomKeyCodes(): button right key up message " << hex << (int)kup_right << endl;
2710  
    cout << "DEBUG setCustomKeyCodes(): button left key up message " << hex << (int)kup_left << endl;
2711  
    cout << "DEBUG setCustomKeyCodes(): button center key up message " << hex << (int)kup_center << endl;
2712  
    cout << "DEBUG setCustomKeyCodes(): button bottom key up message " << hex << (int)kup_bottom << endl;
2713  
    cout << "DEBUG setCustomKeyCodes(): button down key up message " << hex << (int)kup_down << endl;
2714  
    cout << "DEBUG setCustomKeyCodes(): button top key down message " << hex << (int)kdown_top << endl;
2715  
    cout << "DEBUG setCustomKeyCodes(): button up key down message " << hex << (int)kdown_up << endl;
2716  
    cout << "DEBUG setCustomKeyCodes(): button right key down message " << hex << (int)kdown_right << endl;
2717  
    cout << "DEBUG setCustomKeyCodes(): button left key down message " << hex << (int)kdown_left << endl;
2718  
    cout << "DEBUG setCustomKeyCodes(): button center key down message " << hex << (int)kdown_center << endl;
2719  
    cout << "DEBUG setCustomKeyCodes(): button bottom key down message " << hex << (int)kdown_bottom << endl;
2720  
    cout << "DEBUG setCustomKeyCodes(): button down key down message " << hex << (int)kdown_down << endl;
  2754
	cout << "DEBUG setCustomKeyCodes(): button top key up message " << hex <<
  2755
		(int)kup_top << endl;
  2756
	cout << "DEBUG setCustomKeyCodes(): button up key up message " << hex <<
  2757
		(int)kup_up << endl;
  2758
	cout << "DEBUG setCustomKeyCodes(): button right key up message " << hex <<
  2759
		(int)kup_right << endl;
  2760
	cout << "DEBUG setCustomKeyCodes(): button left key up message " << hex <<
  2761
		(int)kup_left << endl;
  2762
	cout << "DEBUG setCustomKeyCodes(): button center key up message " << hex <<
  2763
		(int)kup_center << endl;
  2764
	cout << "DEBUG setCustomKeyCodes(): button bottom key up message " << hex <<
  2765
		(int)kup_bottom << endl;
  2766
	cout << "DEBUG setCustomKeyCodes(): button down key up message " << hex <<
  2767
		(int)kup_down << endl;
  2768
	cout << "DEBUG setCustomKeyCodes(): button top key down message " << hex <<
  2769
		(int)kdown_top << endl;
  2770
	cout << "DEBUG setCustomKeyCodes(): button up key down message " << hex <<
  2771
		(int)kdown_up << endl;
  2772
	cout << "DEBUG setCustomKeyCodes(): button right key down message " <<
  2773
		hex << (int)kdown_right << endl;
  2774
	cout << "DEBUG setCustomKeyCodes(): button left key down message " << hex <<
  2775
		(int)kdown_left << endl;
  2776
	cout << "DEBUG setCustomKeyCodes(): button center key down message " <<
  2777
		hex << (int)kdown_center << endl;
  2778
	cout << "DEBUG setCustomKeyCodes(): button bottom key down message " <<
  2779
		hex << (int)kdown_bottom << endl;
  2780
	cout << "DEBUG setCustomKeyCodes(): button down key down message " << hex <<
  2781
		(int)kdown_down << endl;
2721 2782
#endif /* #ifndef NDEBUG */
2722 2783

                                        
2723  
    int message[] = {CMD_INIT,
2724  
                     CMD_CUSTOM_KEYPAD_CODES,
2725  
                     kup_top,
2726  
                     kup_up,
2727  
                     kup_right,
2728  
                     kup_left,
2729  
                     kup_center,
2730  
                     0,
2731  
                     kup_bottom,
2732  
                     kup_down,
2733  
                     0,
2734  
                     kdown_top,
2735  
                     kdown_up,
2736  
                     kdown_right,
2737  
                     kdown_left,
2738  
                     kdown_center,
2739  
                     0,
2740  
                     kdown_bottom,
2741  
                     kdown_down,
2742  
                     0,
2743  
                     EOF};
2744  
    send(&message[0]);
  2784
	int message[] = {CMD_INIT,
  2785
	                 CMD_CUSTOM_KEYPAD_CODES,
  2786
	                 kup_top,
  2787
	                 kup_up,
  2788
	                 kup_right,
  2789
	                 kup_left,
  2790
	                 kup_center,
  2791
	                 0,
  2792
	                 kup_bottom,
  2793
	                 kup_down,
  2794
	                 0,
  2795
	                 kdown_top,
  2796
	                 kdown_up,
  2797
	                 kdown_right,
  2798
	                 kdown_left,
  2799
	                 kdown_center,
  2800
	                 0,
  2801
	                 kdown_bottom,
  2802
	                 kdown_down,
  2803
	                 0,
  2804
	                 EOF};
  2805
	send(&message[0]);
2745 2806

                                        
2746 2807
} /* setCustomKeyCodes() */
2747 2808

                                        
2748 2809
int * Moglk::dumpFs(int * file_ptr)
2749 2810
{
2750  
    int message[] = {CMD_INIT,
2751  
                     CMD_DUMP_FS,
2752  
                     EOF};
2753  
    send(&message[0]);
  2811
	int message[] = {CMD_INIT,
  2812
	                 CMD_DUMP_FS,
  2813
	                 EOF};
  2814
	send(&message[0]);
2754 2815

                                        
2755  
    receiveFile(file_ptr);
  2816
	receiveFile(file_ptr);
2756 2817

                                        
2757  
    return file_ptr;
  2818
	return file_ptr;
2758 2819

                                        
2759 2820
} /* dumpFs() */
2760 2821

                                        
2761 2822
int * Moglk::dumpSettings(int * file_ptr)
2762 2823
{
2763  
    int message[] = {CMD_INIT,
2764  
                     CMD_DUMP_SETTINGS,
2765  
                     EOF};
2766  
    send(&message[0]);
  2824
	int message[] = {CMD_INIT,
  2825
	                 CMD_DUMP_SETTINGS,
  2826
	                 EOF};
  2827
	send(&message[0]);
2767 2828

                                        
2768  
    unsigned int file_size = 466;
  2829
	unsigned int file_size = 466;
2769 2830

                                        
2770  
    int file[file_size + 1];
2771  
    file_ptr = &file[0];
  2831
	int file[file_size + 1];
  2832
	file_ptr = &file[0];
2772 2833

                                        
2773  
    unsigned long int i = 0;
2774  
    while (i < (file_size + 1))
2775  
    {
  2834
	unsigned long int i = 0;
  2835
	while (i < (file_size + 1))
  2836
	{
2776 2837
#ifndef NDEBUG
2777  
        cout << "DEBUG receiveFile(): byte #" << dec << i << " : ";
  2838
		cout &lt;< "DEBUG receiveFile(): byte #" << dec << i << " : ";
2778 2839
#endif /* #ifndef NDEBUG */
2779  
        unsigned char * byte_ptr;
2780  
        receive(byte_ptr);
2781  
        file[i] = *byte_ptr;
2782  
        i++;
2783  
    }
2784  
    file[i] = EOF;
  2840
		unsigned char * byte_ptr;
  2841
		receive(byte_ptr);
  2842
		file[i] = *byte_ptr;
  2843
		i++;
  2844
	}
  2845
	file[i] = EOF;
2785 2846

                                        
2786 2847
#ifndef NDEBUG
2787  
    cout << "DEBUG receiveFile(): received file data = ";
2788  
    unsigned long int j = 0;
2789  
    while (file[j] != EOF)
2790  
    {
2791  
        cout << hex << (int)file[j];
2792  
        j++;
2793  
    }
2794  
    cout << endl;
2795  
    cout << "DEBUG receiveFile(): " << dec << j - 1 << "B" << endl;
  2848
	cout << "DEBUG receiveFile(): received file data = ";
  2849
	unsigned long int j = 0;
  2850
	while (file[j] != EOF)
  2851
	{
  2852
		cout << hex << (int)file[j];
  2853
		j++;
  2854
	}
  2855
	cout << endl;
  2856
	cout << "DEBUG receiveFile(): " << dec << j - 1 << "B" << endl;
2796 2857
#endif /* #ifndef NDEBUG */
2797 2858

                                        
2798  
    return file_ptr;
  2859
	return file_ptr;
2799 2860

                                        
2800 2861
} /* dumpSettings() */
2801 2862

                                        
2802  
void Moglk::drawBmp(unsigned char x, unsigned char y, unsigned char width, unsigned char height, int * data_ptr)
  2863
void Moglk::drawBmp(unsigned char x,
  2864
                    unsigned char y,
  2865
                    unsigned char width,
  2866
                    unsigned char height,
  2867
                    int * data_ptr)
2803 2868
{
2804 2869
#ifndef NDEBUG
2805  
    cout << "DEBUG drawBmp(): " << "X=" << dec << (int)x << "px, Y=" << (int)y << "px, " << (int)width << "x" << (int)height << "px" << endl;
  2870
	cout << "DEBUG drawBmp(): " << "X=" << dec << (int)x << "px, Y=" <<
  2871
		(int)y << "px, " << (int)width << "x" << (int)height << "px" << endl;
2806 2872
#endif /* #ifndef NDEBUG */
2807 2873

                                        
2808  
    int message[] = {CMD_INIT,
2809  
                     CMD_DRAW_BMP,
2810  
                     x,
2811  
                     y,
2812  
                     width,
2813  
                     height,
2814  
                     EOF};
2815  
    send(&message[0]);
2816  
    unsigned int n = 0;
2817  
    int value = *(data_ptr + n);
2818  
    while (value != EOF)
2819  
    {
  2874
	int message[] = {CMD_INIT,
  2875
	                 CMD_DRAW_BMP,
  2876
	                 x,
  2877
	                 y,
  2878
	                 width,
  2879
	                 height,
  2880
	                 EOF};
  2881
	send(&message[0]);
  2882
	unsigned int n = 0;
  2883
	int value = *(data_ptr + n);
  2884
	while (value != EOF)
  2885
	{
2820 2886
	int data_message[] = {value,
2821  
                              EOF};
2822  
        send(data_message);
2823  
        n++;
2824  
        value = *(data_ptr + n);
2825  
    }
  2887
	                      EOF};
  2888
	send(data_message);
  2889
	n++;
  2890
	value = *(data_ptr + n);
  2891
	}
2826 2892

                                        
2827 2893
} /* drawBmp() */
2828 2894

                                        
2830 2896
bool Moglk::upload(char * data_ptr)
2831 2897
{
2832 2898
#ifndef NDEBUG
2833  
    cout << "DEBUG upload()"<< endl;
  2899
	cout << "DEBUG upload()"<< endl;
2834 2900
#endif /* #ifndef NDEBUG */
2835 2901

                                        
2836  
  unsigned char reply;
2837  
  int c_message[] = {CMD_CONFIRM,
2838  
                     EOF};
2839  
  int d_message[] = {CMD_DECLINE,
2840  
                     EOF};
  2902
	unsigned char reply;
  2903
	int c_message[] = {CMD_CONFIRM,
  2904
	                   EOF};
  2905
	int d_message[] = {CMD_DECLINE,
  2906
	                   EOF};
2841 2907

                                        
2842 2908
//Upload code goes here
2843 2909

                                        
2850 2916
                       unsigned int size,
2851 2917
                       char * data_ptr)
2852 2918
{
2853  
    int message[] = {CMD_INIT,
2854  
                     CMD_UPLOAD_FONT,
2855  
                     id,
2856  
                     EOF};
2857  
    send(&message[0]);
  2919
	int message[] = {CMD_INIT,
  2920
	                 CMD_UPLOAD_FONT,
  2921
	                 id,
  2922
	                 EOF};
  2923
	send(&message[0]);
2858 2924

                                        
2859  
    upload(data_ptr);
  2925
	upload(data_ptr);
2860 2926

                                        
2861 2927
} /* uploadFont */
2862 2928

                                        
2866 2932
                      char * data_ptr)
2867 2933
{
2868 2934

                                        
2869  
    int message[] = {CMD_INIT,
2870  
                     CMD_UPLOAD_BMP,
2871  
                     id,
2872  
                     EOF};
2873  
    send(&message[0]);
  2935
	int message[] = {CMD_INIT,
  2936
	                 CMD_UPLOAD_BMP,
  2937
	                 id,
  2938
	                 EOF};
  2939
	send(&message[0]);
2874 2940

                                        
2875  
    upload(data_ptr);
  2941
	upload(data_ptr);
2876 2942

                                        
2877 2943
} /* uploadBmp */
2878 2944

                                        
2881 2947
                     char * data_ptr)
2882 2948
{
2883 2949

                                        
2884  
    int message[] = {CMD_INIT,
2885  
                     CMD_UPLOAD_FS,
2886  
                     EOF};
2887  
    send(&message[0]);
  2950
	int message[] = {CMD_INIT,
  2951
	                 CMD_UPLOAD_FS,
  2952
	                 EOF};
  2953
	send(&message[0]);
2888 2954

                                        
2889  
    upload(data_ptr);
  2955
	upload(data_ptr);
2890 2956

                                        
2891 2957
} /* uploadFs */
2892 2958

                                        

 

Old New Code
62 62

                                        
63 63

                                        
64 64
// COMMUNICATION
65  
#define CMD_INIT					0xFE //Done
  65
#define CMD_INIT						0xFE							//Done
66 66
// (Must be issued before any command)
67  
#define CMD_FLOW_CONTROL_ON				0x3A //Done
  67
#define CMD_FLOW_CONTROL_ON				0x3A							//Done
68 68
//										full[0-128]
69 69
//										(Number of bytes before almost full
70 70
//										 0: full)
72 72
//										(Number of bytes before almost empty
73 73
//										 128: empty)
74 74

                                        
75  
#define RET_ALMOST_FULL					0xFE //Done
76  
#define RET_ALMOST_EMPTY				0xFF //Done
  75
#define RET_ALMOST_FULL					0xFE							//Done
  76
#define RET_ALMOST_EMPTY				0xFF							//Done
77 77

                                        
78  
#define CMD_FLOW_CONTROL_OFF			        0x3B //Done
  78
#define CMD_FLOW_CONTROL_OFF			0x3B							//Done
79 79

                                        
80  
#define CMD_BAUD_RATE					0x39 //Done
  80
#define CMD_BAUD_RATE					0x39							//Done
81 81
//										speed[See table below]
82 82

                                        
83  
#define BAUD_RATE_9600					0xCF //Done
84  
#define BAUD_RATE_14400					0x8A //Done
85  
#define BAUD_RATE_19200					0x67 //Done
86  
#define BAUD_RATE_28800					0x44 //Done
87  
#define BAUD_RATE_38400					0x33 //Done
88  
#define BAUD_RATE_57600					0x22 //Done
89  
#define BAUD_RATE_76800					0x19 //Done
90  
#define BAUD_RATE_115200					0x10 //Done
  83
#define BAUD_RATE_9600					0xCF							//Done
  84
#define BAUD_RATE_14400					0x8A							//Done
  85
#define BAUD_RATE_19200					0x67							//Done
  86
#define BAUD_RATE_28800					0x44							//Done
  87
#define BAUD_RATE_38400					0x33							//Done
  88
#define BAUD_RATE_57600					0x22							//Done
  89
#define BAUD_RATE_76800					0x19							//Done
  90
#define BAUD_RATE_115200				0x10							//Done
91 91

                                        
92  
#define BAUD_RATE_DEFAULT				BAUD_RATE_19200 //Done
  92
#define BAUD_RATE_DEFAULT				BAUD_RATE_19200					//Done
93 93

                                        
94  
#define CMD_NON_STANDARD_BAUD_RATE		        0xA4 //Done
  94
#define CMD_NON_STANDARD_BAUD_RATE		0xA4							//Done
95 95
//										speed[12-2047]
96 96
//										(2 bytes,
97 97
//										LSB then MSB,
101 101
//										to communicate)
102 102
/*
103 103
										Formula :
104  
												 CrystalSpeed (16MHz)
  104
										         CrystalSpeed (16MHz)
105 105
										speed = ---------------------  -  1
106  
												  8 x DesiredBaud
  106
										          8 x DesiredBaud
107 107
*/
108 108

                                        
109 109
// FONTS
124 124
*/
125 125
//TODO: implement font file format
126 126

                                        
127  
#define CMD_UPLOAD_FONT					0x24 //
  127
#define CMD_UPLOAD_FONT					0x24							//
128 128
//										fontid
129 129
//										lsbsize
130  
//                                      msbsize
  130
//										msbsize
131 131
//										fontfile
132 132
// (Don't forget to set the new font metrics,
133 133
//  see FILESYSTEM file transfer protocol)
134  
#define CMD_USE_FONT					0x31 //Done
  134
#define CMD_USE_FONT					0x31							//Done
135 135
//										fontid
136  
#define CMD_FONT_METRICS				0x32 //Done
  136
#define CMD_FONT_METRICS				0x32							//Done
137 137
//										lm
138 138
//										(Left Margin: Location in pixels)
139 139
//										tm
145 145
//										srow
146 146
//										(Scroll Row:
147 147
//										Y location of last row in pixels)
148  
#define CMD_BOX_SPACE_MODE				0xAC //Done
  148
#define CMD_BOX_SPACE_MODE				0xAC							//Done
149 149
//										value[0-1]
150 150
//										(0: Off,
151 151
//										 1: On)
152 152

                                        
153 153
// TEXT
154  
#define CMD_HOME					0x48 //Done
155  
#define CMD_CURSOR_POSITION				0x47 //Done
  154
#define CMD_HOME						0x48							//Done
  155
#define CMD_CURSOR_POSITION				0x47							//Done
156 156
//										col
157 157
//										row
158 158
//										(Derived from current font base size)
159  
#define CMD_CURSOR_COORDINATE			        0x79 //Done
  159
#define CMD_CURSOR_COORDINATE			0x79							//Done
160 160
//										x
161 161
//										y
162  
#define CMD_AUTO_SCROLL_ON				0x51 //Done
163  
#define CMD_AUTO_SCROLL_OFF				0x52 //Done
  162
#define CMD_AUTO_SCROLL_ON				0x51							//Done
  163
#define CMD_AUTO_SCROLL_OFF				0x52							//Done
164 164

                                        
165 165
// BITMAPS
166 166
/*
168 168
	The bitmap is encoded into bytes horizontally
169 169
*/
170 170

                                        
171  
#define CMD_UPLOAD_BMP					0x5E //Done
  171
#define CMD_UPLOAD_BMP					0x5E							//Done
172 172
//										bitmapid
173 173
//										lsbsize
174  
//                                      msbsize
  174
//										msbsize
175 175
//										bitmapfile
176 176
// (see FILESYSTEM file transfer protocol)
177  
#define CMD_DRAW_MEMORY_BMP				0x62 //Done
  177
#define CMD_DRAW_MEMORY_BMP				0x62							//Done
178 178
//										bitmapid
179 179
//										x
180 180
//										y
181  
#define CMD_DRAW_BMP					0x64 //Done
  181
#define CMD_DRAW_BMP					0x64							//Done
182 182
//										x
183 183
//										y
184 184
//										width
186 186
//										data
187 187

                                        
188 188
// BAR GRAPHS & DRAWING
189  
#define CMD_DRAWING_COLOR				0x63 //Done
  189
#define CMD_DRAWING_COLOR				0x63							//Done
190 190
//										color[0-255]
191  
//										(0: 	White,
  191
//										(0:     White,
192 192
//										 1-255: Black)
193  
#define CMD_DRAW_PIXEL					0x70 //Done
  193
#define CMD_DRAW_PIXEL					0x70							//Done
194 194
//										x
195 195
//										y
196  
#define CMD_DRAW_LINE					0x6C //Done
  196
#define CMD_DRAW_LINE					0x6C							//Done
197 197
//										x1
198 198
//										y1
199 199
//										x2
200 200
//										y2
201 201
// (Lines may interpolate differently Left to Right and Right to Left)
202  
#define CMD_CONTINUE_LINE				0x65 //Done
  202
#define CMD_CONTINUE_LINE				0x65							//Done
203 203
//										x
204 204
//										y
205  
#define CMD_DRAW_RECTANGLE				0x72 //Done
  205
#define CMD_DRAW_RECTANGLE				0x72							//Done
206 206
//										color[0-255]
207  
//										(0: 	White,
  207
//										(0:     White,
208 208
//										 1-255: Black)
209 209
//										x1
210 210
//										y1
211 211
//										x2
212 212
//										y2
213  
#define CMD_DRAW_SOLID_RECTANGLE		        0x78 //Done
  213
#define CMD_DRAW_SOLID_RECTANGLE		0x78							//Done
214 214
//										color[0-255]
215  
//										(0: 	White,
  215
//										(0:     White,
216 216
//										 1-255: Black)
217 217
//										x1
218 218
//										y1
219 219
//										x2
220 220
//										y2
221  
#define CMD_INITIALIZE_BAR_GRAPH		        0x67 //Done
  221
#define CMD_INITIALIZE_BAR_GRAPH		0x67							//Done
222 222
//										bgid[0-15]
223 223
//										type[0-3]
224 224
//										(0: Vertical from bottom,
232 232
//										y2
233 233
//										(y1<y2)
234 234
// (Beware of overlapping bar graphs)
235  
#define CMD_DRAW_BAR_GRAPH				0x69 //Done
  235
#define CMD_DRAW_BAR_GRAPH				0x69							//Done
236 236
//										bgid[0-15]
237 237
//										value
238 238
//										(In pixels)
239  
#define CMD_INITIALIZE_STRIP_CHART		        0x6A //Done
  239
#define CMD_INITIALIZE_STRIP_CHART		0x6A							//Done
240 240
//										scid[0-6]
241 241
//										x1
242 242
//										y1
244 244
//										(x1<x2)
245 245
//										y2
246 246
//										(y1<y2)
247  
#define CMD_SHIFT_STRIP_CHART			        0x6B //Done
  247
#define CMD_SHIFT_STRIP_CHART			0x6B							//Done
248 248
//										ref
249 249
//										(LSB: scid,
250 250
//										 MSB: direction
255 255
// (Hardwired to 3 tricolor LEDs)
256 256
/*
257 257
  LEDS LAYOUT
258  
		LED 1 - Top	GPO 2	GPO 1
259  
		LED 2 - Middle	GPO 4	GPO 3
260  
		LED 3 - Bottom	GPO 6	GPO 5
261  
		Yellow		0	0
262  
		Green		0	1
263  
		Red		1	0
264  
		Off		1	1
  258
		LED 1 - Top     GPO 2   GPO 1
  259
		LED 2 - Middle  GPO 4   GPO 3
  260
		LED 3 - Bottom  GPO 6   GPO 5
  261
		Yellow          0   0
  262
		Green           0   1
  263
		Red             1   0
  264
		Off             1   1
265 265
*/
266  
#define CMD_GPO_OFF					0x56 //Done
  266
#define CMD_GPO_OFF						0x56							//Done
267 267
//										num[1-6]
268  
#define CMD_GPO_ON					0x57 //Done
  268
#define CMD_GPO_ON						0x57							//Done
269 269
//										num[1-6]
270  
#define CMD_STARTUP_GPO_STATE                           0xC3 //Done
  270
#define CMD_STARTUP_GPO_STATE			0xC3							//Done
271 271
//										num[1-6]
272 272
//										state[0-1]
273 273
//										(0: Off,
276 276

                                        
277 277
// KEYPAD
278 278
// Default layout:
279  
#define RET_UP						0x42 //Done
280  
#define RET_DOWN					0x48 //Done
281  
#define RET_LEFT					0x44 //Done
282  
#define RET_RIGHT					0x43 //Done
283  
#define RET_CENTER					0x45 //Done
284  
#define RET_TOP						0x41 //Done
285  
#define RET_BOTTOM					0x47 //Done
286  
#define RET_RELEASE_UP					0x62 //Done
287  
#define RET_RELEASE_DOWN				0x68 //Done
288  
#define RET_RELEASE_LEFT				0x64 //Done
289  
#define RET_RELEASE_RIGHT				0x63 //Done
290  
#define RET_RELEASE_CENTER				0x65 //Done
291  
#define RET_RELEASE_TOP					0x61 //Done
292  
#define RET_RELEASE_BOTTOM				0x67 //Done
  279
#define RET_UP							0x42							//Done
  280
#define RET_DOWN						0x48							//Done
  281
#define RET_LEFT						0x44							//Done
  282
#define RET_RIGHT						0x43							//Done
  283
#define RET_CENTER						0x45							//Done
  284
#define RET_TOP							0x41							//Done
  285
#define RET_BOTTOM						0x47							//Done
  286
#define RET_RELEASE_UP					0x62							//Done
  287
#define RET_RELEASE_DOWN				0x68							//Done
  288
#define RET_RELEASE_LEFT				0x64							//Done
  289
#define RET_RELEASE_RIGHT				0x63							//Done
  290
#define RET_RELEASE_CENTER				0x65							//Done
  291
#define RET_RELEASE_TOP					0x61							//Done
  292
#define RET_RELEASE_BOTTOM				0x67							//Done
293 293

                                        
294  
#define CMD_AUTO_TRANSMIT_KEY_ON		        0x41 //Done
295  
#define CMD_AUTO_TRANSMIT_KEY_OFF		        0x4F //Done
  294
#define CMD_AUTO_TRANSMIT_KEY_ON		0x41							//Done
  295
#define CMD_AUTO_TRANSMIT_KEY_OFF		0x4F							//Done
296 296
// (The keypad buffer is reset after 10 key presses)
297  
#define CMD_POLL_KEY					0x26 //Done
  297
#define CMD_POLL_KEY					0x26							//Done
298 298
// (Returned code MSB flags 'more than one key press in buffer')
299 299

                                        
300  
#define RET_NO_KEY					0x00 //Done
  300
#define RET_NO_KEY						0x00							//Done
301 301

                                        
302  
#define CMD_CLEAR_KEY_BUFFER			        0x45 //Done
303  
#define CMD_DEBOUNCE_TIME				0x55 //Done
  302
#define CMD_CLEAR_KEY_BUFFER			0x45							//Done
  303
#define CMD_DEBOUNCE_TIME				0x55							//Done
304 304
//										time[0-255]
305 305
//										(6.554ms increments,
306 306
//										 Default: 8)
307  
#define CMD_AUTO_REPEAT_MODE			        0x7E //Done
  307
#define CMD_AUTO_REPEAT_MODE			0x7E							//Done
308 308
//										mode[0-1]
309 309
//										(0: Resend Key,
310 310
//										 1: Key Up/Down)
311  
#define CMD_AUTO_REPEAT_OFF				0x60 //Done
312  
#define CMD_CUSTOM_KEYPAD_CODES			        0xD5 //Done
  311
#define CMD_AUTO_REPEAT_OFF				0x60							//Done
  312
#define CMD_CUSTOM_KEYPAD_CODES			0xD5							//Done
313 313
//										kdown[See table bellow]
314 314
//										(9 bytes)
315 315
//										kup[See table bellow]
329 329
//FIXME: Report it missing from codes list
330 330

                                        
331 331
// DISPLAY
332  
#define CMD_CLEAR_SCREEN				0x58 //Done
333  
#define CMD_DISPLAY_ON					0x42 //Done
  332
#define CMD_CLEAR_SCREEN				0x58							//Done
  333
#define CMD_DISPLAY_ON					0x42							//Done
334 334
//										min[0-90]
335  
#define CMD_DISPLAY_OFF					0x46 //Done
336  
#define CMD_BRIGHTNESS					0x99 //Done
  335
#define CMD_DISPLAY_OFF					0x46							//Done
  336
#define CMD_BRIGHTNESS					0x99							//Done
337 337
//										brightness[0-255]
338 338
//										(Default: 255)
339  
#define CMD_DEFAULT_BRIGHTNESS			        0x98 //Done
  339
#define CMD_DEFAULT_BRIGHTNESS			0x98							//Done
340 340
//										brightness[0-255]
341 341
//										(Default: 255)
342  
#define CMD_CONTRAST					0x50 //Done
  342
#define CMD_CONTRAST					0x50							//Done
343 343
//										contrast[0-255]
344 344
//										(Default: 128)
345  
#define CMD_DEFAULT_CONTRAST			        0x91 //Done
  345
#define CMD_DEFAULT_CONTRAST			0x91							//Done
346 346
//										contrast[0-255]
347 347
//										(Default: 128)
348 348

                                        
353 353
	CMD_INIT
354 354
	CMD_UPLOAD(_FS | _FONT | _BMP)
355 355
	(parameters)
356  
                                            (RET_CONFIRM | RET_DECLINE)
  356
	(RET_CONFIRM | RET_DECLINE)
357 357
	CMD_CONFIRM
358 358
	-------------------Loop Here----------------------------
359 359
	NEXT_BYTE
360  
											NEXT_BYTE
  360
	NEXT_BYTE
361 361
	(CMD_CONFIRM | CMD_DECLINE)
362 362
	-------------------End Loop-----------------------------
363 363
*/
364 364
//TODO: Implement file transfer protocol
365 365

                                        
366  
#define RET_CONFIRM					0x01    //
367  
#define RET_DECLINE					0x08    //
  366
#define RET_CONFIRM						0x01							//
  367
#define RET_DECLINE						0x08							//
368 368

                                        
369  
#define CMD_CONFIRM					0x01    //
370  
#define CMD_DECLINE					0x08    //
  369
#define CMD_CONFIRM						0x01							//
  370
#define CMD_DECLINE						0x08							//
371 371

                                        
372  
#define CMD_WIPE_FILESYSTEM				0x21,0x59,0x21 //Done
  372
#define CMD_WIPE_FILESYSTEM				0x21,0x59,0x21					//Done
373 373
// (Be carefull with this one!)
374  
#define CMD_DELETE_FILE					0xAD //Done
  374
#define CMD_DELETE_FILE					0xAD							//Done
375 375
//										type[0-1]
376 376
//										(0: Font,
377 377
//										 1: Bitmap)
378 378
//										 fontid or bitmapid
379  
#define CMD_FREE_SPACE					0xAF //Done
  379
#define CMD_FREE_SPACE					0xAF							//Done
380 380

                                        
381 381
/*
382 382
  FREE SPACE RETURN FORMAT
383 383
	Free space size (4 bytes LSB to MSB)
384 384
*/
385 385

                                        
386  
#define CMD_DIRECTORY					0xB3 //WIP
  386
#define CMD_DIRECTORY					0xB3							//WIP
387 387

                                        
388 388
/*
389 389
  DIRECTORY RETURN FORMAT
400 400
		File size MSB (1 byte)
401 401
*/
402 402

                                        
403  
#define CMD_UPLOAD_FS					0xB0 //
  403
#define CMD_UPLOAD_FS					0xB0							//
404 404
//										fsimagefile
405 405
//										(Must be 16KB)
406  
#define CMD_DOWNLOAD_FILE				0xB2 //WIP
  406
#define CMD_DOWNLOAD_FILE				0xB2							//WIP
407 407
//										type[0-1]
408 408
//										(0: Font,
409 409
//										 1: Bitmap)
410 410
//										fontid or bitmapid
411 411

                                        
412  
#define CMD_MOVE_FILE					0xB4 //Done
  412
#define CMD_MOVE_FILE					0xB4							//Done
413 413
//										oldtype[0-1]
414 414
//										(0: Font,
415 415
//										 1: Bitmap)
418 418
//										(0: Font,
419 419
//										 1: Bitmap)
420 420
//										newid
421  
#define CMD_DUMP_FS					0x30 //WIP
  421
#define CMD_DUMP_FS						0x30							//WIP
422 422

                                        
423 423
/*
424 424
  DOWNLOAD_FILE AND DUMP_FS RETURN FORMAT
428 428
*/
429 429

                                        
430 430
// Undocumented command! Seems to dump the settings.
431  
#define CMD_DUMP_SETTINGS                               0xD0 //WIP
  431
#define CMD_DUMP_SETTINGS				0xD0							//WIP
432 432

                                        
433 433
// SECURITY
434  
#define CMD_REMEMBER					0x93 //Done
  434
#define CMD_REMEMBER					0x93							//Done
435 435
//										value[0-1]
436 436
//										(0: Do not remember,
437 437
//										 1: Remember)
438  
#define CMD_LOCK_LEVEL					0xCA,0xF5,0xA0 //Done
  438
#define CMD_LOCK_LEVEL					0xCA,0xF5,0xA0					//Done
439 439
//										level
440 440
//										(Lock bits:
441  
//										 0-2: 	Reserved leave 0,
442  
//										 3: 	Communication speed,
443  
//										 4: 	Settings,
444  
//										 5: 	Filesystem,
445  
//										 6: 	Command,
446  
//										 7: 	Display)
447  
#define CMD_DEFAULT_LOCK_LEVEL			        0xCB,0xF5,0xA0 //Done
  441
//										 0-2:	Reserved leave 0,
  442
//										 3:		Communication speed,
  443
//										 4:		Settings,
  444
//										 5:		Filesystem,
  445
//										 6:		Command,
  446
//										 7:		Display)
  447
#define CMD_DEFAULT_LOCK_LEVEL			0xCB,0xF5,0xA0					//Done
448 448
//										level
449 449
//										(Lock bits:
450  
//										 0-2: 	Reserved leave 0,
451  
//										 3: 	Communication speed,
452  
//										 4: 	Settings,
453  
//										 5: 	Filesystem,
454  
//										 6: 	Command,
455  
//										 7: 	Display)
  450
//										 0-2:	Reserved leave 0,
  451
//										 3:		Communication speed,
  452
//										 4:		Settings,
  453
//										 5:		Filesystem,
  454
//										 6:		Command,
  455
//										 7:		Display)
456 456
//FIXME: Report it missing from codes list
457  
#define CMD_WRITE_CUSTOMER_DATA			        0x34 //Done
  457
#define CMD_WRITE_CUSTOMER_DATA			0x34							//Done
458 458
//										data
459 459
//										(16B are accessible)
460  
#define CMD_READ_CUSTOMER_DATA			        0x35 //Done
  460
#define CMD_READ_CUSTOMER_DATA			0x35							//Done
461 461

                                        
462 462
/*
463 463
  READ_CUSTOMER_DATA RETURN FORMAT
465 465
*/
466 466

                                        
467 467
// MISC
468  
#define CMD_VERSION_NUMBER				0x36 //Done
  468
#define CMD_VERSION_NUMBER				0x36							//Done
469 469

                                        
470 470
/*
471 471
  VERSION_NUMBER RETURN FORMAT
472 472
	Version (1 byte)
473 473
	(Represents the version number
474  
	 Hex    Version
475  
	 0x19   1.9
476  
	 0x57   5.7)
  474
	 Hex	Version
  475
	 0x19	1.9
  476
	 0x57	5.7)
477 477
*/
478 478

                                        
479  
#define CMD_MODULE_TYPE					0x37 //Done
  479
#define CMD_MODULE_TYPE					0x37							//Done
480 480

                                        
481 481
/*
482 482
  MODULE_TYPE RETURN FORMAT
483  
    Type (1 byte)
  483
	Type (1 byte)
484 484
	(One of the following return codes)
485 485
*/
486  
#define RET_LCD0821					0x01 //Done
487  
#define RET_LCD2021					0x02 //Done
488  
#define RET_LCD2041					0x05 //Done
489  
#define RET_LCD4021					0x06 //Done
490  
#define RET_LCD4041					0x07 //Done
491  
#define RET_LK202_25					0x08 //Done
492  
#define RET_LK204_25					0x09 //Done
493  
#define RET_LK404_55					0x0A //Done
494  
#define RET_VFD2021					0x0B //Done
495  
#define RET_VFD2041					0x0C //Done
496  
#define RET_VFD4021					0x0D //Done
497  
#define RET_VK202_25					0x0E //Done
498  
#define RET_VK204_25					0x0F //Done
499  
#define RET_GLC12232					0x10 //Done
500  
#define RET_GLC24064					0x13 //Done
501  
#define RET_GLK24064_25					0x15 //Done
502  
#define RET_GLK12232_25					0x22 //Done
503  
#define RET_GLK12232_25_SM				0x24 //Done
504  
#define RET_GLK24064_16_1U_USB			        0x25 //Done
505  
#define RET_GLK24064_16_1U				0x26 //Done
506  
#define RET_GLK19264_7T_1U_USB		        	0x27 //Done
507  
#define RET_GLK12236_16					0x28 //Done
508  
#define RET_GLK12232_16_SM				0x29 //Done
509  
#define RET_GLK19264_7T_1U				0x2A //Done
510  
#define RET_LK204_7T_1U					0x2B //Done
511  
#define RET_LK204_7T_1U_USB				0x2C //Done
512  
#define RET_LK404_AT					0x31 //Done
513  
#define RET_MOS_AV_162A					0x32 //Done
514  
#define RET_LK402_12					0x33 //Done
515  
#define RET_LK162_12					0x34 //Done
516  
#define RET_LK204_25PC					0x35 //Done
517  
#define RET_LK202_24_USB				0x36 //Done
518  
#define RET_VK202_24_USB				0x37 //Done
519  
#define RET_LK204_24_USB				0x38 //Done
520  
#define RET_VK204_24_USB				0x39 //Done
521  
#define RET_PK162_12					0x3A //Done
522  
#define RET_VK162_12					0x3B //Done
523  
#define RET_MOS_AP_162A					0x3C //Done
524  
#define RET_PK202_25					0x3D //Done
525  
#define RET_MOS_AL_162A					0x3E //Done
526  
#define RET_MOS_AL_202A					0x3F //Done
527  
#define RET_MOS_AV_202A					0x40 //Done
528  
#define RET_MOS_AP_202A					0x41 //Done
529  
#define RET_PK202_24_USB				0x42 //Done
530  
#define RET_MOS_AL_082					0x43 //Done
531  
#define RET_MOS_AL_204					0x44 //Done
532  
#define RET_MOS_AV_204					0x45 //Done
533  
#define RET_MOS_AL_402					0x46 //Done
534  
#define RET_MOS_AV_402					0x47 //Done
535  
#define RET_LK082_12					0x48 //Done
536  
#define RET_VK402_12					0x49 //Done
537  
#define RET_VK404_55					0x4A //Done
538  
#define RET_LK402_25					0x4B //Done
539  
#define RET_VK402_25					0x4C //Done
540  
#define RET_PK204_25					0x4D //Done
541  
#define RET_MOS						0x4F //Done
542  
#define RET_MOI						0x50 //Done
543  
#define RET_XBOARD_S					0x51 //Done
544  
#define RET_XBOARD_I					0x52 //Done
545  
#define RET_MOU						0x53 //Done
546  
#define RET_XBOARD_U					0x54 //Done
547  
#define RET_LK202_25_USB				0x55 //Done
548  
#define RET_VK202_25_USB				0x56 //Done
549  
#define RET_LK204_25_USB				0x57 //Done
550  
#define RET_VK204_25_USB				0x58 //Done
551  
#define RET_LK162_12_TC					0x5B //Done
552  
#define RET_GLK240128_25				0x72 //Done
553  
#define RET_LK404_25					0x73 //Done
554  
#define RET_VK404_25					0x74 //Done
  486
#define RET_LCD0821						0x01							//Done
  487
#define RET_LCD2021						0x02							//Done
  488
#define RET_LCD2041						0x05							//Done
  489
#define RET_LCD4021						0x06							//Done
  490
#define RET_LCD4041						0x07							//Done
  491
#define RET_LK202_25					0x08							//Done
  492
#define RET_LK204_25					0x09							//Done
  493
#define RET_LK404_55					0x0A							//Done
  494
#define RET_VFD2021						0x0B							//Done
  495
#define RET_VFD2041						0x0C							//Done
  496
#define RET_VFD4021						0x0D							//Done
  497
#define RET_VK202_25					0x0E							//Done
  498
#define RET_VK204_25					0x0F							//Done
  499
#define RET_GLC12232					0x10							//Done
  500
#define RET_GLC24064					0x13							//Done
  501
#define RET_GLK24064_25					0x15							//Done
  502
#define RET_GLK12232_25					0x22							//Done
  503
#define RET_GLK12232_25_SM				0x24							//Done
  504
#define RET_GLK24064_16_1U_USB			0x25							//Done
  505
#define RET_GLK24064_16_1U				0x26							//Done
  506
#define RET_GLK19264_7T_1U_USB			0x27							//Done
  507
#define RET_GLK12236_16					0x28							//Done
  508
#define RET_GLK12232_16_SM				0x29							//Done
  509
#define RET_GLK19264_7T_1U				0x2A							//Done
  510
#define RET_LK204_7T_1U					0x2B							//Done
  511
#define RET_LK204_7T_1U_USB				0x2C							//Done
  512
#define RET_LK404_AT					0x31							//Done
  513
#define RET_MOS_AV_162A					0x32							//Done
  514
#define RET_LK402_12					0x33							//Done
  515
#define RET_LK162_12					0x34							//Done
  516
#define RET_LK204_25PC					0x35							//Done
  517
#define RET_LK202_24_USB				0x36							//Done
  518
#define RET_VK202_24_USB				0x37							//Done
  519
#define RET_LK204_24_USB				0x38							//Done
  520
#define RET_VK204_24_USB				0x39							//Done
  521
#define RET_PK162_12					0x3A							//Done
  522
#define RET_VK162_12					0x3B							//Done
  523
#define RET_MOS_AP_162A					0x3C							//Done
  524
#define RET_PK202_25					0x3D							//Done
  525
#define RET_MOS_AL_162A					0x3E							//Done
  526
#define RET_MOS_AL_202A					0x3F							//Done
  527
#define RET_MOS_AV_202A					0x40							//Done
  528
#define RET_MOS_AP_202A					0x41							//Done
  529
#define RET_PK202_24_USB				0x42							//Done
  530
#define RET_MOS_AL_082					0x43							//Done
  531
#define RET_MOS_AL_204					0x44							//Done
  532
#define RET_MOS_AV_204					0x45							//Done
  533
#define RET_MOS_AL_402					0x46							//Done
  534
#define RET_MOS_AV_402					0x47							//Done
  535
#define RET_LK082_12					0x48							//Done
  536
#define RET_VK402_12					0x49							//Done
  537
#define RET_VK404_55					0x4A							//Done
  538
#define RET_LK402_25					0x4B							//Done
  539
#define RET_VK402_25					0x4C							//Done
  540
#define RET_PK204_25					0x4D							//Done
  541
#define RET_MOS							0x4F							//Done
  542
#define RET_MOI							0x50							//Done
  543
#define RET_XBOARD_S					0x51							//Done
  544
#define RET_XBOARD_I					0x52							//Done
  545
#define RET_MOU							0x53							//Done
  546
#define RET_XBOARD_U					0x54							//Done
  547
#define RET_LK202_25_USB				0x55							//Done
  548
#define RET_VK202_25_USB				0x56							//Done
  549
#define RET_LK204_25_USB				0x57							//Done
  550
#define RET_VK204_25_USB				0x58							//Done
  551
#define RET_LK162_12_TC					0x5B							//Done
  552
#define RET_GLK240128_25				0x72							//Done
  553
#define RET_LK404_25					0x73							//Done
  554
#define RET_VK404_25					0x74							//Done
555 555

                                        
556 556
//Includes
557  
#include <bitset>       // C++ bit structure
558  
//#include <cc++/common.h>//GNU Common C++
  557
#include <bitset>	// C++ bit structure
  558
//#include <cc++/common.h>	//GNU Common C++
559 559

                                        
560 560
//Namespaces
561  
#ifdef	CCXX_NAMESPACES
  561
#ifdef CCXX_NAMESPACES
562 562
using namespace std;
563 563
using namespace ost;
564 564
#endif
567 567
class Moglk
568 568
{
569 569
	private:
570  
        bool openPort(char * device_ptr = "/dev/ttyS0");
571  
        void configurePort(void);
572  
        void setPortBaudRate(unsigned long int baud_rate);
573  
        void setPortFlowControl(bool state);
  570
		bool openPort(char * device_ptr = "/dev/ttyS0");
  571
		void configurePort(void);
  572
		void setPortBaudRate(unsigned long int baud_rate);
  573
		void setPortFlowControl(bool state);
574 574

                                        
575  
        void transmit(int * data_ptr);
576  
        bool receive(unsigned char * data_ptr);
577  
        bool receiveFile(int * file_ptr);
  575
		void transmit(int * data_ptr);
  576
		bool receive(unsigned char * data_ptr);
  577
		bool receiveFile(int * file_ptr);
578 578

                                        
579  
        bool upload(char * data_ptr);
  579
		bool upload(char * data_ptr);
580 580

                                        
581  
	void send(int * message_ptr);
  581
		void send(int * message_ptr);
582 582

                                        
583 583
	public:
584  
        Moglk();
585  
        ~Moglk();
  584
		Moglk();
  585
		~Moglk();
586 586

                                        
587  
        bool init(char * device_ptr = "/dev/ttyS0",
588  
                  unsigned long int baud_rate = 0);
  587
		bool init(char * device_ptr = "/dev/ttyS0",
  588
		          unsigned long int baud_rate = 0);
589 589

                                        
590  
        //int autodetect(void);
  590
		//int autodetect(void);
591 591

                                        
592  
        //int autodetectPort(void);
  592
		//int autodetectPort(void);
593 593

                                        
594  
        unsigned long int autodetectBaudRate(char * device_ptr = "/dev/ttyS0");
  594
		unsigned long int autodetectBaudRate(char * device_ptr = "/dev/ttyS0");
595 595

                                        
596  
        bool setBaudRate(unsigned long int baud_rate = 19200);
  596
		bool setBaudRate(unsigned long int baud_rate = 19200);
597 597

                                        
598  
        void setFlowControl(bool state = 0,
599  
                            unsigned char full = 0,
600  
                            unsigned char empty = 0);
  598
		void setFlowControl(bool state	= 0,
  599
		                    unsigned char full	= 0,
  600
		                    unsigned char empty	= 0);
601 601

                                        
602  
        void display(const char text[],
603  
                     unsigned char font = 0,
604  
                     unsigned char x = 255,
605  
                     unsigned char y = 255);
  602
		void display(const char text[],
  603
		             unsigned char font = 0,
  604
		             unsigned char x = 255,
  605
		             unsigned char y = 255);
606 606

                                        
607  
        void goHome(void);
  607
		void goHome(void);
608 608

                                        
609  
        void setFont(unsigned char id = 1,
610  
                     unsigned char lm = 0,
611  
                     unsigned char tm = 0,
612  
                     unsigned char csp = 0,
613  
                     unsigned char lsp = 1,
614  
                     unsigned char srow = 64);
  609
		void setFont(unsigned char id = 1,
  610
		             unsigned char lm = 0,
  611
		             unsigned char tm = 0,
  612
		             unsigned char csp = 0,
  613
		             unsigned char lsp = 1,
  614
		             unsigned char srow = 64);
615 615

                                        
616  
        void setFontMetrics(unsigned char lm = 0,
617  
                            unsigned char tm = 0,
618  
                            unsigned char csp = 0,
619  
                            unsigned char lsp = 1,
620  
                            unsigned char srow = 64);
  616
		void setFontMetrics(unsigned char lm = 0,
  617
		                    unsigned char tm = 0,
  618
		                    unsigned char csp = 0,
  619
		                    unsigned char lsp = 1,
  620
		                    unsigned char srow = 64);
621 621

                                        
622  
        void setBoxSpace(bool mode = 1);
  622
		void setBoxSpace(bool mode = 1);
623 623

                                        
624  
        void setAutoScroll(bool mode = 1);
  624
		void setAutoScroll(bool mode = 1);
625 625

                                        
626  
        void setCursor(unsigned char x,
627  
                       unsigned char y,
628  
                       bool mode = 0);
  626
		void setCursor(unsigned char x,
  627
		               unsigned char y,
  628
		               bool mode = 0);
629 629

                                        
630  
        void drawMemBmp(unsigned char id = 1,
631  
                        unsigned char x = 0,
632  
                        unsigned char y = 0);
  630
		void drawMemBmp(unsigned char id = 1,
  631
		                unsigned char x = 0,
  632
		                unsigned char y = 0);
633 633

                                        
634  
        void setDrawingColor(bool color = 1);
  634
		void setDrawingColor(bool color = 1);
635 635

                                        
636  
        void drawPixel(unsigned char x,
637  
                       unsigned char y,
638  
                       bool color = 1);
  636
		void drawPixel(unsigned char x,
  637
		               unsigned char y,
  638
		               bool color = 1);
639 639

                                        
640  
        bool drawLine(unsigned char x1,
641  
                      unsigned char y1,
642  
                      unsigned char x2 = 255,
643  
                      unsigned char y2 = 255,
644  
                      bool color = 1);
  640
		bool drawLine(unsigned char x1,
  641
		              unsigned char y1,
  642
		              unsigned char x2 = 255,
  643
		              unsigned char y2 = 255,
  644
		              bool color = 1);
645 645

                                        
646  
        void drawRectangle(unsigned char x1,
647  
                           unsigned char y1,
648  
                           unsigned char x2,
649  
                           unsigned char y2,
650  
                           bool mode = 0,
651  
                           bool color = 1);
  646
		void drawRectangle(unsigned char x1,
  647
		                   unsigned char y1,
  648
		                   unsigned char x2,
  649
		                   unsigned char y2,
  650
		                   bool mode = 0,
  651
		                   bool color = 1);
652 652

                                        
653  
        bool initBarGraph(unsigned char x1,
654  
                          unsigned char y1,
655  
                          unsigned char x2,
656  
                          unsigned char y2,
657  
                          unsigned char type = 0,
658  
                          unsigned char id = 0);
  653
		bool initBarGraph(unsigned char x1,
  654
		                  unsigned char y1,
  655
		                  unsigned char x2,
  656
		                  unsigned char y2,
  657
		                  unsigned char type = 0,
  658
		                  unsigned char id = 0);
659 659

                                        
660  
        bool drawBarGraph(unsigned char value,
661  
                          unsigned char id = 0);
  660
		bool drawBarGraph(unsigned char value,
  661
		                  unsigned char id = 0);
662 662

                                        
663  
        bool initStripChart(unsigned char x1,
664  
                            unsigned char y1,
665  
                            unsigned char x2,
666  
                            unsigned char y2,
667  
                            unsigned char id = 0);
  663
		bool initStripChart(unsigned char x1,
  664
		                    unsigned char y1,
  665
		                    unsigned char x2,
  666
		                    unsigned char y2,
  667
		                    unsigned char id = 0);
668 668

                                        
669  
        bool shiftStripChart(bool direction = 0,
670  
                             unsigned char id =0);
  669
		bool shiftStripChart(bool direction = 0,
  670
		                     unsigned char id =0);
671 671

                                        
672  
        bool setGpo(unsigned char id,
673  
                    bool state);
  672
		bool setGpo(unsigned char id,
  673
		            bool state);
674 674

                                        
675  
        bool setLed(unsigned char id,
676  
                    unsigned char state);
  675
		bool setLed(unsigned char id,
  676
		            unsigned char state);
677 677

                                        
678  
        bool ledYellow(unsigned char id);
  678
		bool ledYellow(unsigned char id);
679 679

                                        
680  
        bool ledGreen(unsigned char id);
  680
		bool ledGreen(unsigned char id);
681 681

                                        
682  
        bool ledRed(unsigned char id);
  682
		bool ledRed(unsigned char id);
683 683

                                        
684  
        bool ledOff(unsigned char id);
  684
		bool ledOff(unsigned char id);
685 685

                                        
686  
        bool startupGpo(unsigned char id,
687  
                        bool state);
  686
		bool startupGpo(unsigned char id,
  687
		                 bool state);
688 688

                                        
689  
        void setAutoTxKey(bool state);
  689
		void setAutoTxKey(bool state);
690 690

                                        
691  
        void clearKeyBuffer(void);
  691
		void clearKeyBuffer(void);
692 692

                                        
693  
        void setDebounce(unsigned char time);
  693
		void setDebounce(unsigned char time);
694 694

                                        
695  
        void setAutoRepeat(bool mode);
  695
		void setAutoRepeat(bool mode);
696 696

                                        
697  
        void autoRepeatOff(void);
  697
		void autoRepeatOff(void);
698 698

                                        
699  
        void clearScreen(void);
  699
		void clearScreen(void);
700 700

                                        
701  
        bool setBacklight(bool state = 1,
702  
                          unsigned char time = 0);
  701
		bool setBacklight(bool state = 1,
  702
		                  unsigned char time = 0);
703 703

                                        
704  
        void setBrightness(unsigned char value = 255);
  704
		void setBrightness(unsigned char value = 255);
705 705

                                        
706  
        void setDefaultBrightness(unsigned char value = 255);
  706
		void setDefaultBrightness(unsigned char value = 255);
707 707

                                        
708  
        void setContrast(unsigned char value = 128);
  708
		void setContrast(unsigned char value = 128);
709 709

                                        
710  
        void setDefaultContrast(unsigned char value = 128);
  710
		void setDefaultContrast(unsigned char value = 128);
711 711

                                        
712  
        void wipeFs(void);
  712
		void wipeFs(void);
713 713

                                        
714  
        unsigned short int getFreeSpace(void);
  714
		unsigned short int getFreeSpace(void);
715 715

                                        
716  
        void setRemember(bool mode = 1);
  716
		void setRemember(bool mode = 1);
717 717

                                        
718  
        void setCustomerData(const char * data);
  718
		void setCustomerData(const char * data);
719 719

                                        
720  
        void getCustomerData(unsigned char * data);
  720
		void getCustomerData(unsigned char * data);
721 721

                                        
722  
        unsigned char getVersion(void);
  722
		unsigned char getVersion(void);
723 723

                                        
724  
        unsigned char getModuleType(void);
  724
		unsigned char getModuleType(void);
725 725

                                        
726  
        void getDirectory(void);
  726
		void getDirectory(void);
727 727

                                        
728  
        void deleteFile(bool type,
729  
                        unsigned char id);
  728
		void deleteFile(bool type,
  729
		                unsigned char id);
730 730

                                        
731  
        int * downloadFile(bool type,
732  
                           unsigned char id,
733  
                           int * file_ptr);
  731
		int * downloadFile(bool type,
  732
		                   unsigned char id,
  733
		                   int * file_ptr);
734 734

                                        
735  
        int * dumpFs(int * file_ptr);
  735
		int * dumpFs(int * file_ptr);
736 736

                                        
737  
        int * dumpSettings(int * file_ptr);
  737
		int * dumpSettings(int * file_ptr);
738 738

                                        
739  
        void moveFile(bool old_type,
740  
                      unsigned char old_id,
741  
                      bool new_type,
742  
                      unsigned char new_id);
  739
		void moveFile(bool old_type,
  740
		              unsigned char old_id,
  741
		              bool new_type,
  742
		              unsigned char new_id);
743 743

                                        
744  
        void setLock(std::bitset<8> level);
  744
		void setLock(std::bitset<8> level);
745 745

                                        
746  
        void setDefaultLock(std::bitset<8> level);
  746
		void setDefaultLock(std::bitset<8> level);
747 747

                                        
748  
        unsigned char pollKey(void);
  748
		unsigned char pollKey(void);
749 749

                                        
750  
        void setCustomKeyCodes(unsigned char kup_top,
751  
                               unsigned char kup_up,
752  
                               unsigned char kup_right,
753  
                               unsigned char kup_left,
754  
                               unsigned char kup_center,
755  
                               unsigned char kup_bottom,
756  
                               unsigned char kup_down,
757  
                               unsigned char kdown_top,
758  
                               unsigned char kdown_up,
759  
                               unsigned char kdown_right,
760  
                               unsigned char kdown_left,
761  
                               unsigned char kdown_center,
762  
                               unsigned char kdown_bottom,
763  
                               unsigned char kdown_down);
  750
		void setCustomKeyCodes(unsigned char kup_top,
  751
		                       unsigned char kup_up,
  752
		                       unsigned char kup_right,
  753
		                       unsigned char kup_left,
  754
		                       unsigned char kup_center,
  755
		                       unsigned char kup_bottom,
  756
		                       unsigned char kup_down,
  757
		                       unsigned char kdown_top,
  758
		                       unsigned char kdown_up,
  759
		                       unsigned char kdown_right,
  760
		                       unsigned char kdown_left,
  761
		                       unsigned char kdown_center,
  762
		                       unsigned char kdown_bottom,
  763
		                       unsigned char kdown_down);
764 764

                                        
765  
        void drawBmp(unsigned char x,
766  
                     unsigned char y,
767  
                     unsigned char width,
768  
                     unsigned char height,
769  
                     int * data);
  765
		void drawBmp(unsigned char x,
  766
		             unsigned char y,
  767
		             unsigned char width,
  768
		             unsigned char height,
  769
		             int * data);
770 770

                                        
771  
        void uploadFont(unsigned char id,
772  
                        unsigned int size,
773  
                        char * data_ptr);
  771
		void uploadFont(unsigned char id,
  772
		                unsigned int size,
  773
		                char * data_ptr);
774 774

                                        
775  
        void uploadBmp(unsigned char id,
776  
                       unsigned int size,
777  
                       char * data_ptr);
  775
		void uploadBmp(unsigned char id,
  776
		               unsigned int size,
  777
		               char * data_ptr);
778 778

                                        
779  
        void uploadFs(unsigned int size,
780  
                      char * data_ptr);
  779
		void uploadFs(unsigned int size,
  780
		              char * data_ptr);
781 781

                                        
782  
}; /* Moglk */
  782
} /* Moglk */
783 783

                                        
784 784
#endif /* #ifndef _MOGLK_H */
785 785