Skip to content

Commit

Permalink
add boards to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
marchingband committed Sep 2, 2021
1 parent e4366dc commit 0dc52d1
Show file tree
Hide file tree
Showing 19 changed files with 485 additions and 62 deletions.
119 changes: 119 additions & 0 deletions examples/wvr_dev_board/wvr_dev_board.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#include <wvr_pins.h>
#include <button_struct.h>
#include <ws_log.h>
#include <wvr_ui.h>
#include <WVR.h>
#include <midiXparser.h>
#include <midi_in.h>
#include <wav_player.h>
#include <button.h>
#include <rpc.h>
#include <file_system.h>
#include <wvr_0.3.h>
#include <gpio.h>
#include "rgb.h"
extern "C" {
#include "encoder.h"
#include "pot.h"
}

WVR wvr;

Button *switch_one;
Button *switch_two;

void onEncoderDevBoard(bool down)
{
// log a running number for the encoder
// static int cnt = 0;
// log_i("%d", down ? --cnt : ++cnt);

// change what voice is used for midi channel 1
uint8_t *channel_lut = get_channel_lut();
if(down)
{
// decrement but not below zero
channel_lut[0] -= (channel_lut[0] > 0);
}
else
{
// incriment but not above 15
channel_lut[0] += (channel_lut[0] < 15);
}
}

void onPotDevBoard(uint32_t raw_val)
{
// log a 7 bit number when the pot moves and set the volume
static uint8_t val = 0;
uint8_t temp = raw_val >> 5;
if(temp != val)
{
val = temp;
log_i("%d", val);
wvr.setGlobalVolume(val);
}
}

void switch_one_up(void)
{
log_i("switch one up");
wvr.unmute();
// rgb_set_color(100 /* red */,100 /* green */,100 /* blue */); // makes white
}

void switch_one_down(void)
{
log_i("switch one down");
wvr.mute();
// rgb_set_color(0 ,0 ,0); // turn off RGB LED
}

void switch_two_up(void)
{
log_i("switch two up");
wvr.wifiOn();
}

void switch_two_down(void)
{
log_i("switch two down");
wvr.wifiOff();
}

void setup() {
wvr.useFTDI = true;
wvr.useUsbMidi = false;
wvr.begin();

encoder_init(D9, D10);
pot_init();

// connect D13 to RGBLED pin on dev board, make sure pin D13 is set to edge:none in WEB GUI
// rgb_init(D13);

gpio_reset_pin(gpioNumToGpioNum_T(D3));
gpio_reset_pin(gpioNumToGpioNum_T(D4));

pinMode(D3, INPUT_PULLUP);
pinMode(D4, INPUT_PULLUP);

switch_one = new Button(D3, FALLING, 60);
switch_two = new Button(D4, FALLING, 60);

switch_one->onPress(switch_one_up);
switch_one->onRelease(switch_one_down);
switch_two->onPress(switch_two_up);
switch_two->onRelease(switch_two_down);

wvr.wifiIsOn = get_metadata()->wifi_starts_on;
log_i("wifi is %s", wvr.wifiIsOn ? "on" : "off");

onEncoder = onEncoderDevBoard;
onPot = onPotDevBoard;
}

void loop() {
// vTaskDelay(portMAX_DELAY);
vTaskDelete(NULL);
}
124 changes: 124 additions & 0 deletions examples/wvr_dev_board_usb/wvr_dev_board_usb.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#include <wvr_pins.h>
#include <button_struct.h>
#include <ws_log.h>
#include <wvr_ui.h>
#include <WVR.h>
#include <midiXparser.h>
#include <midi_in.h>
#include <wav_player.h>
#include <button.h>
#include <rpc.h>
#include <file_system.h>
#include <wvr_0.3.h>
#include <gpio.h>
#include "rgb.h"
extern "C" {
#include "encoder.h"
#include "pot.h"
}

WVR wvr;

Button *switch_one;
Button *switch_two;

void onEncoderDevBoard(bool down)
{
// log a running number for the encoder
// static int cnt = 0;
// log_i("%d", down ? --cnt : ++cnt);

// change what voice is used for midi channel 1
uint8_t *channel_lut = get_channel_lut();
if(down)
{
// decrement but not below zero
channel_lut[0] -= (channel_lut[0] > 0);
}
else
{
// incriment but not above 15
channel_lut[0] += (channel_lut[0] < 15);
}
}

void onPotDevBoard(uint32_t raw_val)
{
// log a 7 bit number when the pot moves and set the volume
static uint8_t val = 0;
uint8_t temp = raw_val >> 5;
if(temp != val)
{
val = temp;
// log_i("%d", val);
wvr.setGlobalVolume(val);
}
}

void switch_one_up(void)
{
log_i("switch one up");
wvr.unmute();
// rgb_set_color(100 /* red */,100 /* green */,100 /* blue */); // makes white
}

void switch_one_down(void)
{
log_i("switch one down");
wvr.mute();
// rgb_set_color(0 ,0 ,0); // turn off RGB LED
}

void switch_two_up(void)
{
log_i("switch two up");
wvr.wifiOn();
}

void switch_two_down(void)
{
log_i("switch two down");
wvr.wifiOff();
}

