Browse Source

extend firwmare with lcd etc..

master
Sebastian Denz 4 years ago
parent
commit
096ade67d8
  1. 188
      firmware/firmware.ino

188
firmware/firmware.ino

@ -1,7 +1,17 @@
/* stupid atenna matrix firmware - by DL3SD
* FIXME:
* - replace delay in loop by interrupt handling
* - maybe implement sleep mode to avoid hf issues by arduino clock
*/
#include <EEPROM.h> #include <EEPROM.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define MODES 6 #define MODES 6
#define VERSION " v0.2"
#define pin_K1 8 #define pin_K1 8
#define pin_K2 7 #define pin_K2 7
#define pin_K3 6 #define pin_K3 6
@ -21,28 +31,28 @@ struct state {
}; };
struct identifier { struct identifier {
char in1[16]; char ant[3][16];
char in2[16]; char trx[3][16];
char in3[16];
char out1[16];
char out2[16];
char out3[16];
}; };
struct identifier names; struct identifier names;
const struct state matrix[] = { const struct state matrix[] = {
{"123", 0, 0, 0, 0, 0, 0}, // IN1->OUT1 IN2->OUT2 IN3->OUT3 {"123", 0, 0, 0, 0, 0, 0}, // ANT1->TRX1 ANT2->TRX2 ANT3->TRX3
{"213", 1, 0, 1, 0, 0, 0}, // IN1->OUT2 IN2->OUT1 IN3->OUT3 {"213", 1, 0, 1, 0, 0, 0}, // ANT1->TRX2 ANT2->TRX1 ANT3->TRX3
{"312", 1 ,1, 1, 0, 1, 0}, // IN1->OUT3 IN2->OUT1 IN3->OUT2 {"312", 1 ,1, 1, 0, 1, 0}, // ANT1->TRX3 ANT2->TRX1 ANT3->TRX2
{"132", 0 ,0, 1, 1, 1, 0}, // IN1->OUT1 IN2->OUT3 IN3->OUT2 {"132", 0 ,0, 1, 1, 1, 0}, // ANT1->TRX1 ANT2->TRX3 ANT3->TRX2
{"231", 1 ,0 ,1, 1, 1, 1}, // IN1->OUT2 IN2->OUT3 IN3->OUT1 {"231", 1 ,0 ,1, 1, 1, 1}, // ANT1->TRX2 ANT2->TRX3 ANT3->TRX1
{"321", 1 ,1 ,0, 0, 1, 1}, // IN1->OUT3 IN2->OUT2 IN3->OUT1 {"321", 1 ,1 ,0, 0, 1, 1}, // ANT1->TRX3 ANT2->TRX2 ANT3->TRX1
}; };
int mode; int mode;
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() { void setup() {
Serial.begin(9600);
Serial.print(F("configuring pins.."));
pinMode(pin_K1, OUTPUT); pinMode(pin_K1, OUTPUT);
pinMode(pin_K2, OUTPUT); pinMode(pin_K2, OUTPUT);
pinMode(pin_K3, OUTPUT); pinMode(pin_K3, OUTPUT);
@ -50,15 +60,58 @@ void setup() {
pinMode(pin_K5, OUTPUT); pinMode(pin_K5, OUTPUT);
pinMode(pin_K6, OUTPUT); pinMode(pin_K6, OUTPUT);
pinMode(pin_T, INPUT); pinMode(pin_T, INPUT);
Serial.println("done");
Serial.print(F("loading identifiers from EEPROM.."));
EEPROM.get(0, names); EEPROM.get(0, names);
Serial.println("done");
Serial.begin(9600); Serial.print(F("initializing display.."));
lcd.init();
lcd.backlight();
Serial.println("done");
Serial.print(F("initializing relays with mode 123.."));
setMode("123");
Serial.println("done");
Serial.println("setup finished");
Serial.println();
}
void storeName(char *dst, char *src) {
strncpy(dst, src, strlen(src));
dst[strlen(src) - 1] = '\0';
} }
void storeName(char *s, char *name, char *identifier) { void printMatrix() {
strncpy(s, name, strlen(name)); char m[4], out[32];
s[strlen(name) - 1] = '\0'; int c;
// get current mode string like '312'
strcpy(m, matrix[mode].name);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" S.A.M. by DL3SD");
for(int i=0; i < 3; i++) {
c = m[i]-48;
lcd.setCursor(0, i+1);
lcd.print(names.trx[i]);
sprintf(out, "<- %s", names.ant[c-1]);
lcd.setCursor(8, i+1);
lcd.print(out);
}
}
void setRelays() {
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);
printMatrix();
} }
void nextMode() { void nextMode() {
@ -69,75 +122,58 @@ void nextMode() {
} }
Serial.print("next mode: "); Serial.print("next mode: ");
Serial.println(matrix[mode].name); Serial.println(matrix[mode].name);
digitalWrite(pin_K1, matrix[mode].K1); setRelays();
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) { void setMode(char *m) {
Serial.print("m: "); char debug[32];
Serial.println(m);
m[3] = '\0'; m[3] = '\0';
for(int i=0 ; i < MODES; i++) { for(int i=0 ; i < MODES; i++) {
Serial.print("comparing "); //sprintf(debug, "comparing %s against %s", m, matrix[i].name);
Serial.print(m); //Serial.println(debug);
Serial.print(" against ");
Serial.println(matrix[i].name);
if(strcmp(matrix[i].name, m) == 0) { if(strcmp(matrix[i].name, m) == 0) {
mode = i; mode = i;
Serial.print("found mode at index "); //sprintf(debug, "found mode %s at index %d", m, i);
Serial.println(i); //Serial.println(debug);
digitalWrite(pin_K1, matrix[mode].K1); setRelays();
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; return;
} }
} }
sprintf(debug, "ERROR: cant find mode %s", m);
Serial.println(debug);
return;
} }
void parseCommand() { void parseCommand() {
String s; String s;
s = Serial.readString(); s = Serial.readString();
Serial.print("got: ");
Serial.println(s);
switch (s[0]) { switch (s[0]) {
case 'i': case 'a':
switch (s[1]) { switch (s[1]) {
case '1': case '1':
storeName(names.in1, &s[1], "IN1");
break;
case '2': case '2':
storeName(names.in2, &s[1], "IN2");
break;
case '3': case '3':
storeName(names.in3, &s[1], "IN3"); storeName(names.ant[(int)s[1] - 49], &s[2]);
break; break;
default: default:
Serial.println("unsupported option"); Serial.println("unsupported option");
Serial.println();
break; break;
} }
break; break;
case 'o': case 't':
switch (s[1]) { switch (s[1]) {
case '1': case '1':
storeName(names.out1, &s[1], "OUT1");
break;
case '2': case '2':
storeName(names.out2, &s[1], "OUT2");
break;
case '3': case '3':
storeName(names.out3, &s[1], "OUT3"); storeName(names.trx[(int)s[1] - 49], &s[2]);
break; break;
default: default:
Serial.println("unsupported option"); Serial.println("unsupported option");
Serial.println();
break; break;
} }
break; break;
@ -147,30 +183,29 @@ void parseCommand() {
} else { } else {
Serial.print("getting mode:"); Serial.print("getting mode:");
Serial.println(matrix[mode].name); Serial.println(matrix[mode].name);
Serial.println();
} }
break; break;
case 'n': case 'n':
nextMode(); nextMode();
break; break;
case '1':
case '2':
case '3':
Serial.println("yeah you propably entered another mode ;)");
break;
case 'h': case 'h':
Serial.println(F("following commands are available:")); Serial.println(F("following commands are available:"));
Serial.println(F(" i1mygreatantenna - sets name of IN1 to mygreatantenna")); Serial.println(F(" a1mygreatantenna1 - sets name of ANT1 to mygreatantenna1"));
Serial.println(F(" i2mygreatantenna - sets name of IN2 to mygreatantenna")); Serial.println(F(" a2mygreatantenna2 - sets name of ANT2 to mygreatantenna2"));
Serial.println(F(" i3mygreatantenna - sets name of IN3 to mygreatantenna")); Serial.println(F(" a3mygreatantenna3 - sets name of ANT3 to mygreatantenna3"));
Serial.println(F(" o1mygreatrig - sets name of OUT1 to mygreatrig")); Serial.println(F(" t1mygreatrig1 - sets name of TRX1 to mygreatrig1"));
Serial.println(F(" o2mygreatrig - sets name of OUT2 to mygreatrig")); Serial.println(F(" t2mygreatrig2 - sets name of TRX2 to mygreatrig2"));
Serial.println(F(" o3mygreatrig - sets name of OUT3 to mygreatrig")); Serial.println(F(" t3mygreatrig3 - sets name of TRX3 to mygreatrig3"));
Serial.println(F(" m312 - activate matrix 312 (I1->O3 I2->O1 I3->O2)")); Serial.println(F(" m312 - activate matrix 312 (I1->O3 I2->O1 I3->O2)"));
Serial.println(F(" m - print current matrix")); Serial.println(F(" m - print current matrix"));
Serial.println(F(" n - goto next matrix entry")); Serial.println(F(" n - goto next matrix entry"));
Serial.println(F(" r - print runtime settings")); Serial.println(F(" r - print runtime settings"));
Serial.println(F(" w - store runtime settings to EEPROM")); Serial.println(F(" w - store runtime settings to EEPROM"));
Serial.println(F(" h - print this help text")); Serial.println(F(" h - print this help text"));
Serial.print(F(" firmware version: "));
Serial.println(VERSION);
Serial.println();
break; break;
case 'w': case 'w':
EEPROM.put(0, names); EEPROM.put(0, names);
@ -178,23 +213,24 @@ void parseCommand() {
break; break;
case 'r': case 'r':
Serial.println(F("current runtime settings:")); Serial.println(F("current runtime settings:"));
Serial.print(F("IN1: ")); Serial.print(F("ANT1: "));
Serial.println(names.in1); Serial.println(names.ant[0]);
Serial.print(F("IN2: ")); Serial.print(F("ANT2: "));
Serial.println(names.in2); Serial.println(names.ant[1]);
Serial.print(F("IN3: ")); Serial.print(F("ANT3: "));
Serial.println(names.in3); Serial.println(names.ant[2]);
Serial.print(F("OUT1: ")); Serial.print(F("TRX1: "));
Serial.println(names.out1); Serial.println(names.trx[0]);
Serial.print(F("OUT2: ")); Serial.print(F("TRX2: "));
Serial.println(names.out2); Serial.println(names.trx[1]);
Serial.print(F("OUT3: ")); Serial.print(F("TRX3: "));
Serial.println(names.out3); Serial.println(names.trx[2]);
Serial.println(F("REMEMBER to write to EEPROM with 'w'")); Serial.println(F("-> dont forget to write to EEPROM with 'w'"));
Serial.println(); Serial.println();
break; break;
default: default:
Serial.println(F("command not found - enter 'h' for help")); Serial.println(F("command not found - enter 'h' for help"));
Serial.println();
break; break;
} }
} }
@ -204,8 +240,8 @@ void loop() {
parseCommand(); parseCommand();
} }
if(digitalRead(pin_T) == HIGH) { if(digitalRead(pin_T) == HIGH) {
Serial.println("button pressed... going to next matrix position"); //Serial.println("button pressed..");
nextMode(); nextMode();
} }
delay(500); delay(300);
} }

Loading…
Cancel
Save