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