From 9553968f636e6ea00cdc0c68abd69661db60b94b Mon Sep 17 00:00:00 2001 From: marchingband Date: Mon, 7 Jun 2021 13:59:44 -0700 Subject: [PATCH] touch pad setup --- src/WVR.cpp | 21 +++- src/WVR.h | 12 +- src/button.cpp | 109 ++++++++++++++++- src/button.h | 6 +- src/dev_board.cpp | 15 ++- src/file_system.c | 20 +++- src/file_system.h | 1 + src/gpio.cpp | 291 +++++++++++++++++++--------------------------- src/gpio.h | 8 ++ src/midi_in.c | 5 + src/midi_in.h | 2 + src/mkr_board.cpp | 43 ++++--- src/server.cpp | 23 +++- src/server.h | 1 + src/wav_player.c | 10 +- src/wav_player.h | 2 + src/wvr_0.3.cpp | 21 +++- src/wvr_0.3.h | 13 +-- src/wvr_pins.c | 90 ++++++++++++++ src/wvr_pins.h | 62 +--------- src/wvr_ui.h | 2 +- 21 files changed, 476 insertions(+), 281 deletions(-) create mode 100644 src/gpio.h create mode 100644 src/wvr_pins.c diff --git a/src/WVR.cpp b/src/WVR.cpp index 1b66232..6121e16 100644 --- a/src/WVR.cpp +++ b/src/WVR.cpp @@ -6,25 +6,42 @@ WVR::WVR() { + // this->autoConfigPins = true; + this->wifiIsOn = get_wifi_is_on(); + // this->mute = false; + // this->globalVolume = 127; } void WVR::begin() { wvr_init(); } + void WVR::play(uint8_t voice, uint8_t note, uint8_t velocity) { play_wav(voice,note,velocity); } + void WVR::stop(uint8_t voice, uint8_t note) { stop_wav(voice,note); } -void WVR::serverPause() + +void WVR::wifiOff() { server_pause(); + this->wifiIsOn = get_wifi_is_on(); } -void WVR::serverResume() + +void WVR::wifiOn() { server_resume(); + this->wifiIsOn = get_wifi_is_on(); +} + +void WVR::toggleWifi() +{ + this->wifiIsOn ? wifiOff() : wifiOn(); + // wifiIsOn = !wifiIsOn; + this->wifiIsOn = get_wifi_is_on(); } \ No newline at end of file diff --git a/src/WVR.h b/src/WVR.h index 9f677cb..caf48fd 100644 --- a/src/WVR.h +++ b/src/WVR.h @@ -11,11 +11,17 @@ class WVR { public: WVR(); - void begin(); + void begin(void); void play(uint8_t voice, uint8_t note, uint8_t velocity); void stop(uint8_t voice, uint8_t note); - void serverPause(); - void serverResume(); + void wifiOff(void); + void wifiOn(void); + void toggleWifi(void); + // int globalVolume; + // bool mute; + // bool autoConfigPins; + bool wifiIsOn; + }; #endif \ No newline at end of file diff --git a/src/button.cpp b/src/button.cpp index 6259646..5f8b8dc 100644 --- a/src/button.cpp +++ b/src/button.cpp @@ -5,15 +5,40 @@ #include "button.h" #include "wvr_pins.h" #include "ws_log.h" +#include "file_system.h" +#include "wav_player.h" +#include "midi_in.h" +#include "WVR.h" + +#define TOUCH_THRESH_NO_USE (0) +#define TOUCH_THRESH_PERCENT (80) +#define TOUCHPAD_FILTER_TOUCH_PERIOD (10) xQueueHandle gpio_queue_handle; xTaskHandle gpio_task_handle; + static void gpioTask(void* x) { button_event_t *event; + uint32_t touch_reg = 0; for(;;) { if(xQueueReceive(gpio_queue_handle, &event, portMAX_DELAY)) { - event->button->handleChange(event->val); + log_i("gpio task pin:%d val:%d",event->pin, event->val); + if(event->button->touch != 1) + { + // digital + event->button->handleChange(event->val); + } + else + { + // touch + touch_reg = ( touch_reg | (uint32_t)event->val ); // cache the new parts of this event + if((touch_reg >> gpioNumToTPNum(event->pin)) & 0x01) + { + event->button->handleChange(0); // 0 to invert the edge + touch_reg &= ~(1UL << gpioNumToTPNum(event->pin)); // clear that bit from the cache but leave the rest for the other touch interrupts + } + } } }; } @@ -24,13 +49,40 @@ void IRAM_ATTR isr(void *e){ xQueueSendFromISR(gpio_queue_handle, &event, NULL); } +void IRAM_ATTR touch_isr(void *e){ + // isr_log_i("touch isr"); + button_event_t *event = (button_event_t*)e; + uint32_t pad_intr = touch_pad_get_status(); + touch_pad_clear_status(); + // send the whole register to the queue so the other pad interrupts can read it even though its bee cleared + event->val = pad_intr; + xQueueSendFromISR(gpio_queue_handle, &event, NULL); +} + Button::Button(int pin, int mode, int dbnc){ this->pin = pin; this->mode = mode; this->dbnc = dbnc; this->last = 0; + this->touch = false; + this->handlePress = NULL; + this->handleRelease = NULL; + event.pin = pin; + event.button = this; + // gpio_reset_pin(gpioNumToGpioNum_T(pin)); +} + +Button::Button(int pin, int mode, int dbnc, bool touch){ + this->pin = pin; + this->mode = mode; + this->dbnc = dbnc; + this->last = 0; + this->touch = true; + this->handlePress = NULL; + this->handleRelease = NULL; event.pin = pin; event.button = this; + // gpio_reset_pin(gpioNumToGpioNum_T(pin)); } Button::~Button(){ @@ -40,7 +92,16 @@ Button::~Button(){ void Button::onPress(void(*handlePress)()){ this->handlePress = handlePress; - attachInterruptArg(pin, isr, (void*)&event, CHANGE); + if(this->touch != 1) + { + // digital read mode + attachInterruptArg(pin, isr, (void*)&event, CHANGE); + } + else + { + // capacitive touch mode + init_touch_pad(pin, (void*)&event); + } } void Button::onRelease(void(*handleRelease)()){ @@ -50,6 +111,7 @@ void Button::onRelease(void(*handleRelease)()){ void Button::handleChange(int val){ // if EDGE_NONE then ignore + log_i("pin:%d val:%d",pin,val); if(mode != RISING && mode != FALLING) return; int now = millis(); if((now - last) > dbnc){ @@ -58,18 +120,53 @@ void Button::handleChange(int val){ (val==0 && mode == FALLING) || (val==1 && mode == RISING) ){ - if(handlePress){ + if(handlePress != NULL) + { handlePress(); } - } else { - if(handleRelease){ + } + else + { + if(handleRelease != NULL) + { handleRelease(); } } } } +static bool touch_initialized = false; + +void init_touch(void) +{ + log_i("*"); + touch_pad_init(); + touch_pad_set_fsm_mode(TOUCH_FSM_MODE_TIMER); + touch_pad_set_voltage(TOUCH_HVOLT_2V7, TOUCH_LVOLT_0V5, TOUCH_HVOLT_ATTEN_0V5); + // touch_pad_filter_start(TOUCHPAD_FILTER_TOUCH_PERIOD); + // touch_initialized = true; +} + +void init_touch_pad(int pin, void *event) +{ + log_i("*"); + if(!touch_initialized) + { + init_touch(); + } + uint16_t touch_value; + touch_pad_config( gpioNumToTPNum(pin), TOUCH_THRESH_NO_USE); + touch_pad_filter_start(TOUCHPAD_FILTER_TOUCH_PERIOD); + touch_initialized = true; + + touch_pad_read_filtered( gpioNumToTPNum(pin), &touch_value); + ESP_ERROR_CHECK(touch_pad_set_thresh( gpioNumToTPNum(pin), touch_value * 2 / 3)); + log_i("touch setup TPNUM:%d touchValue:%d",gpioNumToTPNum(pin),touch_value); + touch_pad_isr_register(touch_isr, (void*)event); + touch_pad_intr_enable(); +} + void button_init(){ gpio_queue_handle = xQueueCreate(10, sizeof(button_event_t)); xTaskCreate(gpioTask, "gpio_task", 2048, NULL, 3, &gpio_task_handle); -} +} \ No newline at end of file diff --git a/src/button.h b/src/button.h index 7980d7c..a060b9d 100644 --- a/src/button.h +++ b/src/button.h @@ -9,16 +9,20 @@ class Button { int dbnc; int last; int mode; + bool touch; void (*handlePress)(); void (*handleRelease)(); button_event_t event; Button(int pin, int mode, int dbnc); + Button(int pin, int mode, int dbnc, bool touch); ~Button(); void onPress(void(*handlePress)()); void onRelease(void(*handlePress)()); void handleChange(int val); }; -void button_init(); +void button_init(void); +void init_touch(void); +void init_touch_pad(int pin, void *event); #endif \ No newline at end of file diff --git a/src/dev_board.cpp b/src/dev_board.cpp index 8a2ab81..977d197 100644 --- a/src/dev_board.cpp +++ b/src/dev_board.cpp @@ -8,11 +8,11 @@ extern "C" void encoder_init(void); void rgb_init(void); extern "C" void pot_init(void); -Button b1(D5,FALLING, 50); -Button b2(D6,FALLING, 50); -Button b3(D7,FALLING, 50); -Button s1(D3,FALLING, 50); -Button s2(D4,FALLING, 50); +// Button b1(D5,FALLING, 50); +// Button b2(D6,FALLING, 50); +// Button b3(D7,FALLING, 50); +// Button s1(D3,FALLING, 50); +// Button s2(D4,FALLING, 50); void logB1(){ wlog_i("1"); @@ -45,6 +45,11 @@ void logSw2Down(){ } void dev_board_init(){ + Button b1(D5,FALLING, 50); + Button b2(D6,FALLING, 50); + Button b3(D7,FALLING, 50); + Button s1(D3,FALLING, 50); + Button s2(D4,FALLING, 50); button_init(); encoder_init(); diff --git a/src/file_system.c b/src/file_system.c index bc4edf9..4e19c5d 100644 --- a/src/file_system.c +++ b/src/file_system.c @@ -518,7 +518,8 @@ void add_wav_to_file_system(char *name,int voice,int note,size_t start_block,siz voice_data[note].start_block = start_block; voice_data[note].length = size; voice_data[note].empty = 0; - memcpy(voice_data[note].name,name,24); + bzero(voice_data[note].name,24); + strcpy(voice_data[note].name,name); ESP_ERROR_CHECK(emmc_write(voice_data,voice_start_block,BLOCKS_PER_VOICE)); read_wav_lut_from_disk(); // read_rack_lut_from_disk(); @@ -1142,6 +1143,23 @@ void updatePinConfig(cJSON *config){ cJSON_Delete(json); } +void log_pin_config(void) +{ + for(int i=0;i<14;i++) + { + log_i("pin %d action:%d edge:%d gpio:%d note:%d touch:%d velocity:%d dbnc:%d", + i, + pin_config_lut[i].action, + pin_config_lut[i].edge, + pin_config_lut[i].gpio_num, + pin_config_lut[i].note, + pin_config_lut[i].touch, + pin_config_lut[i].velocity, + pin_config_lut[i].debounce + ); + } +} + void updateMetadata(cJSON *config){ cJSON *json = cJSON_Parse(config); metadata.global_volume = cJSON_GetObjectItemCaseSensitive(json, "globalVolume")->valueint; diff --git a/src/file_system.h b/src/file_system.h index 0cf9cfa..c5db5ff 100644 --- a/src/file_system.h +++ b/src/file_system.h @@ -343,6 +343,7 @@ size_t search_directory(struct wav_lu_t *_data, size_t num_data_entries, size_t void current_bank_up(void); void current_bank_down(void); struct metadata_t *get_metadata(void); +void log_pin_config(void); #ifdef __cplusplus } diff --git a/src/gpio.cpp b/src/gpio.cpp index 35f158e..0dd5721 100644 --- a/src/gpio.cpp +++ b/src/gpio.cpp @@ -3,197 +3,140 @@ #include "wvr_pins.h" #include "ws_log.h" #include "file_system.h" +#include "gpio.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/queue.h" +#include "WVR.h" +#include "midi_in.h" +#include "server.h" + // extern "C" { // #include "wav_player.h" // } extern "C" void rpc_out(int procedure, int arg0, int arg1, int arg2); -extern "C" void server_pause(void); -extern "C" void server_resume(void); -// extern "C" void current_bank_up(void); -// extern "C" void current_bank_down(void); +// extern "C" void server_pause(void); +// extern "C" void server_resume(void); struct pin_config_t *pin_config_lut; -extern QueueHandle_t midi_queue; struct midi_event_t gpio_midi_event; -bool wifi_on = true; -bool wvr_pin_override[14] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0}; -Button pinD0(D0,FALLING,300); -Button pinD1(D1,FALLING,300); -Button pinD2(D2,FALLING,300); -Button pinD3(D3,FALLING,300); -Button pinD4(D4,FALLING,300); -Button pinD5(D5,FALLING,300); -Button pinD6(D6,FALLING,300); -Button pinD7(D7,FALLING,300); -Button pinD8(D8,FALLING,300); -Button pinD9(D9,FALLING,300); -Button pinD10(D10,FALLING,300); -Button pinD11(D11,FALLING,300); -Button pinD12(D12,FALLING,300); -Button pinD13(D13,FALLING,300); +Button *buttons[14] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; -Button *pin_buttons[14] = {&pinD0,&pinD1,&pinD2,&pinD3,&pinD4,&pinD5,&pinD6,&pinD7,&pinD8,&pinD9,&pinD10,&pinD11,&pinD12,&pinD13,}; +extern bool mute; -void note_on(uint8_t pin) -{ - gpio_midi_event.channel = 0; - gpio_midi_event.code = 9; - gpio_midi_event.note = pin_config_lut[pin].note; - gpio_midi_event.velocity = pin_config_lut[pin].velocity; - xQueueSendToBack(midi_queue,(void *) &gpio_midi_event, portMAX_DELAY); -} - -void on_press(uint8_t i) -{ - wlog_i("onPress %d",i); - pin_config_t pin = pin_config_lut[i]; - switch (pin.action) - { - case NOTE_ON: - note_on(i); - break; - case BANK_UP: - current_bank_up(); - break; - case BANK_DOWN: - current_bank_down(); - break; - case TOGGLE_WIFI: - wifi_on ? server_pause() : server_resume(); - wifi_on = !wifi_on; - break; - default: - break; - } -} +static struct metadata_t *metadata = get_metadata(); -void on_release(uint8_t pin) -{ - wlog_i("onRelease %d",pin); - gpio_midi_event.channel = 0; - gpio_midi_event.code = 8; - gpio_midi_event.note = pin_config_lut[pin].note; - gpio_midi_event.velocity = 0; - xQueueSendToBack(midi_queue,(void *) &gpio_midi_event, portMAX_DELAY); +struct wav_player_event_t wav_player_event; +extern "C" { + QueueHandle_t wav_player_queue; } -void gpio_update_config(void) +void on_press_per_config(int pin_num) { - for(int i=0;i<14;i++) - { - pin_buttons[i]->dbnc = pin_config_lut[i].debounce; - pin_buttons[i]->mode = - pin_config_lut[i].edge == EDGE_RISING ? RISING : - pin_config_lut[i].edge == EDGE_FALLING ? FALLING : - EDGE_NONE; - wlog_i("pin%d debounce:%d",i,pin_config_lut[i].debounce); - wlog_i("pin%d edge:%d",i,pin_config_lut[i].edge); - wlog_i("pin%d action:%d",i,pin_config_lut[i].action); - wlog_i("pin%d velocity:%d",i,pin_config_lut[i].velocity); + uint8_t *channel_lut = get_channel_lut(); + struct pin_config_t pin = pin_config_lut[pin_num]; + switch(pin.action){ + case NOTE_ON: + wav_player_event.code = MIDI_NOTE_ON; + wav_player_event.note = pin.note; + wav_player_event.velocity = pin.velocity; + wav_player_event.voice = channel_lut[0]; + xQueueSendToBack(wav_player_queue, (void *)&wav_player_event, portMAX_DELAY); + break; + case BANK_UP: + channel_lut[0] += (channel_lut[0] < 15); + break; + case BANK_DOWN: + channel_lut[0] -= (channel_lut[0] > 0); + break; + case WVR_WIFI_ON: + if(!get_wifi_is_on()) + { + server_resume(); + } + break; + case WVR_WIFI_OFF: + if(get_wifi_is_on()) + { + server_pause(); + } + break; + case TOGGLE_WIFI: + if(get_wifi_is_on()) + { + server_pause(); + } + else + { + server_resume(); + } + break; + case VOLUME_UP: + metadata->global_volume += (metadata->global_volume < 127); + break; + case VOLUME_DOWN: + metadata->global_volume -= (metadata->global_volume > 0); + break; + case MUTE_ON: + mute = true; + break; + case MUTE_OFF: + mute = false; + break; + case TOGGLE_MUTE: + mute = !mute; + break; + default: + break; } } -void gpio_init(void) +void wvr_gpio_init(void) { - if (!wvr_pin_override[0]) - { - gpio_reset_pin(GPIO_NUM_3); - pinMode(D0, INPUT_PULLUP); - pinD0.onPress([](){on_press(0);}); - pinD0.onRelease([](){on_release(0);}); - } - if (!wvr_pin_override[1]) - { - gpio_reset_pin(GPIO_NUM_1); - pinMode(D1, INPUT_PULLUP); - pinD1.onPress([](){on_press(1);}); - pinD1.onRelease([](){on_release(1);}); - } - if (!wvr_pin_override[2]) - { - gpio_reset_pin(GPIO_NUM_21); - pinMode(D2, INPUT_PULLUP); - pinD2.onPress([](){on_press(2);}); - pinD2.onRelease([](){on_release(2);}); - } - if (!wvr_pin_override[3]) - { - gpio_reset_pin(GPIO_NUM_19); - pinMode(D3, INPUT_PULLUP); - pinD3.onPress([](){on_press(3);}); - pinD3.onRelease([](){on_release(3);}); - } - if (!wvr_pin_override[4]) - { - gpio_reset_pin(GPIO_NUM_18); - pinMode(D4, INPUT_PULLUP); - pinD4.onPress([](){on_press(4);}); - pinD4.onRelease([](){on_release(4);}); - } - if (!wvr_pin_override[5]) - { - gpio_reset_pin(GPIO_NUM_5); - pinMode(D5, INPUT_PULLUP); - pinD5.onPress([](){on_press(5);}); - pinD5.onRelease([](){on_release(5);}); - } - if (!wvr_pin_override[6]) - { - gpio_reset_pin(GPIO_NUM_0); - pinMode(D6, INPUT_PULLUP); - pinD6.onPress([](){on_press(6);}); - pinD6.onRelease([](){on_release(6);}); - } - if (!wvr_pin_override[7]) - { - gpio_reset_pin(GPIO_NUM_36); - pinMode(D7, INPUT_PULLUP); - pinD7.onPress([](){on_press(7);}); - pinD7.onRelease([](){on_release(7);}); - } - if (!wvr_pin_override[8]) - { - gpio_reset_pin(GPIO_NUM_39); - pinMode(D8, INPUT_PULLUP); - pinD8.onPress([](){on_press(8);}); - pinD8.onRelease([](){on_release(8);}); - } - if (!wvr_pin_override[9]) - { - gpio_reset_pin(GPIO_NUM_34); - pinMode(D9, INPUT_PULLUP); - pinD9.onPress([](){on_press(9);}); - pinD9.onRelease([](){on_release(9);}); - } - if (!wvr_pin_override[10]) - { - gpio_reset_pin(GPIO_NUM_35); - pinMode(D10, INPUT_PULLUP); - pinD10.onPress([](){on_press(10);}); - pinD10.onRelease([](){on_release(10);}); - } - if (!wvr_pin_override[11]) - { - gpio_reset_pin(GPIO_NUM_32); - pinMode(D11, INPUT_PULLUP); - pinD11.onPress([](){on_press(11);}); - pinD11.onRelease([](){on_release(11);}); - } - if (!wvr_pin_override[12]) - { - gpio_reset_pin(GPIO_NUM_33); - pinMode(D12, INPUT_PULLUP); - pinD12.onPress([](){on_press(12);}); - pinD12.onRelease([](){on_release(12);}); - } - if (!wvr_pin_override[13]) - { - gpio_reset_pin(GPIO_NUM_27); - pinMode(D13, INPUT_PULLUP); - pinD13.onPress([](){on_press(13);}); - pinD13.onRelease([](){on_release(13);}); - } - gpio_update_config(); + for(int i=2;i<14;i++) + { + gpio_num_t gpio_num = gpio_pins[i]; + int pin_num = wvr_pins[i]; + pin_config_t pin = pin_config_lut[i]; + gpio_reset_pin(gpio_num); // should this move to the button constructor to remove touch? + if(pin.touch != 1) + { + // digital mode + if(pin.edge == EDGE_NONE) + { + continue; + } + else if(pin.edge == EDGE_FALLING) + { + pinMode(pin_num, INPUT_PULLUP); + buttons[i] = new Button(pin_num, FALLING, pin.debounce); + } + else if(pin.edge == EDGE_RISING) + { + pinMode(pin_num, INPUT_PULLDOWN); + buttons[i] = new Button(pin_num, RISING, pin.debounce); + } + } + else + { + // touch mode + buttons[i] = new Button(pin_num, FALLING, pin.debounce, true); + } + } + if(buttons[0] != NULL) buttons[0]->onPress([](){on_press_per_config(0);}); + if(buttons[1] != NULL) buttons[1]->onPress([](){on_press_per_config(1);}); + if(buttons[2] != NULL) buttons[2]->onPress([](){on_press_per_config(2);}); + if(buttons[3] != NULL) buttons[3]->onPress([](){on_press_per_config(3);}); + if(buttons[4] != NULL) buttons[4]->onPress([](){on_press_per_config(4);}); + if(buttons[5] != NULL) buttons[5]->onPress([](){on_press_per_config(5);}); + if(buttons[6] != NULL) buttons[6]->onPress([](){on_press_per_config(6);}); + if(buttons[7] != NULL) buttons[7]->onPress([](){on_press_per_config(7);}); + if(buttons[8] != NULL) buttons[8]->onPress([](){on_press_per_config(8);}); + if(buttons[9] != NULL) buttons[9]->onPress([](){on_press_per_config(9);}); + if(buttons[10] != NULL) buttons[10]->onPress([](){on_press_per_config(10);}); + if(buttons[11] != NULL) buttons[11]->onPress([](){on_press_per_config(11);}); + if(buttons[12] != NULL) buttons[12]->onPress([](){on_press_per_config(12);}); + if(buttons[13] != NULL) buttons[13]->onPress([](){on_press_per_config(13);}); } \ No newline at end of file diff --git a/src/gpio.h b/src/gpio.h new file mode 100644 index 0000000..9df401d --- /dev/null +++ b/src/gpio.h @@ -0,0 +1,8 @@ +#ifndef GPIO_H +#define GPIO_H + +void wvr_gpio_init(void); +void on_press(uint8_t i); +void on_release(uint8_t pin); + +#endif \ No newline at end of file diff --git a/src/midi_in.c b/src/midi_in.c index 36fb8ca..f5e546c 100644 --- a/src/midi_in.c +++ b/src/midi_in.c @@ -52,6 +52,11 @@ void init_gpio(void) uint8_t channel_lut[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +uint8_t *get_channel_lut(void) +{ + return &channel_lut[0]; +} + static void read_uart_task() { uart_event_t event; diff --git a/src/midi_in.h b/src/midi_in.h index 5bef8e0..da6429f 100644 --- a/src/midi_in.h +++ b/src/midi_in.h @@ -16,6 +16,8 @@ struct midi_event_t { uint8_t channel; }; +uint8_t *get_channel_lut(void); + #ifdef __cplusplus } #endif diff --git a/src/mkr_board.cpp b/src/mkr_board.cpp index 29a75a2..a281c99 100644 --- a/src/mkr_board.cpp +++ b/src/mkr_board.cpp @@ -5,20 +5,20 @@ extern "C" void play_sound_ext(int i); -Button p1(D13,FALLING, 50); -Button p2(D12,FALLING, 50); -Button p3(D11,FALLING, 50); -Button p4(D10,FALLING, 50); -Button p5(D9,FALLING, 50); -Button p6(D8,FALLING, 50); -Button p7(D7,FALLING, 50); -Button p8(D6,FALLING, 50); -Button p9(D5,FALLING, 50); -Button p10(D4,FALLING, 50); -Button p11(D3,FALLING, 50); -Button p12(D2,FALLING, 50); -Button p13(D1,FALLING, 50); -Button p14(D0,FALLING, 50); +// Button p1(D13,FALLING, 50); +// Button p2(D12,FALLING, 50); +// Button p3(D11,FALLING, 50); +// Button p4(D10,FALLING, 50); +// Button p5(D9,FALLING, 50); +// Button p6(D8,FALLING, 50); +// Button p7(D7,FALLING, 50); +// Button p8(D6,FALLING, 50); +// Button p9(D5,FALLING, 50); +// Button p10(D4,FALLING, 50); +// Button p11(D3,FALLING, 50); +// Button p12(D2,FALLING, 50); +// Button p13(D1,FALLING, 50); +// Button p14(D0,FALLING, 50); void logPress(){ play_sound_ext(40); @@ -30,6 +30,21 @@ void logPress2(){ } void mkr_init(){ + Button p1(D13,FALLING, 50); + Button p2(D12,FALLING, 50); + Button p3(D11,FALLING, 50); + Button p4(D10,FALLING, 50); + Button p5(D9,FALLING, 50); + Button p6(D8,FALLING, 50); + Button p7(D7,FALLING, 50); + Button p8(D6,FALLING, 50); + Button p9(D5,FALLING, 50); + Button p10(D4,FALLING, 50); + Button p11(D3,FALLING, 50); + Button p12(D2,FALLING, 50); + Button p13(D1,FALLING, 50); + Button p14(D0,FALLING, 50); + button_init(); diff --git a/src/server.cpp b/src/server.cpp index 8688e8d..701c613 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -15,6 +15,7 @@ #include "wvr_0.3.h" #include "server.h" #include "file_system.h" +#include "server.h" extern "C" char* print_fs_json(); extern "C" size_t find_gap_in_file_system(size_t size); @@ -30,7 +31,7 @@ extern "C" char* write_recovery_firmware_to_emmc(uint8_t* source, size_t size); extern "C" char* close_recovery_firmware_to_emmc(size_t recovery_firmware_size); // extern "C" size_t add_firmware_and_gui_to_file_system(char *gui_name,char *firmware_name,size_t gui_start_block,size_t firmware_start_block,size_t gui_size,size_t firmware_size); -struct metadata_t metadata; +static struct metadata_t *metadata = get_metadata(); struct wav_lu_t **lut; struct firmware_t *firmware_lut; struct website_t *website_lut; @@ -450,7 +451,7 @@ void handleNewGUI(AsyncWebServerRequest *request, uint8_t *data, size_t len, siz void handleFsjson(AsyncWebServerRequest *request){ char *json = print_fs_json(); size_t size = strlen(json); - wlog_e("fs size is %d",size); + // wlog_e("fs size is %d",size); AsyncWebServerResponse *response = request->beginResponse("text/html", size, [size,json](uint8_t *buffer, size_t maxLen, size_t index) -> size_t { size_t toWrite = min(size - index, maxLen); memcpy(buffer, json + index, toWrite); @@ -472,8 +473,8 @@ void handleFsjson(AsyncWebServerRequest *request){ } void handleEmmcGUI(AsyncWebServerRequest *request){ - size_t size = website_lut[metadata.current_website_index].length; - size_t start_block = website_lut[metadata.current_website_index].start_block; + size_t size = website_lut[metadata->current_website_index].length; + size_t start_block = website_lut[metadata->current_website_index].start_block; request->send("text/html", size, [size,start_block](uint8_t *buffer, size_t maxLen, size_t index) -> size_t { size_t toWrite = min(size - index, maxLen); size_t written = get_website_chunk(start_block, toWrite, buffer, size); @@ -528,14 +529,15 @@ void server_begin() { WiFi.mode(WIFI_AP); + IPAddress IP = IPAddress (192, 168, 5, 18); IPAddress gateway = IPAddress (192, 168, 5, 20); IPAddress NMask = IPAddress (255, 255, 255, 0); WiFi.softAPConfig(IP, gateway, NMask); - WiFi.softAP(metadata.ssid, metadata.passphrase); - log_i("set ssid :%s, set passphrase: %s",metadata.ssid, metadata.passphrase); + WiFi.softAP(metadata->ssid, metadata->passphrase); + log_i("set ssid :%s, set passphrase: %s",metadata->ssid, metadata->passphrase); // again?? WiFi.softAPConfig(IP, gateway, NMask); @@ -666,12 +668,21 @@ void server_begin() { Serial.println("Server started"); } +bool wifi_is_on = true; + +bool get_wifi_is_on() +{ + return wifi_is_on; +} + void server_pause(void){ // _server_pause(); WiFi.mode(WIFI_OFF); + wifi_is_on = false; } void server_resume(void){ // server_begin(); WiFi.mode(WIFI_AP); + wifi_is_on = true; } diff --git a/src/server.h b/src/server.h index c4f52d2..d406e07 100644 --- a/src/server.h +++ b/src/server.h @@ -5,5 +5,6 @@ void server_pause(); void server_resume(); +bool get_wifi_is_on(); #endif \ No newline at end of file diff --git a/src/wav_player.c b/src/wav_player.c index 8210e11..2e84a3a 100644 --- a/src/wav_player.c +++ b/src/wav_player.c @@ -48,7 +48,7 @@ static const char* TAG = "wav_player"; // #define MAX_READS_PER_LOOP 3 struct metadata_t metadata; - +bool mute = false; struct buf_t { struct wav_lu_t wav_data; struct wav_player_event_t wav_player_event; @@ -468,6 +468,14 @@ void wav_player_task(void* pvParameters) { output_buf[i] = scale_sample(output_buf[i], metadata.global_volume); } + // apply the mute + if(mute) + { + for(size_t i=0;iglobalVolume = metadata.global_volume; + // log_i("set global volume : %d", wvr->globalVolume); + dac_init(); logSize("dac"); @@ -111,6 +117,9 @@ void wvr_init(void) { button_init(); logSize("button"); + + wvr_gpio_init(); + logSize("gpio"); rpc_init(); logSize("rpc"); @@ -120,5 +129,13 @@ void wvr_init(void) { server_pause(); } + log_pin_config(); + + // if(wvr->autoConfigPins) + // { + // log_i("auto config pins"); + // wvr_gpio_init(); + // } + logRam(); } \ No newline at end of file diff --git a/src/wvr_0.3.h b/src/wvr_0.3.h index 92e2a6a..dfa3f29 100644 --- a/src/wvr_0.3.h +++ b/src/wvr_0.3.h @@ -1,15 +1,10 @@ #ifndef WVR_0_3_H #define WVR_0_3_H -#ifdef __cplusplus -extern "C" -{ -#endif +// #include "WVR.h" -#define VERSION_CODE "0.3.5" -void wvr_init(); +#define VERSION_CODE "0.3.6" + +void wvr_init(void); -#ifdef __cplusplus -} -#endif #endif \ No newline at end of file diff --git a/src/wvr_pins.c b/src/wvr_pins.c new file mode 100644 index 0000000..685ed5e --- /dev/null +++ b/src/wvr_pins.c @@ -0,0 +1,90 @@ +#include "wvr_pins.h" +#include "driver/touch_pad.h" + +touch_pad_t gpioNumToTPNum(int gpio) +{ + switch(gpio){ + case T0: + return TOUCH_PAD_NUM1; + case T1: + return TOUCH_PAD_NUM9; + case T2: + return TOUCH_PAD_NUM8; + case T3: + return TOUCH_PAD_NUM7; + // default: + // return -1; + } +} + +int gpioNumToPinNum(int gpio) +{ + switch(gpio){ + case D0: + return 0; + case D1: + return 1; + case D2: + return 2; + case D3: + return 3; + case D4: + return 4; + case D5: + return 5; + case D6: + return 6; + case D7: + return 7; + case D8: + return 8; + case D9: + return 9; + case D10: + return 10; + case D11: + return 11; + case D12: + return 12; + case D13: + return 13; + default: + return -1; + } +} + +gpio_num_t gpioNumToGpioNum_T(int gpio) +{ + switch(gpio){ + case D0: + return D0_GPIO; + case D1: + return D1_GPIO; + case D2: + return D2_GPIO; + case D3: + return D3_GPIO; + case D4: + return D4_GPIO; + case D5: + return D5_GPIO; + case D6: + return D6_GPIO; + case D7: + return D7_GPIO; + case D8: + return D8_GPIO; + case D9: + return D9_GPIO; + case D10: + return D10_GPIO; + case D11: + return D11_GPIO; + case D12: + return D12_GPIO; + case D13: + return D13_GPIO; + // default: + // return -1; + } +} diff --git a/src/wvr_pins.h b/src/wvr_pins.h index 8594ae1..ce76724 100644 --- a/src/wvr_pins.h +++ b/src/wvr_pins.h @@ -5,6 +5,9 @@ extern "C" { #endif +#include "driver/gpio.h" +#include "driver/touch_pad.h" + #define D0_GPIO GPIO_NUM_3 #define D1_GPIO GPIO_NUM_1 #define D2_GPIO GPIO_NUM_21 @@ -99,62 +102,9 @@ static const uint8_t wvr_pins[14] = { #define PAD13 D1 #define PAD14 D0 -// 34 -// 35 -// 36 -// 39 - -// int wvr_get_pin_name(int pin){ -// switch (pin) -// { -// case D0: -// return 0; -// break; -// case D1: -// return 1; -// break; -// case D2: -// return 2; -// break; -// case D3: -// return 3; -// break; -// case D4: -// return 4; -// break; -// case D5: -// return 5; -// break; -// case D6: -// return 6; -// break; -// case D7: -// return 7; -// break; -// case D8: -// return 8; -// break; -// case D9: -// return 9; -// break; -// case D10: -// return 10; -// break; -// case D11: -// return 11; -// break; -// case D12: -// return 12; -// break; -// case D13: -// return 13; -// break; -// default: -// return -1; -// break; -// } -// } -// D7,D8,D9,D10 (34,35,36,39) INPUT ONLY, No PULLUPS +int gpioNumToPinNum(int gpio); +touch_pad_t gpioNumToTPNum(int gpio); +gpio_num_t gpioNumToGpioNum_T(int gpio); #ifdef __cplusplus } diff --git a/src/wvr_ui.h b/src/wvr_ui.h index 5fe7538..1aa56c4 100644 --- a/src/wvr_ui.h +++ b/src/wvr_ui.h @@ -1,3 +1,3 @@ const char MAIN_page[] PROGMEM = R"=====( -Waver UI
+Waver UI
)====="; \ No newline at end of file