|
|
|
#include <EEPROM.h>
|
|
|
|
|
|
|
|
#define MODES 6
|
|
|
|
|
|
|
|
#define pin_K1 8
|
|
|
|
#define pin_K2 7
|
|
|
|
#define pin_K3 6
|
|
|
|
#define pin_K4 5
|
|
|
|
#define pin_K5 4
|
|
|
|
#define pin_K6 3
|
|
|
|
#define pin_T 12
|
|
|
|
|
|
|
|
struct state {
|
|
|
|
char name[4];
|
|
|
|
bool K1;
|
|
|
|
bool K2;
|
|
|
|
bool K3;
|
|
|
|
bool K4;
|
|
|
|
bool K5;
|
|
|
|
bool K6;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct identifier {
|
|
|
|
char in1[16];
|
|
|
|
char in2[16];
|
|
|
|
char in3[16];
|
|
|
|
char out1[16];
|
|
|
|
char out2[16];
|
|
|
|
char out3[16];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct identifier names;
|
|
|
|
|
|
|
|
const struct state matrix[] = {
|
|
|
|
{"123", 0, 0, 0, 0, 0, 0}, // IN1->OUT1 IN2->OUT2 IN3->OUT3
|
|
|
|
{"213", 1, 0, 1, 0, 0, 0}, // IN1->OUT2 IN2->OUT1 IN3->OUT3
|
|
|
|
{"312", 1 ,1, 1, 0, 1, 0}, // IN1->OUT3 IN2->OUT1 IN3->OUT2
|
|
|
|
{"132", 0 ,0, 1, 1, 1, 0}, // IN1->OUT1 IN2->OUT3 IN3->OUT2
|
|
|
|
{"231", 1 ,0 ,1, 1, 1, 1}, // IN1->OUT2 IN2->OUT3 IN3->OUT1
|
|
|
|
{"321", 1 ,1 ,0, 0, 1, 1}, // IN1->OUT3 IN2->OUT2 IN3->OUT1
|
|
|
|
};
|
|
|
|
|
|
|
|
int mode;
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
pinMode(pin_K1, OUTPUT);
|
|
|
|
pinMode(pin_K2, OUTPUT);
|
|
|
|
pinMode(pin_K3, OUTPUT);
|
|
|
|
pinMode(pin_K4, OUTPUT);
|
|
|
|
pinMode(pin_K5, OUTPUT);
|
|
|
|
pinMode(pin_K6, OUTPUT);
|
|
|
|
pinMode(pin_T, INPUT);
|
|
|
|
|
|
|
|
EEPROM.get(0, names);
|
|
|
|
|
|
|
|
Serial.begin(9600);
|
|
|
|
}
|
|
|
|
|
|
|
|
void storeName(char *s, char *name, char *identifier) {
|
|
|
|
strncpy(s, name, strlen(name));
|
|
|
|
s[strlen(name) - 1] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
void nextMode() {
|
|
|
|
if(mode == MODES - 1) {
|
|
|
|
mode = 0;
|
|
|
|
} else {
|
|
|
|
mode++;
|
|
|
|
}
|
|
|
|
Serial.print("next mode: ");
|
|
|
|
Serial.println(matrix[mode].name);
|
|
|
|
digitalWrite(pin_K1, matrix[mode].K1);
|
|
|
|
digitalWrite(pin_K2, matrix[mode].K2);
|
|
|
|
digitalWrite(pin_K3, matrix[mode].K3);
|
|
|
|
digitalWrite(pin_K4, matrix[mode].K4);
|
|
|
|
digitalWrite(pin_K5, matrix[mode].K5);
|
|
|
|
digitalWrite(pin_K6, matrix[mode].K6);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMode(char *m) {
|
|
|
|
Serial.print("m: ");
|
|
|
|
Serial.println(m);
|
|
|
|
m[3] = '\0';
|
|
|
|
for(int i=0 ; i < MODES; i++) {
|
|
|
|
Serial.print("comparing ");
|
|
|
|
Serial.print(m);
|
|
|
|
Serial.print(" against ");
|
|
|
|
Serial.println(matrix[i].name);
|
|
|
|
if(strcmp(matrix[i].name, m) == 0) {
|
|
|
|
mode = i;
|
|
|
|
Serial.print("found mode at index ");
|
|
|
|
Serial.println(i);
|
|
|
|
digitalWrite(pin_K1, matrix[mode].K1);
|
|
|
|
digitalWrite(pin_K2, matrix[mode].K2);
|
|
|
|
digitalWrite(pin_K3, matrix[mode].K3);
|
|
|
|
digitalWrite(pin_K4, matrix[mode].K4);
|
|
|
|
digitalWrite(pin_K5, matrix[mode].K5);
|
|
|
|
digitalWrite(pin_K6, matrix[mode].K6);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void parseCommand() {
|
|
|
|
String s;
|
|
|
|
|
|
|
|
s = Serial.readString();
|
|
|
|
Serial.print("got: ");
|
|
|
|
Serial.println(s);
|
|
|
|
|
|
|
|
switch (s[0]) {
|
|
|
|
case 'i':
|
|
|
|
switch (s[1]) {
|
|
|
|
case '1':
|
|
|
|
storeName(names.in1, &s[1], "IN1");
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
storeName(names.in2, &s[1], "IN2");
|
|
|
|
break;
|
|
|
|
case '3':
|
|
|
|
storeName(names.in3, &s[1], "IN3");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Serial.println("unsupported option");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
switch (s[1]) {
|
|
|
|
case '1':
|
|
|
|
storeName(names.out1, &s[1], "OUT1");
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
storeName(names.out2, &s[1], "OUT2");
|
|
|
|
break;
|
|
|
|
case '3':
|
|
|
|
storeName(names.out3, &s[1], "OUT3");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Serial.println("unsupported option");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
if(s.length() == 5) {
|
|
|
|
setMode(&s[1]);
|
|
|
|
} else {
|
|
|
|
Serial.print("getting mode:");
|
|
|
|
Serial.println(matrix[mode].name);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
nextMode();
|
|
|
|
break;
|
|
|
|
case '1':
|
|
|
|
case '2':
|
|
|
|
case '3':
|
|
|
|
Serial.println("yeah you propably entered another mode ;)");
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
Serial.println(F("following commands are available:"));
|
|
|
|
Serial.println(F(" i1mygreatantenna - sets name of IN1 to mygreatantenna"));
|
|
|
|
Serial.println(F(" i2mygreatantenna - sets name of IN2 to mygreatantenna"));
|
|
|
|
Serial.println(F(" i3mygreatantenna - sets name of IN3 to mygreatantenna"));
|
|
|
|
Serial.println(F(" o1mygreatrig - sets name of OUT1 to mygreatrig"));
|
|
|
|
Serial.println(F(" o2mygreatrig - sets name of OUT2 to mygreatrig"));
|
|
|
|
Serial.println(F(" o3mygreatrig - sets name of OUT3 to mygreatrig"));
|
|
|
|
Serial.println(F(" m312 - activate matrix 312 (I1->O3 I2->O1 I3->O2)"));
|
|
|
|
Serial.println(F(" m - print current matrix"));
|
|
|
|
Serial.println(F(" n - goto next matrix entry"));
|
|
|
|
Serial.println(F(" r - print runtime settings"));
|
|
|
|
Serial.println(F(" w - store runtime settings to EEPROM"));
|
|
|
|
Serial.println(F(" h - print this help text"));
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
EEPROM.put(0, names);
|
|
|
|
Serial.println("runtime settings stored in EEPROM");
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
Serial.println(F("current runtime settings:"));
|
|
|
|
Serial.print(F("IN1: "));
|
|
|
|
Serial.println(names.in1);
|
|
|
|
Serial.print(F("IN2: "));
|
|
|
|
Serial.println(names.in2);
|
|
|
|
Serial.print(F("IN3: "));
|
|
|
|
Serial.println(names.in3);
|
|
|
|
Serial.print(F("OUT1: "));
|
|
|
|
Serial.println(names.out1);
|
|
|
|
Serial.print(F("OUT2: "));
|
|
|
|
Serial.println(names.out2);
|
|
|
|
Serial.print(F("OUT3: "));
|
|
|
|
Serial.println(names.out3);
|
|
|
|
Serial.println(F("REMEMBER to write to EEPROM with 'w'"));
|
|
|
|
Serial.println();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Serial.println(F("command not found - enter 'h' for help"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
if (Serial.available() > 0) {
|
|
|
|
parseCommand();
|
|
|
|
}
|
|
|
|
if(digitalRead(pin_T) == HIGH) {
|
|
|
|
Serial.println("button pressed... going to next matrix position");
|
|
|
|
nextMode();
|
|
|
|
}
|
|
|
|
delay(500);
|
|
|
|
}
|