Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
Update the examples with the API break and use human readable variabl…
Browse files Browse the repository at this point in the history
…e types.
  • Loading branch information
MrHaroldA committed Feb 8, 2018
1 parent c315e9a commit bb2e8ee
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 62 deletions.
155 changes: 103 additions & 52 deletions examples/effect_state/effect_state.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@
MS3 MS3;

// These are addresses for the effect states.
const uint32_t P_FX1 = 0x60000030;
const uint32_t P_MOD1 = 0x60000430;
const uint32_t P_L1 = 0x60000020;
const uint32_t P_L2 = 0x60000021;
const uint32_t P_L3 = 0x60000022;
const uint32_t P_FX2 = 0x60000229;
const uint32_t P_MOD2 = 0x6000051E;
const uint32_t P_DLY = 0x60000610;
const uint32_t P_REV = 0x60000630;
const uint32_t P_NS = 0x60000656;
const uint32_t P_SOLO = 0x60000B02;
const uint32_t P_CTL1 = 0x60000B05;
const uint32_t P_CTL2 = 0x60000B06;
const unsigned long P_FX1 = 0x60000030;
const unsigned long P_MOD1 = 0x60000430;
const unsigned long P_L1 = 0x60000020;
const unsigned long P_L2 = 0x60000021;
const unsigned long P_L3 = 0x60000022;
const unsigned long P_FX2 = 0x60000229;
const unsigned long P_MOD2 = 0x6000051E;
const unsigned long P_DLY = 0x60000610;
const unsigned long P_REV = 0x60000630;
const unsigned long P_NS = 0x60000656;
const unsigned long P_SOLO = 0x60000B02;
const unsigned long P_CTL1 = 0x60000B05;
const unsigned long P_CTL2 = 0x60000B06;

// This is the address for the program change.
const uint32_t P_PATCH = 0x00010000;
const unsigned long P_PATCH = 0x00010000;

