mirror of
https://github.com/0015/ThatProject.git
synced 2026-01-12 17:27:43 +03:00
ESP32 | LVGL8 | Ep 2. Shortcuts for Pull Stack Developer
This commit is contained in:
50
ESP32_LVGL/LVGL8/2_LILYPI_StackOverflow_BLE/BLECont.cpp
Normal file
50
ESP32_LVGL/LVGL8/2_LILYPI_StackOverflow_BLE/BLECont.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include <Arduino.h>
|
||||
#include <BleKeyboard.h>
|
||||
#include "BLECont.h"
|
||||
#include "MyShortcut.h"
|
||||
|
||||
#define ALIVE_INTERVAL 100
|
||||
|
||||
BLECont::BLECont() {
|
||||
bleKeyboard = new BleKeyboard("My Shortcuts v2", "That Project", 100);
|
||||
isConnected = false;
|
||||
previousTimestamp = 0;
|
||||
}
|
||||
|
||||
void BLECont::begin() {
|
||||
bleKeyboard->begin();
|
||||
}
|
||||
|
||||
void BLECont::loop() {
|
||||
unsigned long currentTimestamp = millis();
|
||||
if (currentTimestamp - previousTimestamp > ALIVE_INTERVAL) {
|
||||
previousTimestamp = currentTimestamp;
|
||||
|
||||
if (isConnected != bleKeyboard->isConnected()) {
|
||||
isConnected = bleKeyboard->isConnected();
|
||||
callback(isConnected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sendTask(void *pvParam) {
|
||||
MyShortcut *_myShortcut = reinterpret_cast<MyShortcut *>(pvParam);
|
||||
_myShortcut->Action();
|
||||
vTaskDelay(100);
|
||||
_myShortcut->RelaseAllkey();
|
||||
delete _myShortcut;
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
||||
void BLECont::triggerTask(int caseNum) {
|
||||
if (!isConnected) return;
|
||||
|
||||
MyShortcut *myShortcut = new MyShortcut(bleKeyboard, caseNum);
|
||||
xTaskCreate(
|
||||
sendTask, /* Function that implements the task. */
|
||||
"sendTask", /* Text name for the task. */
|
||||
4096, /* Stack size in words, not bytes. */
|
||||
(void *)myShortcut, /* Parameter passed into the task. */
|
||||
1, /* Priority at which the task is created. */
|
||||
NULL); /* Used to pass out the created task's handle. */
|
||||
}
|
||||
Reference in New Issue
Block a user