|
|
|
@ -18,9 +18,9 @@ HCuOLED HCuOLED(SH1106, CS_DI, DC_DI, RST_DI);
|
|
|
|
|
LiquidCrystal_I2C lcd(0x27, 16, 2);
|
|
|
|
|
String lcd_output;
|
|
|
|
|
|
|
|
|
|
size_t toKeyIndex(const String& input_hex)
|
|
|
|
|
uint16_t toKeyIndex(const String& input_hex)
|
|
|
|
|
{
|
|
|
|
|
size_t index = -1;
|
|
|
|
|
uint16_t index = -1;
|
|
|
|
|
for (size_t i = 0; i < ALPHABET_SIZE; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (key_values[i].hex == input_hex)
|
|
|
|
@ -33,14 +33,67 @@ size_t toKeyIndex(const String& input_hex)
|
|
|
|
|
return index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t forward(size_t index, size_t current_wheel)
|
|
|
|
|
{
|
|
|
|
|
size_t input = (index + key_shifts[current_wheel]) % ALPHABET_SIZE;
|
|
|
|
|
|
|
|
|
|
size_t output = 0;
|
|
|
|
|
for (size_t i = 0; i < ALPHABET_SIZE; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (mutations[current_wheel][i].from == input)
|
|
|
|
|
{
|
|
|
|
|
output = mutations[current_wheel][i].to;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t backward(size_t index, size_t current_wheel)
|
|
|
|
|
{
|
|
|
|
|
int output = 0;
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < ALPHABET_SIZE; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (input == mutations[current_wheel][i].to)
|
|
|
|
|
{
|
|
|
|
|
output = (mutations[current_wheel][i].from - key_shifts[current_wheel]);
|
|
|
|
|
while (output < 0)
|
|
|
|
|
{
|
|
|
|
|
output += ALPHABET_SIZE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
output = output % ALPHABET_SIZE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t encode(size_t index)
|
|
|
|
|
{
|
|
|
|
|
for (size_t i = 0; i < WHEELS_AMOUNT; ++i)
|
|
|
|
|
{
|
|
|
|
|
index += key_shifts[i];
|
|
|
|
|
index = forward(index, i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return index % ALPHABET_SIZE;
|
|
|
|
|
size_t overturning_input = index % ALPHABET_SIZE;
|
|
|
|
|
for (size_t i = 0; i < ALPHABET_SIZE; ++i)
|
|
|
|
|
{
|
|
|
|
|
if (mutations[3][i].from == overturning_input)
|
|
|
|
|
{
|
|
|
|
|
index = mutations[3][i].to;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (size_t i = (WHEELS_AMOUNT - 1); i >= 0; --i)
|
|
|
|
|
{
|
|
|
|
|
index = backward(index, i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void rotate()
|
|
|
|
@ -75,17 +128,17 @@ void loop()
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const String value = String(key, HEX);
|
|
|
|
|
const size_t index = toKeyIndex(value);
|
|
|
|
|
const uint16_t index = toKeyIndex(value);
|
|
|
|
|
if (index == -1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
rotate();
|
|
|
|
|
size_t encoded_index = encode(index);
|
|
|
|
|
const String encoded_letter = key_values[encoded_index].view;
|
|
|
|
|
|
|
|
|
|
const String encoded_letter = key_values[encode(index)].view;
|
|
|
|
|
size_t y = 0;
|
|
|
|
|
for (size_t i = 0; i < WHEELS_AMOUNT; ++i)
|
|
|
|
|
{
|
|
|
|
|
HCuOLED.Cursor(4,y);
|
|
|
|
|
HCuOLED.Cursor(4, y);
|
|
|
|
|
HCuOLED.SetFont(MedProp_11pt);
|
|
|
|
|
HCuOLED.Print(key_shifts[i]);
|
|
|
|
|
y += 20;
|
|
|
|
@ -101,4 +154,5 @@ void loop()
|
|
|
|
|
|
|
|
|
|
lcd.clear();
|
|
|
|
|
lcd.print(lcd_output);
|
|
|
|
|
rotate();
|
|
|
|
|
}
|
|
|
|
|