Skip to content

Commit

Permalink
Merge pull request #42 from marchingband/sysex
Browse files Browse the repository at this point in the history
Add sysex commands to control WiFi on/off
Patch Wav Upload bug, web requests need the correct mime type or (very silly) server lib occasionally parses the body as query params and explodes.
  • Loading branch information
marchingband authored Apr 3, 2022
2 parents 8212936 + d5f0be2 commit b8024b1
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/bundle.h

Large diffs are not rendered by default.

57 changes: 53 additions & 4 deletions src/midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,40 @@
#include "midi_in.h"
#include "ws_log.h"
#include "midi.h"
#include "server.h"

midiXparser midiParser;
midiXparser usbMidiParser;
midiXparser webMidiParser;
uint8_t *msg;
uint8_t *usb_msg;
uint8_t *web_msg;
uint8_t sysex_byte;

void handle_sysex(void)
{
switch(sysex_byte){
case 0x01: // WiFi on
log_i("got sysex 0x01, wifi on");
if(!get_wifi_is_on())
server_resume();
break;
case 0x02: // WiFi off
log_i("got sysex 0x02, wifi off");
if(get_wifi_is_on())
server_pause();
break;
default:
log_e("got unkown sysex command");
break;
}
}

void midi_parser_init(void)
{
midiParser.setMidiMsgFilter( midiXparser::channelVoiceMsgTypeMsk );
usbMidiParser.setMidiMsgFilter( midiXparser::channelVoiceMsgTypeMsk );
webMidiParser.setMidiMsgFilter( midiXparser::channelVoiceMsgTypeMsk );
midiParser.setMidiMsgFilter( midiXparser::channelVoiceMsgTypeMsk | midiXparser::sysExMsgTypeMsk );
usbMidiParser.setMidiMsgFilter( midiXparser::channelVoiceMsgTypeMsk | midiXparser::sysExMsgTypeMsk );
webMidiParser.setMidiMsgFilter( midiXparser::channelVoiceMsgTypeMsk | midiXparser::sysExMsgTypeMsk );
}

extern "C" uint8_t* midi_parse(uint8_t in)
Expand All @@ -34,6 +54,16 @@ extern "C" uint8_t* midi_parse(uint8_t in)
msg = midiParser.getMidiMsg();
return msg;
}
else if(midiParser.getMidiMsgType() == midiXparser::sysExMsgTypeMsk) // sysex EOX
{
int len = midiParser.getSysExMsgLen();
if(len == 1)
handle_sysex();
}
}
else if(midiParser.isSysExMode() && midiParser.isByteCaptured()) // sysex data
{
sysex_byte = midiParser.getByte();
}
return NULL;
}
Expand All @@ -52,13 +82,22 @@ extern "C" uint8_t* usb_midi_parse(uint8_t in)
usb_msg = usbMidiParser.getMidiMsg();
return usb_msg;
}
else if(usbMidiParser.getMidiMsgType() == midiXparser::sysExMsgTypeMsk) // sysex EOX
{
int len = usbMidiParser.getSysExMsgLen();
if(len == 1)
handle_sysex();
}
}
else if(usbMidiParser.isSysExMode() && usbMidiParser.isByteCaptured()) // sysex data
{
sysex_byte = usbMidiParser.getByte();
}
return NULL;
}

extern "C" uint8_t* web_midi_parse(uint8_t in)
{
// log_i("got a byte %d", in);
if ( webMidiParser.parse( in ) ) // Do we received a channel voice msg ?
{
if (
Expand All @@ -71,6 +110,16 @@ extern "C" uint8_t* web_midi_parse(uint8_t in)
web_msg = webMidiParser.getMidiMsg();
return web_msg;
}
else if(webMidiParser.getMidiMsgType() == midiXparser::sysExMsgTypeMsk) // sysex EOX
{
int len = webMidiParser.getSysExMsgLen();
if(len == 1)
handle_sysex();
}
}
else if(webMidiParser.isSysExMode() && webMidiParser.isByteCaptured()) // sysex data
{
sysex_byte = webMidiParser.getByte();
}
return NULL;
}
11 changes: 11 additions & 0 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,22 @@ void handleWav(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t
if(index==0){
//start
//wav_player_pause();
// log_i("start len %d", len);
AsyncWebHeader* size_string = request->getHeader("size");
sscanf(size_string->value().c_str(), "%d", &w_size);
// log_i("size %d", w_size);
AsyncWebHeader* name = request->getHeader("name");
strcpy(&w_name[0], name->value().c_str());
// log_i("name %s", w_name);
AsyncWebHeader* voice_string = request->getHeader("voice");
sscanf(voice_string->value().c_str(), "%d", &w_voice);
// log_i("voice %d", w_voice);
AsyncWebHeader* note_string = request->getHeader("note");
sscanf(note_string->value().c_str(), "%d", &w_note);
// log_i("note %d", w_note);
// log_i("%s w_size %d w_voice %d w_note %d", w_name, w_size, w_voice, w_note);
w_start_block = find_gap_in_file_system(w_size);
// log_i("w_start_block %d",w_start_block);
if(w_start_block == 0)
{
// error no mem
Expand All @@ -264,12 +271,16 @@ void handleWav(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t
}
//always
feedLoopWDT();
// log_i("len %d", len);
write_wav_to_emmc(data, w_start_block, len);
w_bytes_read += len;
if(index + len == total){
//done
// log_i("close %d");
close_wav_to_emmc();
add_wav_to_file_system(&w_name[0],w_voice,w_note,w_start_block,total);
request->send(200);
// log_i("done");
//wav_player_resume();
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/wvr_0.3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ void logRam(){
Serial.printf("Free PSRAM: %d\n", ESP.getFreePsram());
}

// void forceARP(){
// char *netif = netif_list;
// while(netif){
// netif = *((char **) netif);
// }
// }

struct metadata_t metadata;

void wvr_init(bool useFTDI, bool useUsbMidi, bool checkRecoveryModePin) {
Expand Down Expand Up @@ -136,4 +143,6 @@ void wvr_init(bool useFTDI, bool useUsbMidi, bool checkRecoveryModePin) {

log_pin_config();
logRam();

// forceARP();
}
2 changes: 1 addition & 1 deletion src/wvr_0.3.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef WVR_0_3_H
#define WVR_0_3_H

#define VERSION_CODE "3.1.1"
#define VERSION_CODE "3.2.0"

void wvr_init(bool useFTDI, bool useUsbMidi, bool checkRecoveryModePin);

Expand Down

0 comments on commit b8024b1

Please sign in to comment.