From 3d5014aaae259f20ad1df2bf9e7b09b1dc5ead8f Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Fri, 23 Oct 2020 08:58:11 +0200 Subject: [PATCH] Added Encoder with button instead od reset button. --- OSC2MIDI.ino | 110 ++++++++++++++++++++++++++++++++++++++++----------- OSC2Midi.cpp | 22 +++++++++++ OSC2Midi.h | 22 +++++++++++ 3 files changed, 131 insertions(+), 23 deletions(-) diff --git a/OSC2MIDI.ino b/OSC2MIDI.ino index b77ff75..1f45bc3 100644 --- a/OSC2MIDI.ino +++ b/OSC2MIDI.ino @@ -1,3 +1,25 @@ +/* + OSC2MIDI + + OSC2MIDI is a heavily extended port of https://github.com/tadas-s/OSC2Midi + + (c)2020 H. Wirtz + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + // Use from 0 to 4. Higher number, more debugging messages and memory usage. #define _WIFIMGR_LOGLEVEL_ 1 #define DEBUG 1 @@ -19,6 +41,7 @@ #include #include #include +#include #define MDNS_NAME "osc2midi" #define AP_SSID_NAME "OSC2MIDI" @@ -29,7 +52,6 @@ #define CFG_PORTAL_TIMEOUT 90 #define SOFT_SERIAL_RX 18 #define SOFT_SERIAL_TX 19 -#define AP_DATA_RESET_PIN 25 #define AP_MODE_PIN 26 #define LCD_I2C_ADDR 0x27 #define LCD_COL 16 @@ -44,6 +66,9 @@ #define FORMAT_SPIFFS_IF_FAILED true #define MIDI_SOLO_VOLUME 100 #define MIDI_IGNORE_VOLUME_CC 150 +#define ENC_BUTTON_PIN 32 +#define ENC_A_PIN 34 +#define ENC_B_PIN 35 void OSCToMidiCC(OSCMessage &msg, int offset); void OSCMixerMuteToMidiCC(OSCMessage &msg, int offset); @@ -79,25 +104,30 @@ bool write_state = false; uint32_t last_usage = millis(); bool broadcast_send = false; uint32_t midi_ignore_volume_cc = 0; +ESP32Encoder enc; MIDI_CREATE_INSTANCE(HardwareSerial, midi1, MIDI1); void setup() { + bool enc_but_pin_reset; + + pinMode(AP_MODE_PIN, INPUT_PULLDOWN); + ap_mode_state = digitalRead(AP_MODE_PIN); + pinMode(ENC_BUTTON_PIN, INPUT); + //ESP32Encoder::useInternalWeakPullResistors = UP; + enc.attachSingleEdge(ENC_A_PIN, ENC_B_PIN); + enc.setCount(0); + enc_but_pin_reset = digitalRead(ENC_BUTTON_PIN); + Serial.begin(115200); DEBUG_MSG("\n"); - //Serial.print("FORMAT SPIFFS..."); SPIFFS.format(); Serial.println("done."); while (1); - memset(midistate_cc, -1, 16 * 128); memset(midistate_mute, -1, 16); memset(midistate_solo, -1, 16); - pinMode(AP_DATA_RESET_PIN, INPUT_PULLDOWN); - pinMode(AP_MODE_PIN, INPUT_PULLDOWN); - ap_mode_state = digitalRead(AP_MODE_PIN); - Serial.setDebugOutput(true); Serial.println(F("OSC2MIDI (c)2020 H. Wirtz ")); @@ -111,6 +141,11 @@ void setup() lcd.print(F("(c)parasiTstudio")); delay(1000); + if (enc_but_pin_reset == LOW && digitalRead(ENC_BUTTON_PIN) == LOW) + { + reset_ap_data(); + } + WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP if (!SPIFFS.begin(FORMAT_SPIFFS_IF_FAILED)) @@ -211,6 +246,7 @@ void setup() sched.addJob(check_mode, KRATE_MODE); sched.addJob(check_reset_ap_data, KRATE_RESET_AP_DATA); sched.addJob(check_write_state, KRATE_CHECK_WRITE_STATE); + sched.addJob(enc_show, 1000); //sched.addJob(show_midi_state, KRATE_STATE); listDir(SPIFFS, "/", 1); @@ -1011,25 +1047,13 @@ void broadcast_midistate(void) void check_reset_ap_data(void) { - if (digitalRead(AP_DATA_RESET_PIN) == HIGH && last_reset_ap_check == true) + if (digitalRead(ENC_BUTTON_PIN) == LOW && last_reset_ap_check == true) { - DEBUG_MSG("Reset AP data\n"); - - WiFiManager wm; - - lcd.clear(); - lcd.setCursor(0, 0); - lcd.print("Firmware reset"); - wm.resetSettings(); - SPIFFS.format(); - lcd.setCursor(0, 1); - lcd.print("Done."); - delay(1000); - ESP.restart(); + reset_ap_data(); } - else if (digitalRead(AP_DATA_RESET_PIN) == HIGH) + else if (digitalRead(ENC_BUTTON_PIN) == LOW) { - if (digitalRead(AP_DATA_RESET_PIN) == HIGH) + if (digitalRead(ENC_BUTTON_PIN) == LOW) DEBUG_MSG("Reset AP data pressed\n"); last_reset_ap_check = true; } @@ -1061,6 +1085,46 @@ void ConfigAPStarted(WiFiManager * wm) DEBUG_MSG("Config-AP started\n"); } +void reset_ap_data(void) +{ + WiFiManager wm; + + DEBUG_MSG("Reset AP data\n"); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Reset AP data..."); + wm.resetSettings(); + lcd.setCursor(0, 1); + lcd.print("done."); + delay(500); + lcd.clear(); + ESP.restart(); +} + +void firmware_reset(void) +{ + WiFiManager wm; + + lcd.setCursor(0, 3); + lcd.print(F("Firmware reset...")); + DEBUG_MSG("Reset AP data\n"); + wm.resetSettings(); + DEBUG_MSG("FORMAT SPIFFS..."); + SPIFFS.format(); + DEBUG_MSG("done.\n"); + lcd.setCursor(0, 1); + lcd.print(F("done.")); + delay(500); + lcd.clear(); + ESP.restart(); +} + +void enc_show(void) +{ + DEBUG_MSG("Encoder count = %d", enc.getCount()); + DEBUG_MSG(" button[%d] = %d\n", ENC_BUTTON_PIN, (uint8_t)digitalRead(ENC_BUTTON_PIN)); +} + void listDir(fs::FS & fs, const char * dirname, uint8_t levels) { DEBUG_MSG("Listing directory : %s\n", dirname); diff --git a/OSC2Midi.cpp b/OSC2Midi.cpp index 167c74b..a9ed616 100644 --- a/OSC2Midi.cpp +++ b/OSC2Midi.cpp @@ -1,3 +1,25 @@ +/* + OSC2MIDI + + OSC2MIDI is a heavily extended port of https://github.com/tadas-s/OSC2Midi + + (c)2020 H. Wirtz + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + #include "OSC2Midi.h" #include #include diff --git a/OSC2Midi.h b/OSC2Midi.h index c6552cb..c7715b0 100644 --- a/OSC2Midi.h +++ b/OSC2Midi.h @@ -1,3 +1,25 @@ +/* + OSC2MIDI + + OSC2MIDI is a heavily extended port of https://github.com/tadas-s/OSC2Midi + + (c)2020 H. Wirtz + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + #ifndef OSC2MIDI_H #define OSC2MIDI_H