annotate lcdtest/testmain.c @ 27:4b7cac119fb5

lcdtest: added our own local exitcodes.h header
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 27 May 2018 21:49:46 +0000
parents 225556110fa6
children de3d3cfcbb35
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdio.h>
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdlib.h>
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <unistd.h>
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <ftdi.h>
27
4b7cac119fb5 lcdtest: added our own local exitcodes.h header
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
6 #include "exitcodes.h"
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
23
2127e6fdeab2 lcdtest: simplify USB device selection by serial string
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
8 char *device_serial;
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 struct ftdi_context ftdi;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 process_cmdline(argc, argv)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 char **argv;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 int c;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern char *optarg;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 while ((c = getopt(argc, argv, "d:")) != EOF) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 switch (c) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 case 'd':
23
2127e6fdeab2 lcdtest: simplify USB device selection by serial string
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
20 device_serial = optarg;
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 continue;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 default:
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 /* error msg already printed */
27
4b7cac119fb5 lcdtest: added our own local exitcodes.h header
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
24 exit(ERROR_USAGE);
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 }
22
e9df47110181 lcdtest: added ability to specify chdir on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
27 switch (argc - optind) {
e9df47110181 lcdtest: added ability to specify chdir on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
28 case 0:
e9df47110181 lcdtest: added ability to specify chdir on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
29 break;
e9df47110181 lcdtest: added ability to specify chdir on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
30 case 1:
e9df47110181 lcdtest: added ability to specify chdir on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
31 if (chdir(argv[optind]) < 0) {
e9df47110181 lcdtest: added ability to specify chdir on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
32 perror(argv[optind]);
27
4b7cac119fb5 lcdtest: added our own local exitcodes.h header
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
33 exit(ERROR_UNIX);
22
e9df47110181 lcdtest: added ability to specify chdir on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
34 }
e9df47110181 lcdtest: added ability to specify chdir on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
35 break;
e9df47110181 lcdtest: added ability to specify chdir on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
36 default:
e9df47110181 lcdtest: added ability to specify chdir on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
37 fprintf(stderr, "usage: %s [options] [chdir]\n", argv[0]);
27
4b7cac119fb5 lcdtest: added our own local exitcodes.h header
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
38 exit(ERROR_USAGE);
22
e9df47110181 lcdtest: added ability to specify chdir on the command line
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
39 }
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 main(argc, argv)
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 char **argv;
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 char command[512];
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 process_cmdline(argc, argv);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 ftdi_init(&ftdi);
23
2127e6fdeab2 lcdtest: simplify USB device selection by serial string
Mychaela Falconia <falcon@freecalypso.org>
parents: 22
diff changeset
49 if (ftdi_usb_open_desc(&ftdi, 0x0403, 0x7157, 0, device_serial) < 0) {
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 fprintf(stderr, "FTDI USB open failed: %s\n", ftdi.error_str);
27
4b7cac119fb5 lcdtest: added our own local exitcodes.h header
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
51 exit(ERROR_FTDI);
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 if (ftdi_set_bitmode(&ftdi, 0, BITMODE_MCU) < 0) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 fprintf(stderr, "unable to enter MCU mode: %s\n",
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 ftdi.error_str);
27
4b7cac119fb5 lcdtest: added our own local exitcodes.h header
Mychaela Falconia <falcon@freecalypso.org>
parents: 26
diff changeset
56 exit(ERROR_FTDI);
12
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 for (;;) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 if (isatty(0)) {
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 fputs("lcdtest> ", stdout);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 fflush(stdout);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (!fgets(command, sizeof command, stdin))
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 exit(0);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 dispatch_cmd(command);
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
5eaf832d57d0 lcdtest program started, skeleton compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 }