Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

language change on PC with T-Keyboard. #18

Open
Stigjs opened this issue Dec 3, 2024 · 1 comment
Open

language change on PC with T-Keyboard. #18

Stigjs opened this issue Dec 3, 2024 · 1 comment

Comments

@Stigjs
Copy link

Stigjs commented Dec 3, 2024

Hello
I've never done coding in my life, like VS CODE, but I believe in ChatGPT
I bought a LILYGO T-Keyboard.

I tried to add language conversion (English/Korean) function using GitHub's firmware data and VS code,

The code that ChatGPT corrected keeps making errors..

  1. Change the language to the left alt key and enter key. (You can't change the line when you enter.)
  2. Set Backlight Time
    Backlight off if not entered for 10 seconds. On input back on
  3. Delete letters when you press the Backspace key
    I don't want to press it repeatedly..
  4. Make sure you enter numbers/periods with the left shift key. I asked for these four functions

I kept erasing the original code, so I couldn't do it
I downloaded VS and installed Platformio through ChatGPT
I can't use it because I can't change the language. Please help me..
What should I do?

@Stigjs
Copy link
Author

Stigjs commented Dec 3, 2024

the Code is..
#define TFT_HIGH 40
#define TFT_WIDE 160
#define GAP 8
#define keyborad_BL_PIN 9

#include "Arduino.h"
#include <SPI.h>
#include "img.h"
#include <TFT_GC9D01N.h>
#include <BleKeyboard.h>

TFT_GC9D01N_Class TFT_099;
BleKeyboard bleKeyboard("T-Keyboard", "ESPRESSIF", 100);

byte rows[] = {0, 3, 18, 12, 11, 6, 7};
const int rowCount = sizeof(rows) / sizeof(rows[0]);

byte cols[] = {1, 4, 5, 19, 13};
const int colCount = sizeof(cols) / sizeof(cols[0]);

bool keys[colCount][rowCount];
bool lastValue[colCount][rowCount];
bool changedValue[colCount][rowCount];

char keyboard[colCount][rowCount];
char keyboard_symbol[colCount][rowCount];

bool symbolSelected = false;
bool isEnglish = true; // 언어 전환 상태
bool alt_active = false;
int OffsetX = 0;
bool keyborad_BL_state = true;
bool display_connected = true;
bool case_locking = false;

unsigned long previousMillis_1 = 0;
unsigned long previousMillis_2 = 0;
const long backlight_off_time = 10000; // 10초
const long display_Wait_blue_time = 2000;

void readMatrix();
bool keyPressed(int colIndex, int rowIndex);
bool keyActive(int colIndex, int rowIndex);
bool isPrintableKey(int colIndex, int rowIndex);
void printMatrix();
void set_keyborad_BL(bool state);
void clear_sccreen();

void setup() {
Serial.begin(115200);
Serial.println("Setup started");

// 키보드 배열 초기화
keyboard[0][0] = 'q';
keyboard[0][1] = 'w';
keyboard[0][2] = '\0'; // Symbol
keyboard[0][3] = 'a';
keyboard[0][4] = '\0'; // ALT
keyboard[0][5] = ' ';
keyboard[0][6] = '\0'; // Mic

keyboard[1][0] = 'e';
keyboard[1][1] = 's';
keyboard[1][2] = 'd';
keyboard[1][3] = 'p';
keyboard[1][4] = 'x';
keyboard[1][5] = 'z';
keyboard[1][6] = '\0'; // Left Shift

keyboard[2][0] = 'r';
keyboard[2][1] = 'g';
keyboard[2][2] = 't';
keyboard[2][3] = '\0'; // Right Shift
keyboard[2][4] = 'v';
keyboard[2][5] = 'c';
keyboard[2][6] = 'f';

keyboard[3][0] = 'u';
keyboard[3][1] = 'h';
keyboard[3][2] = 'y';
keyboard[3][3] = '\0'; // Enter
keyboard[3][4] = 'b';
keyboard[3][5] = 'n';
keyboard[3][6] = 'j';

keyboard[4][0] = 'o';
keyboard[4][1] = 'l';
keyboard[4][2] = 'i';
keyboard[4][3] = '\0'; // Backspace
keyboard[4][4] = '$';
keyboard[4][5] = 'm';
keyboard[4][6] = 'k';

delay(500);
pinMode(keyborad_BL_PIN, OUTPUT);
set_keyborad_BL(keyborad_BL_state);

bleKeyboard.begin();

for (int x = 0; x < rowCount; x++) {
    pinMode(rows[x], INPUT);
}

for (int x = 0; x < colCount; x++) {
    pinMode(cols[x], INPUT_PULLUP);
}

TFT_099.begin();
TFT_099.backlight(50);
TFT_099.DispColor(0, 0, TFT_WIDTH, TFT_HEIGHT, BLACK);
TFT_099.DispStr((char*)"Setup completed", 0, 2, WHITE, BLACK); // char*로 캐스팅
Serial.println("Setup completed");

}

void loop() {
if (bleKeyboard.isConnected()) {
readMatrix();

    // ALT(4,0) + ENTER(3,3) 언어 전환
    if (keyActive(4, 0) && keyPressed(3, 3)) {
        isEnglish = !isEnglish;
        TFT_099.DispStr(isEnglish ? (char*)"English Mode" : (char*)"Korean Mode", 0, 2, WHITE, BLACK);
        Serial.println(isEnglish ? "English Mode" : "Korean Mode");
        delay(500);
    }

    // 백라이트 제어
    if (millis() - previousMillis_1 > backlight_off_time) {
        TFT_099.backlight(0);
    }

    printMatrix();

    // Backspace 키 동작
    if (keyPressed(4, 3)) {
        if (OffsetX > 0) OffsetX -= GAP;
        TFT_099.DispColor(0, OffsetX, TFT_HIGH, TFT_WIDE, BLACK);
        bleKeyboard.press(KEY_BACKSPACE);
        bleKeyboard.releaseAll();
    }

    // Left Shift 키로 특수문자 입력
    if (keyActive(1, 6)) {
        case_locking = true;
    } else {
        case_locking = false;
    }

} else {
    if (millis() - previousMillis_2 > display_Wait_blue_time) {
        TFT_099.DispStr((char*)"Waiting for Bluetooth...", 0, 2, WHITE, BLACK); // char*로 캐스팅
        display_connected = true;
        previousMillis_2 = millis();
    }
}

}

void readMatrix() {
for (int colIndex = 0; colIndex < colCount; colIndex++) {
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
bool currentValue = digitalRead(cols[colIndex]) == LOW && digitalRead(rows[rowIndex]) == LOW;
if (currentValue != lastValue[colIndex][rowIndex]) {
changedValue[colIndex][rowIndex] = true;
} else {
changedValue[colIndex][rowIndex] = false;
}
keys[colIndex][rowIndex] = currentValue;
lastValue[colIndex][rowIndex] = currentValue;
}
}
}

bool keyPressed(int colIndex, int rowIndex) {
return changedValue[colIndex][rowIndex] && keys[colIndex][rowIndex];
}

bool keyActive(int colIndex, int rowIndex) {
return keys[colIndex][rowIndex];
}

bool isPrintableKey(int colIndex, int rowIndex) {
return keyboard[colIndex][rowIndex] != '\0';
}

void printMatrix() {
for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
for (int colIndex = 0; colIndex < colCount; colIndex++) {
if (keyPressed(colIndex, rowIndex)) {
String key = String(keyboard[colIndex][rowIndex]);
if (case_locking) key.toUpperCase();
Serial.print(key);
bleKeyboard.print(key);
OffsetX += GAP;
if (OffsetX > 160) {
OffsetX = 0;
clear_sccreen();
}
}
}
}
}

void set_keyborad_BL(bool state) {
digitalWrite(keyborad_BL_PIN, state);
}

void clear_sccreen() {
TFT_099.DispColor(0, 0, TFT_HIGH, TFT_WIDE, BLACK);
OffsetX = 0;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant