annotate lcdtest/testmain.c @ 26:225556110fa6

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