comparison projects/d-box/main.cpp @ 15:901d205d1a3c

Updated to latest PRU library; external PRU file no longer needed. Also catch SIGTERM as well as SIGINT to clean up gracefully.
author andrewm
date Sat, 07 Feb 2015 16:41:56 +0000
parents 09f03ac40fcc
children be427da6fb9c
comparison
equal deleted inserted replaced
14:06f93bef7dd2 15:901d205d1a3c
69 char* gPartialFilename = 0; // name of the partials file to load 69 char* gPartialFilename = 0; // name of the partials file to load
70 bool gAudioIn = false; // stereo audio in status 70 bool gAudioIn = false; // stereo audio in status
71 71
72 int touchSensor0Address = 0x0C; // I2C addresses of touch sensors 72 int touchSensor0Address = 0x0C; // I2C addresses of touch sensors
73 int touchSensor1Address = 0x0B; 73 int touchSensor1Address = 0x0B;
74 bool useNewSensors = false; 74 int sensorType = 0;
75 75
76 char sdPath[256] = "/dev/mmcblk0p2"; // system path of the SD, partition 2 76 char sdPath[256] = "/dev/mmcblk0p2"; // system path of the SD, partition 2
77 char mountPath[256] = "/root/d-box/usersounds"; // mount point of SD partition 2 [where user files are] 77 char mountPath[256] = "/root/d-box/usersounds"; // mount point of SD partition 2 [where user files are]
78 char gUserDirName[256] = "usersounds"; // Directory in which user analysis files can be found [dir of mountPath] 78 char gUserDirName[256] = "usersounds"; // Directory in which user analysis files can be found [dir of mountPath]
79 char gDefaultDirName[256] = "sounds"; // Directory in which built in analysis files can be found 79 char gDefaultDirName[256] = "sounds"; // Directory in which built in analysis files can be found
273 {"help", 0, NULL, 'h'}, 273 {"help", 0, NULL, 'h'},
274 {"audioin", 1, NULL, 'i'}, 274 {"audioin", 1, NULL, 'i'},
275 {"file", 1, NULL, 'f'}, 275 {"file", 1, NULL, 'f'},
276 {"keyboard", 1, NULL, 'k'}, 276 {"keyboard", 1, NULL, 'k'},
277 {"audio-test", 0, NULL, 'T'}, 277 {"audio-test", 0, NULL, 'T'},
278 {"new-sensors", 0, NULL, 'S'}, 278 {"sensor-type", 1, NULL, 'S'},
279 {"sensor0", 1, NULL, 'Q'}, 279 {"sensor0", 1, NULL, 'Q'},
280 {"sensor1", 1, NULL, 'R'}, 280 {"sensor1", 1, NULL, 'R'},
281 {"log", 1, NULL, 'l'}, 281 {"log", 1, NULL, 'l'},
282 {"usesd", 1, NULL, 'u'}, 282 {"usesd", 1, NULL, 'u'},
283 {"oversamp", 1, NULL, 'o'}, 283 {"oversamp", 1, NULL, 'o'},
291 BeagleRT_defaultSettings(settings); 291 BeagleRT_defaultSettings(settings);
292 292
293 while (1) 293 while (1)
294 { 294 {
295 int c; 295 int c;
296 if ((c = BeagleRT_getopt_long(args.argc, args.argv, "hf:ki:sTQ:R:Sl:u:o:n:g:", long_option, settings)) < 0) 296 if ((c = BeagleRT_getopt_long(args.argc, args.argv, "hf:ki:sTQ:R:S:l:u:o:n:g:", long_option, settings)) < 0)
297 break; 297 break;
298 switch (c) 298 switch (c)
299 { 299 {
300 case 'h': 300 case 'h':
301 morehelp++; 301 morehelp++;
315 break; 315 break;
316 case 'T': 316 case 'T':
317 useAudioTest = true; 317 useAudioTest = true;
318 break; 318 break;
319 case 'S': 319 case 'S':
320 useNewSensors = true; 320 sensorType = atoi(optarg);
321 break; 321 break;
322 case 'Q': 322 case 'Q':
323 touchSensor0Address = atoi(optarg); 323 touchSensor0Address = atoi(optarg);
324 break; 324 break;
325 case 'R': 325 case 'R':
394 // Free file name string which is no longer needed 394 // Free file name string which is no longer needed
395 if(gPartialFilename != 0) 395 if(gPartialFilename != 0)
396 free(gPartialFilename); 396 free(gPartialFilename);
397 397
398 if(!useAudioTest) { 398 if(!useAudioTest) {
399 if(initSensorLoop(touchSensor0Address, touchSensor1Address, useNewSensors) != 0) 399 if(initSensorLoop(touchSensor0Address, touchSensor1Address, sensorType) != 0)
400 return -1; 400 return -1;
401 } 401 }
402 402
403 if(gVerbose == 1) 403 if(gVerbose == 1)
404 cout << "main() : creating audio thread" << endl; 404 cout << "main() : creating audio thread" << endl;
448 cout << "Error:unable to create keyboard thread" << endl; 448 cout << "Error:unable to create keyboard thread" << endl;
449 return -1; 449 return -1;
450 } 450 }
451 } 451 }
452 452
453 // Set up interrupt handler to catch Control-C 453 // Set up interrupt handler to catch Control-C and SIGTERM
454 signal(SIGINT, interrupt_handler); 454 signal(SIGINT, interrupt_handler);
455 signal(SIGTERM, interrupt_handler);
455 456
456 // load all other files into oscBanks 457 // load all other files into oscBanks
457 loadAudioFiles(false); 458 loadAudioFiles(false);
458 cout << "Finished loading analysis files\n"; 459 cout << "Finished loading analysis files\n";
459 gIsLoading = false; 460 gIsLoading = false;