1
0
Fork 0

Fix iteration by wheels

This commit is contained in:
NaiJi ✨ 2022-03-21 19:53:49 +03:00
parent a1933c04df
commit 1c4c94774d
1 changed files with 19 additions and 33 deletions

View File

@ -1,18 +1,22 @@
#include <LiquidCrystal_I2C.h>
#include <PS2KeyAdvanced.h> #include <PS2KeyAdvanced.h>
#include <Wire.h> #include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "enigma_types.h" #include "enigma_types.h"
#include "HCuOLED.h" #include "HCuOLED.h"
#include "SPI.h" #include "SPI.h"
#define DATAPIN 4 #define DATAPIN 4
#define IRQPIN 3 #define IRQPIN 3
#define CS_DI 10 #define CS_DI 10
#define DC_DI 9 #define DC_DI 9
#define RST_DI 8 #define RST_DI 8
PS2KeyAdvanced keyboard; PS2KeyAdvanced keyboard;
HCuOLED HCuOLED(SH1106, CS_DI, DC_DI, RST_DI); // For SH1106 displays (HCMODU0058 & HCMODU0059) HCuOLED HCuOLED(SH1106, CS_DI, DC_DI, RST_DI);
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2); LiquidCrystal_I2C lcd(0x27, 16, 2);
String lcd_output;
size_t toKeyIndex(const String& input_hex) size_t toKeyIndex(const String& input_hex)
{ {
@ -29,7 +33,7 @@ size_t toKeyIndex(const String& input_hex)
return index; return index;
} }
size_t shift(size_t index) size_t encode(size_t index)
{ {
for (size_t i = 0; i < WHEELS_AMOUNT; ++i) for (size_t i = 0; i < WHEELS_AMOUNT; ++i)
{ {
@ -41,41 +45,23 @@ size_t shift(size_t index)
void rotate() void rotate()
{ {
++key_shifts[0]; for (size_t i = 0; i < WHEELS_AMOUNT; ++i)
if (key_shifts[0] == 26)
{ {
key_shifts[0] = 1; ++key_shifts[i];
++key_shifts[1]; if (key_shifts[i] != ALPHABET_SIZE)
if (key_shifts[1] == 26) key_shifts[i] = 0;
{ else
key_shifts[1] = 1; break;
++key_shifts[2];
if (key_shifts[2] == 26)
{
key_shifts[2] = 1;
} }
} }
}
Serial.print(key_shifts[0]);
Serial.print(" ");
Serial.print(key_shifts[1]);
Serial.print(" ");
Serial.print(key_shifts[2]);
Serial.println(" ");
}
String lcd_output;
void setup() void setup()
{ {
HCuOLED.Reset(); HCuOLED.Reset();
keyboard.begin(DATAPIN, IRQPIN); keyboard.begin(DATAPIN, IRQPIN);
Serial.begin(115200); Serial.begin(115200);
// initialize the LCD
lcd.begin();
// Turn on the blacklight and print a message. lcd.begin();
lcd.backlight(); lcd.backlight();
} }
@ -95,7 +81,7 @@ void loop()
rotate(); rotate();
const String encoded_letter = key_values[shift(index)].view; const String encoded_letter = key_values[encode(index)].view;
size_t y = 0; size_t y = 0;
for (size_t i = 0; i < WHEELS_AMOUNT; ++i) for (size_t i = 0; i < WHEELS_AMOUNT; ++i)
{ {