|
@ -10,7 +10,7 @@ |
|
|
|
|
|
|
|
|
#define MODES 6 |
|
|
#define MODES 6 |
|
|
|
|
|
|
|
|
#define VERSION " v0.2" |
|
|
#define VERSION "v0.2" |
|
|
|
|
|
|
|
|
#define pin_K1 8 |
|
|
#define pin_K1 8 |
|
|
#define pin_K2 7 |
|
|
#define pin_K2 7 |
|
@ -52,7 +52,7 @@ LiquidCrystal_I2C lcd(0x27, 20, 4); |
|
|
|
|
|
|
|
|
void setup() { |
|
|
void setup() { |
|
|
Serial.begin(9600); |
|
|
Serial.begin(9600); |
|
|
Serial.print(F("configuring pins..")); |
|
|
Serial.print(F("[S] 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); |
|
@ -62,21 +62,50 @@ void setup() { |
|
|
pinMode(pin_T, INPUT); |
|
|
pinMode(pin_T, INPUT); |
|
|
Serial.println("done"); |
|
|
Serial.println("done"); |
|
|
|
|
|
|
|
|
Serial.print(F("loading identifiers from EEPROM..")); |
|
|
Serial.print(F("[S] loading identifiers from EEPROM..")); |
|
|
EEPROM.get(0, names); |
|
|
EEPROM.get(0, names); |
|
|
Serial.println("done"); |
|
|
Serial.println("done"); |
|
|
|
|
|
|
|
|
Serial.print(F("initializing display..")); |
|
|
Serial.print(F("[S] initializing display..")); |
|
|
lcd.init(); |
|
|
lcd.init(); |
|
|
lcd.backlight(); |
|
|
lcd.backlight(); |
|
|
Serial.println("done"); |
|
|
Serial.println("done"); |
|
|
|
|
|
|
|
|
Serial.print(F("initializing relays with mode 123..")); |
|
|
Serial.print(F("[S] initializing relays with mode 123..")); |
|
|
setMode("123"); |
|
|
setMode("123"); |
|
|
|
|
|
setRelays(0); |
|
|
Serial.println("done"); |
|
|
Serial.println("done"); |
|
|
|
|
|
|
|
|
Serial.println("setup finished"); |
|
|
Serial.print(F("[S] showing bootsplash..")); |
|
|
Serial.println(); |
|
|
bootSplash(); |
|
|
|
|
|
Serial.println("done"); |
|
|
|
|
|
printMatrix(); |
|
|
|
|
|
|
|
|
|
|
|
Serial.println("[S] setup finished"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void bootSplash() { |
|
|
|
|
|
lcd.setCursor(8,0); |
|
|
|
|
|
lcd.print(F("stupid")); |
|
|
|
|
|
delay(350); |
|
|
|
|
|
lcd.setCursor(7,1); |
|
|
|
|
|
lcd.print(F("antenna")); |
|
|
|
|
|
delay(350); |
|
|
|
|
|
lcd.setCursor(8,2); |
|
|
|
|
|
lcd.print(F("matrix")); |
|
|
|
|
|
delay(350); |
|
|
|
|
|
lcd.setCursor(4,3); |
|
|
|
|
|
lcd.print(VERSION); |
|
|
|
|
|
lcd.print(F(" by DL3SD")); |
|
|
|
|
|
delay(3000); |
|
|
|
|
|
lcd.clear(); |
|
|
|
|
|
lcd.setCursor(8,0); |
|
|
|
|
|
lcd.print(F("see")); |
|
|
|
|
|
lcd.setCursor(0,1); |
|
|
|
|
|
lcd.print(F("github.com/denzs/sam")); |
|
|
|
|
|
lcd.setCursor(0,2); |
|
|
|
|
|
lcd.print(F("for more information")); |
|
|
|
|
|
delay(5000); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void storeName(char *dst, char *src) { |
|
|
void storeName(char *dst, char *src) { |
|
@ -88,30 +117,31 @@ void printMatrix() { |
|
|
char m[4], out[32]; |
|
|
char m[4], out[32]; |
|
|
int c; |
|
|
int c; |
|
|
|
|
|
|
|
|
// get current mode string like '312'
|
|
|
|
|
|
strcpy(m, matrix[mode].name); |
|
|
strcpy(m, matrix[mode].name); |
|
|
|
|
|
|
|
|
lcd.clear(); |
|
|
lcd.clear(); |
|
|
lcd.setCursor(0,0); |
|
|
lcd.setCursor(3,0); |
|
|
lcd.print(" S.A.M. by DL3SD"); |
|
|
lcd.print(F("S.A.M. by DL3SD")); |
|
|
for(int i=0; i < 3; i++) { |
|
|
for(int i=0; i < 3; i++) { |
|
|
c = m[i]-48; |
|
|
c = m[i]-48; |
|
|
lcd.setCursor(0, i+1); |
|
|
lcd.setCursor(0, i+1); |
|
|
lcd.print(names.trx[i]); |
|
|
lcd.print(names.trx[i]); |
|
|
|
|
|
lcd.setCursor(9, i+1); |
|
|
sprintf(out, "<- %s", names.ant[c-1]); |
|
|
sprintf(out, "<- %s", names.ant[c-1]); |
|
|
lcd.setCursor(8, i+1); |
|
|
|
|
|
lcd.print(out); |
|
|
lcd.print(out); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void setRelays() { |
|
|
void setRelays(bool display) { |
|
|
digitalWrite(pin_K1, matrix[mode].K1); |
|
|
digitalWrite(pin_K1, matrix[mode].K1); |
|
|
digitalWrite(pin_K2, matrix[mode].K2); |
|
|
digitalWrite(pin_K2, matrix[mode].K2); |
|
|
digitalWrite(pin_K3, matrix[mode].K3); |
|
|
digitalWrite(pin_K3, matrix[mode].K3); |
|
|
digitalWrite(pin_K4, matrix[mode].K4); |
|
|
digitalWrite(pin_K4, matrix[mode].K4); |
|
|
digitalWrite(pin_K5, matrix[mode].K5); |
|
|
digitalWrite(pin_K5, matrix[mode].K5); |
|
|
digitalWrite(pin_K6, matrix[mode].K6); |
|
|
digitalWrite(pin_K6, matrix[mode].K6); |
|
|
printMatrix(); |
|
|
if (display) { |
|
|
|
|
|
printMatrix(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void nextMode() { |
|
|
void nextMode() { |
|
@ -120,36 +150,30 @@ void nextMode() { |
|
|
} else { |
|
|
} else { |
|
|
mode++; |
|
|
mode++; |
|
|
} |
|
|
} |
|
|
Serial.print("next mode: "); |
|
|
Serial.print("[M] "); |
|
|
Serial.println(matrix[mode].name); |
|
|
Serial.println(matrix[mode].name); |
|
|
setRelays(); |
|
|
setRelays(1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void setMode(char *m) { |
|
|
void setMode(char *m) { |
|
|
char debug[32]; |
|
|
char debug[32]; |
|
|
m[3] = '\0'; |
|
|
m[3] = '\0'; |
|
|
for(int i=0 ; i < MODES; i++) { |
|
|
for(int i=0 ; i < MODES; i++) { |
|
|
//sprintf(debug, "comparing %s against %s", m, matrix[i].name);
|
|
|
//sprintf(debug, "[D] comparing %s against %s", m, matrix[i].name);
|
|
|
//Serial.println(debug);
|
|
|
//Serial.println(debug);
|
|
|
if(strcmp(matrix[i].name, m) == 0) { |
|
|
if(strcmp(matrix[i].name, m) == 0) { |
|
|
mode = i; |
|
|
mode = i; |
|
|
//sprintf(debug, "found mode %s at index %d", m, i);
|
|
|
//sprintf(debug, "found mode %s at index %d", m, i);
|
|
|
//Serial.println(debug);
|
|
|
//Serial.println(debug);
|
|
|
setRelays(); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
sprintf(debug, "ERROR: cant find mode %s", m); |
|
|
sprintf(debug, "[E] cant find mode %s", m); |
|
|
Serial.println(debug); |
|
|
Serial.println(debug); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void parseCommand() { |
|
|
void parseCommand(String s) { |
|
|
String s; |
|
|
|
|
|
|
|
|
|
|
|
s = Serial.readString(); |
|
|
|
|
|
|
|
|
|
|
|
switch (s[0]) { |
|
|
switch (s[0]) { |
|
|
case 'a': |
|
|
case 'a': |
|
|
switch (s[1]) { |
|
|
switch (s[1]) { |
|
@ -157,10 +181,11 @@ void parseCommand() { |
|
|
case '2': |
|
|
case '2': |
|
|
case '3': |
|
|
case '3': |
|
|
storeName(names.ant[(int)s[1] - 49], &s[2]); |
|
|
storeName(names.ant[(int)s[1] - 49], &s[2]); |
|
|
|
|
|
printMatrix(); |
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
Serial.println("unsupported option"); |
|
|
Serial.println("unsupported option"); |
|
|
Serial.println(); |
|
|
//Serial.println();
|
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
@ -170,74 +195,77 @@ void parseCommand() { |
|
|
case '2': |
|
|
case '2': |
|
|
case '3': |
|
|
case '3': |
|
|
storeName(names.trx[(int)s[1] - 49], &s[2]); |
|
|
storeName(names.trx[(int)s[1] - 49], &s[2]); |
|
|
|
|
|
printMatrix(); |
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
Serial.println("unsupported option"); |
|
|
Serial.println("unsupported option"); |
|
|
Serial.println(); |
|
|
//Serial.println();
|
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
case 'm': |
|
|
case 'm': |
|
|
if(s.length() == 5) { |
|
|
if(s.length() == 5) { |
|
|
setMode(&s[1]); |
|
|
setMode(&s[1]); |
|
|
} else { |
|
|
setRelays(1); |
|
|
Serial.print("getting mode:"); |
|
|
|
|
|
Serial.println(matrix[mode].name); |
|
|
|
|
|
Serial.println(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
Serial.print("[M] "); |
|
|
|
|
|
Serial.println(matrix[mode].name); |
|
|
|
|
|
//Serial.println();
|
|
|
break; |
|
|
break; |
|
|
case 'n': |
|
|
case 'n': |
|
|
nextMode(); |
|
|
nextMode(); |
|
|
break; |
|
|
break; |
|
|
case 'h': |
|
|
case 'h': |
|
|
Serial.println(F("following commands are available:")); |
|
|
Serial.print(F("[I] commands available in ")); |
|
|
Serial.println(F(" a1mygreatantenna1 - sets name of ANT1 to mygreatantenna1")); |
|
|
|
|
|
Serial.println(F(" a2mygreatantenna2 - sets name of ANT2 to mygreatantenna2")); |
|
|
|
|
|
Serial.println(F(" a3mygreatantenna3 - sets name of ANT3 to mygreatantenna3")); |
|
|
|
|
|
Serial.println(F(" t1mygreatrig1 - sets name of TRX1 to mygreatrig1")); |
|
|
|
|
|
Serial.println(F(" t2mygreatrig2 - sets name of TRX2 to mygreatrig2")); |
|
|
|
|
|
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(" 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")); |
|
|
|
|
|
Serial.print(F(" firmware version: ")); |
|
|
|
|
|
Serial.println(VERSION); |
|
|
Serial.println(VERSION); |
|
|
Serial.println(); |
|
|
Serial.println(F("[I] a1mygreatantenna1 - sets name of ANT1 to mygreatantenna1")); |
|
|
|
|
|
Serial.println(F("[I] a2mygreatantenna2 - sets name of ANT2 to mygreatantenna2")); |
|
|
|
|
|
Serial.println(F("[I] a3mygreatantenna3 - sets name of ANT3 to mygreatantenna3")); |
|
|
|
|
|
Serial.println(F("[I] t1mygreatrig1 - sets name of TRX1 to mygreatrig1")); |
|
|
|
|
|
Serial.println(F("[I] t2mygreatrig2 - sets name of TRX2 to mygreatrig2")); |
|
|
|
|
|
Serial.println(F("[I] t3mygreatrig3 - sets name of TRX3 to mygreatrig3")); |
|
|
|
|
|
Serial.println(F("[I] m312 - activate matrix 312 (I1->O3 I2->O1 I3->O2)")); |
|
|
|
|
|
Serial.println(F("[I] m - print current matrix")); |
|
|
|
|
|
Serial.println(F("[I] n - goto next matrix entry")); |
|
|
|
|
|
Serial.println(F("[I] r - print runtime settings")); |
|
|
|
|
|
Serial.println(F("[I] w - store runtime settings to EEPROM")); |
|
|
|
|
|
Serial.println(F("[I] h - print this help text")); |
|
|
|
|
|
//Serial.println();
|
|
|
break; |
|
|
break; |
|
|
case 'w': |
|
|
case 'w': |
|
|
EEPROM.put(0, names); |
|
|
EEPROM.put(0, names); |
|
|
Serial.println("runtime settings stored in EEPROM"); |
|
|
Serial.println(F("[S] runtime settings stored in EEPROM")); |
|
|
break; |
|
|
break; |
|
|
case 'r': |
|
|
case 'r': |
|
|
Serial.println(F("current runtime settings:")); |
|
|
Serial.println(F("[I] current runtime settings:")); |
|
|
Serial.print(F("ANT1: ")); |
|
|
Serial.print(F("[R] ANT1: ")); |
|
|
Serial.println(names.ant[0]); |
|
|
Serial.println(names.ant[0]); |
|
|
Serial.print(F("ANT2: ")); |
|
|
Serial.print(F("[R] ANT2: ")); |
|
|
Serial.println(names.ant[1]); |
|
|
Serial.println(names.ant[1]); |
|
|
Serial.print(F("ANT3: ")); |
|
|
Serial.print(F("[R] ANT3: ")); |
|
|
Serial.println(names.ant[2]); |
|
|
Serial.println(names.ant[2]); |
|
|
Serial.print(F("TRX1: ")); |
|
|
Serial.print(F("[R] TRX1: ")); |
|
|
Serial.println(names.trx[0]); |
|
|
Serial.println(names.trx[0]); |
|
|
Serial.print(F("TRX2: ")); |
|
|
Serial.print(F("[R] TRX2: ")); |
|
|
Serial.println(names.trx[1]); |
|
|
Serial.println(names.trx[1]); |
|
|
Serial.print(F("TRX3: ")); |
|
|
Serial.print(F("[R] TRX3: ")); |
|
|
Serial.println(names.trx[2]); |
|
|
Serial.println(names.trx[2]); |
|
|
Serial.println(F("-> dont forget to write to EEPROM with 'w'")); |
|
|
Serial.println(F("[I] -> dont forget to write to EEPROM with 'w' after modifying")); |
|
|
Serial.println(); |
|
|
//Serial.println();
|
|
|
break; |
|
|
break; |
|
|
default: |
|
|
default: |
|
|
Serial.println(F("command not found - enter 'h' for help")); |
|
|
Serial.println(F("[E] command not found - enter 'h' for help")); |
|
|
Serial.println(); |
|
|
//Serial.println();
|
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void loop() { |
|
|
void loop() { |
|
|
|
|
|
String s; |
|
|
|
|
|
|
|
|
if (Serial.available() > 0) { |
|
|
if (Serial.available() > 0) { |
|
|
parseCommand(); |
|
|
s = Serial.readString(); |
|
|
|
|
|
parseCommand(s); |
|
|
} |
|
|
} |
|
|
if(digitalRead(pin_T) == HIGH) { |
|
|
if(digitalRead(pin_T) == HIGH) { |
|
|
//Serial.println("button pressed..");
|
|
|
//Serial.println("button pressed..");
|
|
|