void setup() {
wvr.useFTDI = true;
wvr.useUsbMidi = true;
wvr.begin();

// connect D13 to RGBLED pin on dev board, make sure pin D13 is set to edge:none in WEB GUI
// rgb_init(D13);

gpio_reset_pin(gpioNumToGpioNum_T(D9));
gpio_reset_pin(gpioNumToGpioNum_T(D10));

encoder_init(D9, D10);
log_i("dev board");
pot_init();


gpio_reset_pin(gpioNumToGpioNum_T(D3));
gpio_reset_pin(gpioNumToGpioNum_T(D4));

pinMode(D3, INPUT_PULLUP);
pinMode(D4, INPUT_PULLUP);

switch_one = new Button(D3, FALLING, 60);
switch_two = new Button(D4, FALLING, 60);

switch_one->onPress(switch_one_up);
switch_one->onRelease(switch_one_down);
switch_two->onPress(switch_two_up);
switch_two->onRelease(switch_two_down);

wvr.wifiIsOn = get_metadata()->wifi_starts_on;
log_i("wifi is %s", wvr.wifiIsOn ? "on" : "off");

onEncoder = onEncoderDevBoard;
onPot = onPotDevBoard;
}

void loop() {
// vTaskDelay(portMAX_DELAY);
vTaskDelete(NULL);
}
28 changes: 28 additions & 0 deletions examples/wvr_makers_board/wvr_makers_board.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <wvr_pins.h>
#include <button_struct.h>
#include <ws_log.h>
#include <wvr_ui.h>
#include <WVR.h>
#include <midiXparser.h>
#include <midi_in.h>
#include <wav_player.h>
#include <button.h>
#include <rpc.h>
#include <file_system.h>
#include <wvr_0.3.h>
#include <gpio.h>

WVR wvr;

void setup() {
wvr.useFTDI = false;
wvr.useUsbMidi = false;
wvr.begin();
wvr.wifiIsOn = get_metadata()->wifi_starts_on;
log_i("wifi is %s", wvr.wifiIsOn ? "on" : "off");
}

void loop() {
// vTaskDelay(portMAX_DELAY);
vTaskDelete(NULL);
}
28 changes: 28 additions & 0 deletions examples/wvr_makers_board_usb/wvr_makers_board_usb.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <wvr_pins.h>
#include <button_struct.h>
#include <ws_log.h>
#include <wvr_ui.h>
#include <WVR.h>
#include <midiXparser.h>
#include <midi_in.h>
#include <wav_player.h>
#include <button.h>
#include <rpc.h>
#include <file_system.h>
#include <wvr_0.3.h>
#include <gpio.h>

WVR wvr;

void setup() {
wvr.useFTDI = false;
wvr.useUsbMidi = true;
wvr.begin();
wvr.wifiIsOn = get_metadata()->wifi_starts_on;
log_i("wifi is %s", wvr.wifiIsOn ? "on" : "off");
}

void loop() {
// vTaskDelay(portMAX_DELAY);
vTaskDelete(NULL);
}
17 changes: 17 additions & 0 deletions src/WVR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
#include "wvr_0.3.h"
#include "wav_player.h"
#include "server.h"
#include "file_system.h"

WVR::WVR()
{
this->wifiIsOn = get_wifi_is_on();
this->useFTDI = false;
this->useUsbMidi = false;
this->forceWifiOn = false;
}

void WVR::begin()
Expand Down Expand Up @@ -43,4 +45,19 @@ void WVR::toggleWifi()
this->wifiIsOn ? wifiOff() : wifiOn();
// wifiIsOn = !wifiIsOn;
this->wifiIsOn = get_wifi_is_on();
}

void WVR::setGlobalVolume(uint8_t volume)
{
set_global_volume(volume);
}

void WVR::mute(void)
{
set_mute(true);
}

void WVR::unmute(void)
{
set_mute(false);
}
4 changes: 4 additions & 0 deletions src/WVR.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ class WVR {
void wifiOff(void);
void wifiOn(void);
void toggleWifi(void);
void setGlobalVolume(uint8_t volume);
void mute(void);
void unmute(void);
// int globalVolume;
// bool mute;
// bool autoConfigPins;
bool wifiIsOn;
bool useFTDI;
bool useUsbMidi;
bool forceWifiOn;
};

#endif
8 changes: 5 additions & 3 deletions src/button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ static void gpioTask(void* x) {
};
}

void IRAM_ATTR isr(void *e){
// void IRAM_ATTR isr(void *e){
void isr(void *e){
button_event_t *event = (button_event_t*)e;
event->val = digitalRead(event->pin);
isr_log_d("read %d",event->val);
xQueueSendFromISR(gpio_queue_handle, &event, NULL);
}

void IRAM_ATTR touch_isr(void *e){
// void IRAM_ATTR touch_isr(void *e){
void touch_isr(void *e){
button_event_t *event = (button_event_t*)e;
uint32_t pad_intr = touch_pad_get_status();
touch_pad_clear_status();
Expand Down Expand Up @@ -96,7 +98,7 @@ void Button::onPress(void(*handlePress)()){
if(this->touch != 1)
{
// digital read mode
attachInterruptArg(pin, isr, (void*)&event, CHANGE);
attachInterruptArg((uint8_t)pin, isr, (void*)&event, CHANGE);
}
else
{
Expand Down
Loading

0 comments on commit 0dc52d1

Please sign in to comment.