// We're going to check and report these effect blocks.
const uint32_t CHECK_THIS[] = {
const unsigned long CHECK_THIS[] = {
P_FX1,
P_MOD1,
P_L1,
Expand All @@ -47,24 +47,26 @@ const uint32_t CHECK_THIS[] = {
P_CTL1,
P_CTL2
};
const uint8_t CHECK_THIS_SIZE = sizeof(CHECK_THIS) / sizeof(CHECK_THIS[0]);
const byte CHECK_THIS_SIZE = sizeof(CHECK_THIS) / sizeof(CHECK_THIS[0]);

// Some global variables to store effect state and if something changed.
uint16_t states = 0;
uint16_t checked = 0;
uint16_t changed = 0;
uint32_t timerStart = 0;
unsigned int states = 0;
unsigned int checked = 0;
bool changed = false;
unsigned long timerStart = 0;

/**
* Incoming data handler.
*/
void parseData(uint32_t parameter, uint8_t *data) {
void parseData(unsigned long parameter, byte data) {
switch (parameter) {

// Refresh all effect states on patch changes.
case P_PATCH:
Serial.print(F("Loaded patch ")); Serial.print(data[0]); Serial.println(F("."));
for (uint8_t i = 0; i < CHECK_THIS_SIZE; i++) {
Serial.print(F("Loaded patch "));
Serial.print(data);
Serial.println(F("."));
for (byte i = 0; i < CHECK_THIS_SIZE; i++) {
MS3.read(CHECK_THIS[i], 0x01);
}
timerStart = millis();
Expand All @@ -73,9 +75,9 @@ void parseData(uint32_t parameter, uint8_t *data) {

// Store the effect state for printing later.
default:
for (uint8_t i = 0; i < CHECK_THIS_SIZE; i++) {
for (byte i = 0; i < CHECK_THIS_SIZE; i++) {
if (CHECK_THIS[i] == parameter) {
bitWrite(states, i, data[0]);
bitWrite(states, i, data);
bitSet(checked, i);
changed = true;
break;
Expand All @@ -87,49 +89,96 @@ void parseData(uint32_t parameter, uint8_t *data) {
/**
* Print all effect states.
*/
void printStatus(uint32_t duration) {
void printStatus(unsigned long duration) {

uint8_t dataReceived = 0;
for (uint8_t i = 0; i < CHECK_THIS_SIZE; i++) {
byte dataReceived = 0;
for (byte i = 0; i < CHECK_THIS_SIZE; i++) {
if (bitRead(checked, i)) {
dataReceived++;
}
}

Serial.println();
Serial.print(F("Received ")); Serial.print(dataReceived); Serial.print(F("/")); Serial.print(CHECK_THIS_SIZE);
Serial.print(F(" effect states in ")); Serial.print(duration); Serial.println(F("ms."));
Serial.print(F("Received "));
Serial.print(dataReceived);
Serial.print(F("/"));
Serial.print(CHECK_THIS_SIZE);
Serial.print(F(" effect states in "));
Serial.print(duration);
Serial.println(F("ms."));
Serial.println();

char state[8];
for (uint8_t i = 0; i < CHECK_THIS_SIZE; i++) {
for (byte i = 0; i < CHECK_THIS_SIZE; i++) {

// Did we receive this parameter?
if (!bitRead(checked, i)) {
strcpy(state, "UNKNOWN");
}
else {
} else {
strcpy(state, (bitRead(states, i) ? "ON" : "OFF"));
}

switch (CHECK_THIS[i]) {
case P_FX1: Serial.print(F("FX1: ")); Serial.println(state); break;
case P_MOD1: Serial.print(F("MOD1: ")); Serial.println(state); break;
case P_L1: Serial.print(F("L1: ")); Serial.println(state); break;
case P_L2: Serial.print(F("L2: ")); Serial.println(state); break;
case P_L3: Serial.print(F("L3: ")); Serial.println(state); break;
case P_FX2: Serial.print(F("FX2: ")); Serial.println(state); break;
case P_MOD2: Serial.print(F("MOD2: ")); Serial.println(state); break;
case P_DLY: Serial.print(F("DLY: ")); Serial.println(state); break;
case P_REV: Serial.print(F("REV: ")); Serial.println(state); break;
case P_NS: Serial.print(F("NS: ")); Serial.println(state); break;
case P_SOLO: Serial.print(F("SOLO: ")); Serial.println(state); break;
case P_CTL1: Serial.print(F("CTL1: ")); Serial.println(state); break;
case P_CTL2: Serial.print(F("CTL2: ")); Serial.println(state); break;

default: Serial.print(CHECK_THIS[i]); Serial.print(F(": ")); Serial.println(state);
case P_FX1:
Serial.print(F("FX1: "));
Serial.println(state);
break;
case P_MOD1:
Serial.print(F("MOD1: "));
Serial.println(state);
break;
case P_L1:
Serial.print(F("L1: "));
Serial.println(state);
break;
case P_L2:
Serial.print(F("L2: "));
Serial.println(state);
break;
case P_L3:
Serial.print(F("L3: "));
Serial.println(state);
break;
case P_FX2:
Serial.print(F("FX2: "));
Serial.println(state);
break;
case P_MOD2:
Serial.print(F("MOD2: "));
Serial.println(state);
break;
case P_DLY:
Serial.print(F("DLY: "));
Serial.println(state);
break;
case P_REV:
Serial.print(F("REV: "));
Serial.println(state);
break;
case P_NS:
Serial.print(F("NS: "));
Serial.println(state);
break;
case P_SOLO:
Serial.print(F("SOLO: "));
Serial.println(state);
break;
case P_CTL1:
Serial.print(F("CTL1: "));
Serial.println(state);
break;
case P_CTL2:
Serial.print(F("CTL2: "));
Serial.println(state);
break;

default:
Serial.print(CHECK_THIS[i]);
Serial.print(F(": "));
Serial.println(state);
}
}

Serial.println();
}

Expand All @@ -139,19 +188,20 @@ void printStatus(uint32_t duration) {
void setup() {
Serial.begin(115200);
while (!Serial) {}
Serial.println(F("Ready!")); Serial.println();
Serial.println(F("Ready!"));
Serial.println();
MS3.begin();
}

/**
* Main loop.
*/
void loop() {
static uint32_t timerStop = 0;
static unsigned long timerStop = 0;

// The MS-3 library stores the parameter and data in these variables.
uint32_t parameter = 0;
uint8_t data[1] = {};
unsigned long parameter = 0;
byte data = 0;

// Check for incoming data or send a queued item.
switch (MS3.update(parameter, data)) {
Expand All @@ -173,5 +223,6 @@ void loop() {
printStatus(millis() - timerStart);
changed = false;
}
break;
}
}
20 changes: 10 additions & 10 deletions examples/force_patch_1/force_patch_1.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@
MS3 MS3;

// This is the address for the program change.
const uint32_t P_PATCH = 0x00010000;
const unsigned long P_PATCH = 0x00010000;

/**
* Incoming data handler.
*/
void parseData(uint32_t parameter, uint8_t *data) {
void parseData(unsigned long parameter, byte data) {
switch (parameter) {
case P_PATCH:
Serial.print(F("Patch number received: "));
Serial.println(data[0]);
Serial.println(data);

// Slowly go back to patch 0.
if (data[0] > 0) {
if (data > 0) {
delay(750);
MS3.write(P_PATCH, data[0] - 1, 2);
}
else {
MS3.write(P_PATCH, data - 1, 2);
} else {
Serial.println(F("Back at zero!"));
}
break;
Expand All @@ -48,7 +47,8 @@ void parseData(uint32_t parameter, uint8_t *data) {
void setup() {
Serial.begin(115200);
while (!Serial) {}
Serial.println(F("Ready!")); Serial.println();
Serial.println(F("Ready!"));
Serial.println();
MS3.begin();
}

Expand All @@ -58,8 +58,8 @@ void setup() {
void loop() {

// Check for incoming data or send a queued item.
uint32_t parameter = 0;
uint8_t data[1] = {};
unsigned long parameter = 0;
byte data = 0;
switch (MS3.update(parameter, data)) {

// Fetch the current active patch on the MS-3.
Expand Down

0 comments on commit bb2e8ee

Please sign in to comment.