Browse Source

final

master
gsd 4 months ago
parent
commit
d39b5c8ff8
  1. BIN
      bat_lvl_scheme.JPG
  2. 62
      main/main.ino

BIN
bat_lvl_scheme.JPG

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

62
main/main.ino

@ -5,6 +5,8 @@
#include <fabgl.h> #include <fabgl.h>
//#define DEBUG 1 //#define DEBUG 1
#define BAT_SUPPORT 1
#define EXTERNAL_RGB_LED_SUPPORT 1
using namespace fabgl; using namespace fabgl;
@ -24,21 +26,42 @@ static std::map<VirtualKey, VirtualKey> _virtualKeyMap;
uint8_t convertToKeyCode(VirtualKey virtualKey); uint8_t convertToKeyCode(VirtualKey virtualKey);
#define LED_RED 26 #if defined (EXTERNAL_RGB_LED_SUPPORT)
#define LED_GREEN 27 #define LED_RED 26
#define LED_BLUE 25 #define LED_GREEN 27
#define LED_BLUE 25
#endif
static bool numlockLed = false; #if defined (BAT_SUPPORT)
static bool capslockLed = false; #define BAT_ANALOG 15
static bool scrolllockLed = false; float lastBatteryStatusPublish = -61.0f;
void updateBatteryStatus() {
if (esp_timer_get_time()/1000 - lastBatteryStatusPublish > 60) {
uint8_t lvl = map(analogRead(BAT_ANALOG), 0.0f, 4095.0f, 0, 100);
bleKeyboard.setBatteryLevel(lvl);
lastBatteryStatusPublish = esp_timer_get_time()/1000;
}
}
#endif
void setup() void setup()
{ {
#if defined (EXTERNAL_RGB_LED_SUPPORT)
pinMode(LED_RED, OUTPUT);
pinMode(LED_GREEN, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
digitalWrite(LED_RED, HIGH);
#endif
#if defined(DEBUG) #if defined(DEBUG)
Serial.begin(115200); Serial.begin(115200);
Serial.println("Starting"); Serial.println("Starting");
#endif #endif
#if defined (BAT_SUPPORT)
updateBatteryStatus();
#endif
bleKeyboard.setName("Chicony KB-5191"); bleKeyboard.setName("Chicony KB-5191");
bleKeyboard.begin(); bleKeyboard.begin();
@ -48,17 +71,17 @@ void setup()
Serial.println("Started"); Serial.println("Started");
#endif #endif
pinMode(LED_RED, OUTPUT);
pinMode(LED_GREEN, OUTPUT);
pinMode(LED_BLUE, OUTPUT);
digitalWrite(LED_GREEN, HIGH);
keyboard->setLayout(&fabgl::USLayout); keyboard->setLayout(&fabgl::USLayout);
const KeyboardLayout* layout = keyboard->getLayout(); const KeyboardLayout* layout = keyboard->getLayout();
for (AltVirtualKeyDef keyDef: layout->alternateVK) for (AltVirtualKeyDef keyDef: layout->alternateVK)
{ {
_virtualKeyMap[keyDef.virtualKey] = keyDef.reqVirtualKey; _virtualKeyMap[keyDef.virtualKey] = keyDef.reqVirtualKey;
} }
#if defined (EXTERNAL_RGB_LED_SUPPORT)
digitalWrite(LED_RED, LOW);
digitalWrite(LED_GREEN, HIGH);
#endif
} }
static void updateModifiers(VirtualKey virtualKey, bool keyDown) static void updateModifiers(VirtualKey virtualKey, bool keyDown)
@ -165,11 +188,15 @@ void loop()
if (!bleKeyboard.isConnected()) if (!bleKeyboard.isConnected())
{ {
connected = false; connected = false;
#if defined(DEBUG) #if defined(DEBUG)
Serial.println("Disconnected"); Serial.println("Disconnected");
#endif #endif
#if defined (EXTERNAL_RGB_LED_SUPPORT)
digitalWrite(LED_GREEN, HIGH); digitalWrite(LED_GREEN, HIGH);
digitalWrite(LED_BLUE, LOW); digitalWrite(LED_BLUE, LOW);
#endif
} }
} }
else else
@ -177,11 +204,15 @@ void loop()
if (bleKeyboard.isConnected()) if (bleKeyboard.isConnected())
{ {
connected = true; connected = true;
#if defined(DEBUG) #if defined(DEBUG)
Serial.println("Connected"); Serial.println("Connected");
#endif #endif
#if defined (EXTERNAL_RGB_LED_SUPPORT)
digitalWrite(LED_GREEN, LOW); digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_BLUE, HIGH); digitalWrite(LED_BLUE, HIGH);
#endif
} }
} }
@ -200,6 +231,10 @@ void loop()
updateModifiers(virtualKey, keyDown); updateModifiers(virtualKey, keyDown);
uint8_t keyCode = convertToKeyCode(virtualKey); uint8_t keyCode = convertToKeyCode(virtualKey);
#if defined (BAT_SUPPORT)
updateBatteryStatus();
#endif
#if defined(DEBUG) #if defined(DEBUG)
Serial.print("After convertToKeyCode: "); Serial.print("After convertToKeyCode: ");
Serial.print(virtualKey); Serial.print(virtualKey);
@ -332,11 +367,8 @@ uint8_t convertToKeyCode(VirtualKey virtualKey)
case VK_SLASH: case VK_SLASH:
case VK_QUESTION: case VK_QUESTION:
return 0x38; return 0x38;
case VK_CAPSLOCK: { case VK_CAPSLOCK:
//capslockLed = !capslockLed;
//keyboard->setLEDs(numlockLed, capslockLed, scrolllockLed);
return 0x39; return 0x39;
}
case VK_F1...VK_F12: case VK_F1...VK_F12:
return 0x3A + (virtualKey - VK_F1); return 0x3A + (virtualKey - VK_F1);

Loading…
Cancel
Save