plugboard & 2004 lcd

This commit is contained in:
rzen 2020-09-23 21:05:03 -04:00
parent 6201fb1cfa
commit 7e2dcc4512

View File

@ -17,8 +17,8 @@ Adafruit_Keypad kbd = Adafruit_Keypad( makeKeymap(keys), rowPins, colPins, KBD_R
#include <LiquidCrystal.h> #include <LiquidCrystal.h>
LiquidCrystal lcd(19, 18, 17, 16, 15, 14); LiquidCrystal lcd(19, 18, 17, 16, 15, 14);
const int LCD_COLS = 16; const int LCD_COLS = 20;
const int LCD_ROWS = 2; const int LCD_ROWS = 4;
bool debug_mode = false; bool debug_mode = false;
@ -59,9 +59,10 @@ byte rotor_type [] = { 1, 2, 3 };
// reflector "UmkehrwalzeUmkehrwalze" // reflector "UmkehrwalzeUmkehrwalze"
byte reflector_type = 12; byte reflector_type = 12;
char plugboard [10][2] = { const int PLUGBOARD_SIZE = 10;
{'-','-'}, {'-','-'}, {'-','-'}, {'-','-'}, {'-','-'}, char plugboard [PLUGBOARD_SIZE][2] = {
{'-','-'}, {'-','-'}, {'-','-'}, {'-','-'}, {'-','-'} {'A','B'}, {'.','.'}, {'.','.'}, {'.','.'}, {'R','Z'},
{'C','D'}, {'.','.'}, {'.','.'}, {'.','.'}, {'G','H'}
}; };
// track rotor positions // track rotor positions
@ -187,8 +188,14 @@ char encode (char c) {
} }
} }
char plug_c = AZ[pin];
// plugboard // plugboard
// TODO for (int i=0; i<PLUGBOARD_SIZE; ++i) {
if (AZ[pin] == plugboard[i][0]) {
return plugboard[i][1];
}
}
return AZ[pin]; return AZ[pin];
} }
@ -230,7 +237,7 @@ void test () {
} }
const int BUF_SIZE = 6; const int BUF_SIZE = LCD_COLS - ROTOR_COUNT*3 - 1;
char input_buf [BUF_SIZE]; char input_buf [BUF_SIZE];
char encoded_buf [BUF_SIZE]; char encoded_buf [BUF_SIZE];
int buf_pos = 0; int buf_pos = 0;
@ -270,14 +277,38 @@ void disp_rotors () {
} }
} }
void disp_plugboard () {
if (LCD_ROWS > 2) {
for (int i=0; i<PLUGBOARD_SIZE/2; ++i) {
lcd.setCursor(i*3+(LCD_COLS-PLUGBOARD_SIZE/2*3+1),2);
lcd.print(plugboard[i][0]);
lcd.print(plugboard[i][1]);
if (i<PLUGBOARD_SIZE/2-1) {
lcd.print(' ');
}
lcd.setCursor(i*3+(LCD_COLS-PLUGBOARD_SIZE/2*3+1),3);
lcd.print(plugboard[i+PLUGBOARD_SIZE/2][0]);
lcd.print(plugboard[i+PLUGBOARD_SIZE/2][1]);
if (i<PLUGBOARD_SIZE/2-1) {
lcd.print(' ');
}
}
}
}
void setup () { void setup () {
// Serial.begin(115200);
kbd.begin(); kbd.begin();
lcd.begin(16, 2); lcd.begin(LCD_COLS, LCD_ROWS);
lcd.setCursor(0,1);
lcd.print("Enigma M3");
// test(); // test();
init_buf(input_buf); init_buf(input_buf);
init_buf(encoded_buf); init_buf(encoded_buf);
disp_rotors(); disp_rotors();
disp_plugboard();
} }