Mercurial > hg > beaglert
comparison projects/d-box/main.cpp @ 108:3068421c0737 ultra-staging
Merged default into ultra-staging
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 18 Aug 2015 00:35:15 +0100 |
parents | 59edd5780fef |
children |
comparison
equal
deleted
inserted
replaced
54:d3f869b98147 | 108:3068421c0737 |
---|---|
31 #include <sched.h> | 31 #include <sched.h> |
32 | 32 |
33 // get_opt_long | 33 // get_opt_long |
34 #include <getopt.h> | 34 #include <getopt.h> |
35 | 35 |
36 #include "../../include/RTAudio.h" | 36 #include <BeagleRT.h> |
37 #include "config.h" | 37 #include "config.h" |
38 #include "sensors.h" | 38 #include "sensors.h" |
39 #include "OscillatorBank.h" | 39 #include "OscillatorBank.h" |
40 #include "StatusLED.h" | 40 #include "StatusLED.h" |
41 #include "logger.h" | 41 #include "logger.h" |
74 int sensorType = 0; | 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] = "/root/d-box/sounds"; // Directory in which built in analysis files can be found |
80 char *gDirName; | 80 char *gDirName; |
81 bool gIsLoading = false; | 81 bool gIsLoading = false; |
82 int fileCnt = 0; | 82 int fileCnt = 0; |
83 std::vector <std::string> files; | 83 std::vector <std::string> files; |
84 | 84 |
260 | 260 |
261 gShouldStop = true; | 261 gShouldStop = true; |
262 } | 262 } |
263 | 263 |
264 | 264 |
265 void parseArguments(arg_data args, RTAudioSettings *settings) | 265 void parseArguments(arg_data args, BeagleRTInitSettings *settings) |
266 { | 266 { |
267 // Default filename; | 267 // Default filename; |
268 gPartialFilename = strdup("D-Box_sound_250_60_40_h88_2.txt"); | 268 gPartialFilename = strdup("D-Box_sound_250_60_40_h88_2.txt"); |
269 | |
270 const int kOptionAudioTest = 1000; | |
269 | 271 |
270 // TODO: complete this | 272 // TODO: complete this |
271 struct option long_option[] = | 273 struct option long_option[] = |
272 { | 274 { |
273 {"help", 0, NULL, 'h'}, | 275 {"help", 0, NULL, 'h'}, |
274 {"audioin", 1, NULL, 'i'}, | 276 {"audioin", 1, NULL, 'i'}, |
275 {"file", 1, NULL, 'f'}, | 277 {"file", 1, NULL, 'f'}, |
276 {"keyboard", 1, NULL, 'k'}, | 278 {"keyboard", 1, NULL, 'k'}, |
277 {"audio-test", 0, NULL, 'T'}, | 279 {"audio-test", 0, NULL, kOptionAudioTest}, |
278 {"sensor-type", 1, NULL, 'S'}, | 280 {"sensor-type", 1, NULL, 't'}, |
279 {"sensor0", 1, NULL, 'Q'}, | 281 {"sensor0", 1, NULL, 'q'}, |
280 {"sensor1", 1, NULL, 'R'}, | 282 {"sensor1", 1, NULL, 'r'}, |
281 {"log", 1, NULL, 'l'}, | 283 {"log", 1, NULL, 'l'}, |
282 {"usesd", 1, NULL, 'u'}, | 284 {"usesd", 1, NULL, 'u'}, |
283 {"oversamp", 1, NULL, 'o'}, | 285 {"oversamp", 1, NULL, 'o'}, |
284 {"boxnumber", 1, NULL, 'n'}, | 286 {"boxnumber", 1, NULL, 'n'}, |
285 {"group", 1, NULL, 'g'}, | 287 {"group", 1, NULL, 'g'}, |
291 BeagleRT_defaultSettings(settings); | 293 BeagleRT_defaultSettings(settings); |
292 | 294 |
293 while (1) | 295 while (1) |
294 { | 296 { |
295 int c; | 297 int c; |
296 if ((c = BeagleRT_getopt_long(args.argc, args.argv, "hf:ki:sTQ:R:S:l:u:o:n:g:", long_option, settings)) < 0) | 298 if ((c = BeagleRT_getopt_long(args.argc, args.argv, "hf:ki:sq:r:t:l:u:o:n:g:", long_option, settings)) < 0) |
297 break; | 299 break; |
298 switch (c) | 300 switch (c) |
299 { | 301 { |
300 case 'h': | 302 case 'h': |
301 morehelp++; | 303 morehelp++; |
311 gAudioIn = (atoi(optarg)==0) ? false : true; | 313 gAudioIn = (atoi(optarg)==0) ? false : true; |
312 break; | 314 break; |
313 case 's': | 315 case 's': |
314 forceSensors = true; | 316 forceSensors = true; |
315 break; | 317 break; |
316 case 'T': | 318 case kOptionAudioTest: |
317 useAudioTest = true; | 319 useAudioTest = true; |
318 break; | 320 break; |
319 case 'S': | 321 case 't': |
320 sensorType = atoi(optarg); | 322 sensorType = atoi(optarg); |
321 break; | 323 break; |
322 case 'Q': | 324 case 'q': |
323 touchSensor0Address = atoi(optarg); | 325 touchSensor0Address = atoi(optarg); |
324 break; | 326 break; |
325 case 'R': | 327 case 'r': |
326 touchSensor1Address = atoi(optarg); | 328 touchSensor1Address = atoi(optarg); |
327 break; | 329 break; |
328 case 'l': | 330 case 'l': |
329 tmp = atoi(optarg); | 331 tmp = atoi(optarg); |
330 if(tmp==0) | 332 if(tmp==0) |
359 gVerbose = settings->verbose; | 361 gVerbose = settings->verbose; |
360 } | 362 } |
361 | 363 |
362 int main(int argc, char *argv[]) | 364 int main(int argc, char *argv[]) |
363 { | 365 { |
364 RTAudioSettings settings; // Standard audio settings | 366 BeagleRTInitSettings settings; // Standard audio settings |
365 RT_TASK rtSensorThread; | 367 RT_TASK rtSensorThread; |
366 const char rtSensorThreadName[] = "dbox-sensor"; | 368 const char rtSensorThreadName[] = "dbox-sensor"; |
367 int oscBankHopSize; | 369 int oscBankHopSize; |
368 | 370 |
369 // Parse command-line arguments | 371 // Parse command-line arguments |
370 args.argc = argc; | 372 args.argc = argc; |
371 args.argv = argv; | 373 args.argv = argv; |
372 parseArguments(args, &settings); | 374 parseArguments(args, &settings); |
373 | 375 |
374 setVerboseLevel(gVerbose); | 376 BeagleRT_setVerboseLevel(gVerbose); |
375 if(gVerbose == 1 && useAudioTest) | 377 if(gVerbose == 1 && useAudioTest) |
376 cout << "main() : running in audio test mode" << endl; | 378 cout << "main() : running in audio test mode" << endl; |
377 | 379 |
378 // Load sound files from directory | 380 // Load sound files from directory |
379 if(initSoundFiles() != 0) | 381 if(initSoundFiles() != 0) |
413 | 415 |
414 if(forceSensors && !useAudioTest) { | 416 if(forceSensors && !useAudioTest) { |
415 if(gVerbose==1) | 417 if(gVerbose==1) |
416 cout << "main() : creating control thread" << endl; | 418 cout << "main() : creating control thread" << endl; |
417 | 419 |
418 if(rt_task_create(&rtSensorThread, rtSensorThreadName, 0, 95, T_JOINABLE | T_FPU)) { | 420 if(rt_task_create(&rtSensorThread, rtSensorThreadName, 0, BEAGLERT_AUDIO_PRIORITY - 5, T_JOINABLE | T_FPU)) { |
419 cout << "Error:unable to create Xenomai control thread" << endl; | 421 cout << "Error:unable to create Xenomai control thread" << endl; |
420 return -1; | 422 return -1; |
421 } | 423 } |
422 if(rt_task_start(&rtSensorThread, &sensorLoop, 0)) { | 424 if(rt_task_start(&rtSensorThread, &sensorLoop, 0)) { |
423 cout << "Error:unable to start Xenomai control thread" << endl; | 425 cout << "Error:unable to start Xenomai control thread" << endl; |