mirror of
https://github.com/supleed2/EIE4-FYP.git
synced 2024-09-19 21:36:17 +00:00
Add verbose flag to can_listen
command
This commit is contained in:
parent
783dc57e4f
commit
cd7efb15c0
|
@ -119,7 +119,7 @@ static void help(void) {
|
||||||
puts("can_read - Receive CAN Frames and print (delay in s)");
|
puts("can_read - Receive CAN Frames and print (delay in s)");
|
||||||
puts("can_watch - Watch CAN Frames at 2Hz");
|
puts("can_watch - Watch CAN Frames at 2Hz");
|
||||||
#ifdef CSR_AUDIO_BASE
|
#ifdef CSR_AUDIO_BASE
|
||||||
puts("can_listen - Play CAN Frames as Audio");
|
puts("can_listen - Play CAN Frames as Audio (-v for verbose)");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -354,7 +354,13 @@ static void can_watch_cmd() {
|
||||||
#ifdef CSR_AUDIO_BASE
|
#ifdef CSR_AUDIO_BASE
|
||||||
const char *notes[85] = {"None", "C1", "C1#", "D1", "D1#", "E1", "F1", "F1#", "G1", "G1#", "A1", "A1#", "B1", "C2", "C2#", "D2", "D2#", "E2", "F2", "F2#", "G2", "G2#", "A2", "A2#", "B2", "C3", "C3#", "D3", "D3#", "E3", "F3", "F3#", "G3", "G3#", "A3", "A3#", "B3", "C4", "C4#", "D4", "D4#", "E4", "F4", "F4#", "G4", "G4#", "A4", "A4#", "B4", "C5", "C5#", "D5", "D5#", "E5", "F5", "F5#", "G5", "G5#", "A5", "A5#", "B5", "C6", "C6#", "D6", "D6#", "E6", "F6", "F6#", "G6", "G6#", "A6", "A6#", "B6", "C7", "C7#", "D7", "D7#", "E7", "F7", "F7#", "G7", "G7#", "A7", "A7#", "B7"};
|
const char *notes[85] = {"None", "C1", "C1#", "D1", "D1#", "E1", "F1", "F1#", "G1", "G1#", "A1", "A1#", "B1", "C2", "C2#", "D2", "D2#", "E2", "F2", "F2#", "G2", "G2#", "A2", "A2#", "B2", "C3", "C3#", "D3", "D3#", "E3", "F3", "F3#", "G3", "G3#", "A3", "A3#", "B3", "C4", "C4#", "D4", "D4#", "E4", "F4", "F4#", "G4", "G4#", "A4", "A4#", "B4", "C5", "C5#", "D5", "D5#", "E5", "F5", "F5#", "G5", "G5#", "A5", "A5#", "B5", "C6", "C6#", "D6", "D6#", "E6", "F6", "F6#", "G6", "G6#", "A6", "A6#", "B6", "C7", "C7#", "D7", "D7#", "E7", "F7", "F7#", "G7", "G7#", "A7", "A7#", "B7"};
|
||||||
const uint32_t freqs[85] = {0, 33, 35, 37, 39, 41, 44, 46, 49, 52, 55, 58, 62, 65, 69, 73, 78, 82, 87, 93, 98, 104, 110, 117, 123, 131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247, 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988, 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976, 2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951};
|
const uint32_t freqs[85] = {0, 33, 35, 37, 39, 41, 44, 46, 49, 52, 55, 58, 62, 65, 69, 73, 78, 82, 87, 93, 98, 104, 110, 117, 123, 131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247, 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988, 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976, 2093, 2217, 2349, 2489, 2637, 2794, 2960, 3136, 3322, 3520, 3729, 3951};
|
||||||
static void can_listen_cmd() {
|
static void can_listen_cmd(char **val) {
|
||||||
|
char *token = get_token(val);
|
||||||
|
bool verbose = false;
|
||||||
|
if (strcmp(token, "-v") == 0) {
|
||||||
|
printf("Verbose mode: debug messages will be printed");
|
||||||
|
verbose = true;
|
||||||
|
}
|
||||||
for (int i = 0; i < 32; i++) {
|
for (int i = 0; i < 32; i++) {
|
||||||
set_wave(i, WAVE_SINE);
|
set_wave(i, WAVE_SINE);
|
||||||
}
|
}
|
||||||
|
@ -371,7 +377,8 @@ static void can_listen_cmd() {
|
||||||
active_notes[note] = true; // Mark note as active
|
active_notes[note] = true; // Mark note as active
|
||||||
active_osc[active_oscs] = note; // Set oscillator to note
|
active_osc[active_oscs] = note; // Set oscillator to note
|
||||||
set_freq(active_oscs, freqs[note]); // Set oscillator frequency
|
set_freq(active_oscs, freqs[note]); // Set oscillator frequency
|
||||||
printf("Playing note %s (%d) on oscillator %d\n", notes[note], note, active_oscs);
|
if (verbose)
|
||||||
|
printf("Playing note %s (%d) on oscillator %d\n", notes[note], note, active_oscs);
|
||||||
active_oscs++;
|
active_oscs++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -380,31 +387,38 @@ static void can_listen_cmd() {
|
||||||
if (active_notes[note] == false) { // Not active, ignore
|
if (active_notes[note] == false) { // Not active, ignore
|
||||||
break;
|
break;
|
||||||
} else if (true) {
|
} else if (true) {
|
||||||
printf("Finding note %s (%d)\n", notes[note], note); // Debug
|
if (verbose)
|
||||||
active_notes[note] = false; // Mark note as inactive
|
printf("Finding note %s (%d)\n", notes[note], note); // Debug
|
||||||
active_oscs--; // Decrement active oscillators
|
active_notes[note] = false; // Mark note as inactive
|
||||||
if (note == active_osc[active_oscs]) { // Note is last active
|
active_oscs--; // Decrement active oscillators
|
||||||
active_osc[active_oscs] = 0; // Clear oscillator
|
if (note == active_osc[active_oscs]) { // Note is last active
|
||||||
set_freq(active_oscs, 0); // Set frequency to 0
|
active_osc[active_oscs] = 0; // Clear oscillator
|
||||||
printf("Stopping last note %s (%d)\n", notes[note], note); // Debug
|
set_freq(active_oscs, 0); // Set frequency to 0
|
||||||
|
if (verbose)
|
||||||
|
printf("Stopping last note %s (%d)\n", notes[note], note); // Debug
|
||||||
break;
|
break;
|
||||||
} // Note is not last active
|
} // Note is not last active
|
||||||
printf("Note %s (%d) is not last active\n", notes[note], note); // Debug
|
if (verbose)
|
||||||
for (uint32_t i = 0; i <= active_oscs; i++) { // Find note
|
printf("Note %s (%d) is not last active\n", notes[note], note); // Debug
|
||||||
printf("Checking oscillator %d\n", i); // Debug
|
for (uint32_t i = 0; i <= active_oscs; i++) { // Find note
|
||||||
if (note != active_osc[i]) { // Not this oscillator
|
if (verbose)
|
||||||
printf("Not in oscillator %d\n", i); // Debug
|
printf("Checking oscillator %d\n", i); // Debug
|
||||||
|
if (note != active_osc[i]) { // Not this oscillator
|
||||||
|
if (verbose)
|
||||||
|
printf("Not in oscillator %d\n", i); // Debug
|
||||||
continue;
|
continue;
|
||||||
} // Found note
|
} // Found note
|
||||||
uint32_t swapped_note = active_osc[active_oscs]; // Get last active note
|
uint32_t swapped_note = active_osc[active_oscs]; // Get last active note
|
||||||
set_freq(i, freqs[swapped_note]); // Set frequency of oscillator to last active note
|
set_freq(i, freqs[swapped_note]); // Set frequency of oscillator to last active note
|
||||||
active_osc[i] = swapped_note; // Set oscillator to last active note
|
active_osc[i] = swapped_note; // Set oscillator to last active note
|
||||||
set_freq(active_oscs, 0); // Set last oscillator to 0
|
set_freq(active_oscs, 0); // Set last oscillator to 0
|
||||||
active_osc[active_oscs] = 0; // Clear last active note
|
active_osc[active_oscs] = 0; // Clear last active note
|
||||||
printf("Stopping note %s (%d)\n", notes[note], note); // Debug
|
if (verbose)
|
||||||
goto done; // Done
|
printf("Stopping note %s (%d)\n", notes[note], note); // Debug
|
||||||
|
goto done; // Done
|
||||||
}
|
}
|
||||||
printf("Note up for note %s not found\n", notes[note]); // Error
|
if (verbose)
|
||||||
|
printf("Note up for note %s not found\n", notes[note]); // Error
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -492,7 +506,7 @@ static void console_service(void) {
|
||||||
can_watch_cmd();
|
can_watch_cmd();
|
||||||
#ifdef CSR_AUDIO_BASE
|
#ifdef CSR_AUDIO_BASE
|
||||||
else if (strcmp(token, "can_listen") == 0)
|
else if (strcmp(token, "can_listen") == 0)
|
||||||
can_listen_cmd();
|
can_listen_cmd(&str);
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
prompt();
|
prompt();
|
||||||
|
|
Loading…
Reference in a new issue