00001
00002
00003
00004
00005
00006
00007 #include <cstdio>
00008 #include <cstdlib>
00009 #include <iostream>
00010 #include <string>
00011 #include <getopt.h>
00012 #include "WacomIntuos4LED.h"
00013
00014 using namespace std;
00015
00016 void help(char* name) {
00017 cout << endl << "Usage: " << endl << endl;
00018 cout << name << " [--lefthanded] "
00019 << "[--vendorid <vid> --productid <pid>] "
00020 << " --button <id> --icon <name> --> Set library icon <name> to button <id>"
00021 << endl << endl;
00022
00023 cout << name << " [--lefthanded] "
00024 << "[--vendorid <vid> --productid <pid>] "
00025 << "--button <id> --image <filename> --> Set image <filename> to button <id>"
00026 << endl << endl;
00027
00028 cout << name
00029 << " --dump <filename> --> Dump image <filename> as C static array"
00030 << endl << endl;
00031 cout << name << " --list" << " -> List library icon names" << endl << endl;
00032 cout << name << " --help" << " -> Display this help text" << endl << endl;
00033 }
00034
00035 int main(int argc, char **argv) {
00036
00037 static struct option long_options[] = { { "help", no_argument, 0, 'h' }, {
00038 "list", no_argument, 0, 'l' },
00039 { "lefthanded", no_argument, 0, 'e' }, { "button",
00040 required_argument, 0, 'b' }, { "icon", required_argument,
00041 0, 'i' }, { "image", required_argument, 0, 'm' }, { "dump",
00042 required_argument, 0, 'd' }, { "vendorid",
00043 required_argument, 0, 'v' }, { "productid",
00044 required_argument, 0, 'p' }, { 0, 0, 0, 0 } };
00045 WacomIntuos4LED intuos4;
00046 int c;
00047 bool done = false;
00048 int button = -1;
00049 bool tablet_ok = false;
00050 bool right_handed = true;
00051 bool set_icon = false;
00052 bool set_image = false;
00053 bool dump_image = false;
00054
00055 string name;
00056 int cmd_counter = 0;
00057 uint16_t vendor_id = 0, product_id = 0;
00058
00059 while (!done) {
00060
00061 int option_index = 0;
00062
00063 c = getopt_long_only(argc, argv, "hleb:i:m:v:p:d:", long_options,
00064 &option_index);
00065
00066
00067 if (c == -1) {
00068 done = true;
00069 } else {
00070 switch (c) {
00071 case 'h':
00072 help(argv[0]);
00073 exit(0);
00074 break;
00075
00076 case 'b':
00077 button = atoi(optarg);
00078 break;
00079
00080 case 'v':
00081 vendor_id = atoi(optarg);
00082 break;
00083
00084 case 'p':
00085 product_id = atoi(optarg);
00086 break;
00087
00088 case 'l':
00089 cmd_counter++;
00090 intuos4.dumpIconNames();
00091 exit(0);
00092 break;
00093
00094 case 'e':
00095 right_handed = false;
00096 break;
00097
00098 case 'i':
00099 cmd_counter++;
00100 set_icon = true;
00101 name = optarg;
00102 break;
00103
00104 case 'd':
00105 cmd_counter++;
00106 dump_image = true;
00107 name = optarg;
00108 break;
00109
00110 case 'm':
00111 cmd_counter++;
00112 set_image = true;
00113 name = optarg;
00114 break;
00115
00116 case '?':
00117 help(argv[0]);
00118 exit(1);
00119
00120 default:
00121 help(argv[0]);
00122 exit(1);
00123 }
00124
00125 }
00126
00127 }
00128
00129 if (cmd_counter != 1) {
00130 help(argv[0]);
00131 exit(1);
00132 }
00133
00134 if ((set_icon || set_image) && (button < 1 || button > 8)) {
00135 cout << "ERROR: invalid button id." << endl;
00136 help(argv[0]);
00137 exit(1);
00138 }
00139
00140 if (set_icon || set_image) {
00141 if (vendor_id > 0 && product_id > 0) {
00142 tablet_ok = intuos4.init(vendor_id, product_id);
00143 } else {
00144 tablet_ok = intuos4.autoDetectTablet();
00145 }
00146
00147 if (!tablet_ok) {
00148 cout << "ERROR: " << "tablet could not be initialized." << endl;
00149 exit(1);
00150 }
00151 }
00152
00153 if (set_icon) {
00154 intuos4.setLibraryIcon(button - 1, name, right_handed);
00155 }
00156
00157 if (set_image) {
00158 intuos4.setImage(button - 1, name, right_handed);
00159 }
00160
00161 if (dump_image) {
00162 intuos4.dumpImageAsStaticData(name);
00163 return 0;
00164 }
00165
00166 exit(0);
00167 }
00168