Compare commits
No commits in common. "main" and "v1.1" have entirely different histories.
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,2 +1,5 @@
|
||||||
.pio
|
.pio
|
||||||
.vscode
|
.vscode/.browse.c_cpp.db*
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
.vscode/launch.json
|
||||||
|
.vscode/ipch
|
||||||
|
|
10
.vscode/extensions.json
vendored
Normal file
10
.vscode/extensions.json
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
],
|
||||||
|
"unwantedRecommendations": [
|
||||||
|
"ms-vscode.cpptools-extension-pack"
|
||||||
|
]
|
||||||
|
}
|
79
.vscode/settings.json
vendored
Normal file
79
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
{
|
||||||
|
"files.associations": {
|
||||||
|
"optional": "cpp",
|
||||||
|
"istream": "cpp",
|
||||||
|
"ostream": "cpp",
|
||||||
|
"ratio": "cpp",
|
||||||
|
"system_error": "cpp",
|
||||||
|
"array": "cpp",
|
||||||
|
"functional": "cpp",
|
||||||
|
"tuple": "cpp",
|
||||||
|
"type_traits": "cpp",
|
||||||
|
"utility": "cpp",
|
||||||
|
"*.tcc": "cpp",
|
||||||
|
"chrono": "cpp",
|
||||||
|
"ctime": "cpp",
|
||||||
|
"iomanip": "cpp",
|
||||||
|
"limits": "cpp",
|
||||||
|
"numeric": "cpp",
|
||||||
|
"streambuf": "cpp",
|
||||||
|
"random": "cpp"
|
||||||
|
},
|
||||||
|
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||||
|
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||||
|
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||||
|
"C_Cpp_Runner.cStandard": "",
|
||||||
|
"C_Cpp_Runner.cppStandard": "",
|
||||||
|
"C_Cpp_Runner.msvcBatchPath": "",
|
||||||
|
"C_Cpp_Runner.useMsvc": false,
|
||||||
|
"C_Cpp_Runner.warnings": [
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-Wpedantic",
|
||||||
|
"-Wshadow",
|
||||||
|
"-Wformat=2",
|
||||||
|
"-Wcast-align",
|
||||||
|
"-Wconversion",
|
||||||
|
"-Wsign-conversion",
|
||||||
|
"-Wnull-dereference"
|
||||||
|
],
|
||||||
|
"C_Cpp_Runner.msvcWarnings": [
|
||||||
|
"/W4",
|
||||||
|
"/permissive-",
|
||||||
|
"/w14242",
|
||||||
|
"/w14287",
|
||||||
|
"/w14296",
|
||||||
|
"/w14311",
|
||||||
|
"/w14826",
|
||||||
|
"/w44062",
|
||||||
|
"/w44242",
|
||||||
|
"/w14905",
|
||||||
|
"/w14906",
|
||||||
|
"/w14263",
|
||||||
|
"/w44265",
|
||||||
|
"/w14928"
|
||||||
|
],
|
||||||
|
"C_Cpp_Runner.enableWarnings": true,
|
||||||
|
"C_Cpp_Runner.warningsAsError": false,
|
||||||
|
"C_Cpp_Runner.compilerArgs": [],
|
||||||
|
"C_Cpp_Runner.linkerArgs": [],
|
||||||
|
"C_Cpp_Runner.includePaths": [],
|
||||||
|
"C_Cpp_Runner.includeSearch": [
|
||||||
|
"*",
|
||||||
|
"**/*"
|
||||||
|
],
|
||||||
|
"C_Cpp_Runner.excludeSearch": [
|
||||||
|
"**/build",
|
||||||
|
"**/build/**",
|
||||||
|
"**/.*",
|
||||||
|
"**/.*/**",
|
||||||
|
"**/.vscode",
|
||||||
|
"**/.vscode/**"
|
||||||
|
],
|
||||||
|
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||||
|
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||||
|
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||||
|
"C_Cpp_Runner.showCompilationTime": false,
|
||||||
|
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||||
|
"C_Cpp_Runner.msvcSecureNoWarnings": false
|
||||||
|
}
|
|
@ -13,5 +13,4 @@ platform = raspberrypi
|
||||||
board = adafruit_kb2040
|
board = adafruit_kb2040
|
||||||
framework = arduino
|
framework = arduino
|
||||||
upload_protocol = picotool
|
upload_protocol = picotool
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
lib_deps = fastled/FastLED@^3.9.4
|
|
40
src/main.cpp
40
src/main.cpp
|
@ -2,14 +2,10 @@
|
||||||
#include <pico.h>
|
#include <pico.h>
|
||||||
#include <hardware/pwm.h>
|
#include <hardware/pwm.h>
|
||||||
#include <Keyboard.h>
|
#include <Keyboard.h>
|
||||||
#include <FastLED.h>
|
|
||||||
|
|
||||||
#define PORT 2
|
#define PORT 2
|
||||||
#define PORT2 3
|
#define PORT2 3
|
||||||
#define THRESHOLD 10
|
#define THRESHOLD 10
|
||||||
#define LEDPORT 5
|
|
||||||
|
|
||||||
CRGB leds[2];
|
|
||||||
|
|
||||||
class HallButton
|
class HallButton
|
||||||
{
|
{
|
||||||
|
@ -19,18 +15,14 @@ public:
|
||||||
uint64_t firstPulseLength[3]; // value of button
|
uint64_t firstPulseLength[3]; // value of button
|
||||||
int64_t value;
|
int64_t value;
|
||||||
uint64_t _median;
|
uint64_t _median;
|
||||||
int64_t maxValue;
|
|
||||||
bool isFirstClick = true;
|
|
||||||
bool isDataReadyToRead = false;
|
bool isDataReadyToRead = false;
|
||||||
bool isButtonPressed = false;
|
bool isButtonPressed = false;
|
||||||
uint64_t nextTogglePoint = 0; // value when to toggle state of button
|
uint64_t nextTogglePoint = 0; // value when to toggle state of button
|
||||||
size_t ledId;
|
|
||||||
|
|
||||||
HallButton(uint8_t gpioNum, char buttonOnKeyboard, size_t ledId)
|
HallButton(uint8_t gpioNum, char buttonOnKeyboard)
|
||||||
{
|
{
|
||||||
this->gpioNum = gpioNum;
|
this->gpioNum = gpioNum;
|
||||||
this->buttonOnKeyboard = buttonOnKeyboard;
|
this->buttonOnKeyboard = buttonOnKeyboard;
|
||||||
this->ledId = ledId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HandleISR(bool gpioState, uint64_t currentTime)
|
void HandleISR(bool gpioState, uint64_t currentTime)
|
||||||
|
@ -53,19 +45,13 @@ public:
|
||||||
return;
|
return;
|
||||||
_median = median(firstPulseLength[0], firstPulseLength[1], firstPulseLength[2]);
|
_median = median(firstPulseLength[0], firstPulseLength[1], firstPulseLength[2]);
|
||||||
value = filtered((float)_median);
|
value = filtered((float)_median);
|
||||||
if (value > maxValue)
|
if (nextTogglePoint == 0)
|
||||||
if (isFirstClick)
|
nextTogglePoint = value + THRESHOLD;
|
||||||
maxValue = value;
|
|
||||||
else
|
|
||||||
value = maxValue;
|
|
||||||
|
|
||||||
if (isButtonPressed)
|
if (isButtonPressed)
|
||||||
{
|
{
|
||||||
if (value < nextTogglePoint)
|
if (value < nextTogglePoint)
|
||||||
{
|
{
|
||||||
Release();
|
Release();
|
||||||
if (isFirstClick)
|
|
||||||
isFirstClick = false;
|
|
||||||
}
|
}
|
||||||
if ((int64_t)value - (int64_t)nextTogglePoint > THRESHOLD)
|
if ((int64_t)value - (int64_t)nextTogglePoint > THRESHOLD)
|
||||||
nextTogglePoint = value - THRESHOLD;
|
nextTogglePoint = value - THRESHOLD;
|
||||||
|
@ -108,7 +94,6 @@ private:
|
||||||
return;
|
return;
|
||||||
Keyboard.press(buttonOnKeyboard);
|
Keyboard.press(buttonOnKeyboard);
|
||||||
isButtonPressed = true;
|
isButtonPressed = true;
|
||||||
LEDTick(isButtonPressed, ledId);
|
|
||||||
}
|
}
|
||||||
void Release()
|
void Release()
|
||||||
{
|
{
|
||||||
|
@ -116,16 +101,10 @@ private:
|
||||||
return;
|
return;
|
||||||
Keyboard.release(buttonOnKeyboard);
|
Keyboard.release(buttonOnKeyboard);
|
||||||
isButtonPressed = false;
|
isButtonPressed = false;
|
||||||
LEDTick(isButtonPressed, ledId);
|
|
||||||
}
|
|
||||||
static void LEDTick(bool status, size_t ledId)
|
|
||||||
{
|
|
||||||
leds[ledId] = status ? CRGB::Red : CRGB::Black;
|
|
||||||
FastLED.show();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
HallButton btn[2] = {HallButton(PORT, 't', 1), HallButton(PORT2, 'y', 0)};
|
HallButton btn[2] = {HallButton(PORT, 't'), HallButton(PORT2, 'y')};
|
||||||
|
|
||||||
void isr(uint gpio, uint32_t events)
|
void isr(uint gpio, uint32_t events)
|
||||||
{
|
{
|
||||||
|
@ -154,19 +133,12 @@ void setup()
|
||||||
gpio_set_irq_enabled_with_callback(PORT2, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true, isr);
|
gpio_set_irq_enabled_with_callback(PORT2, GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL, true, isr);
|
||||||
// Serial.begin(9600);
|
// Serial.begin(9600);
|
||||||
Keyboard.begin();
|
Keyboard.begin();
|
||||||
FastLED.addLeds<NEOPIXEL, LEDPORT>(leds, 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void printDebugInfo()
|
void printDebugInfo()
|
||||||
{
|
{
|
||||||
static uint32_t lastTime = 0;
|
Serial.printf("%llu,%llu,%llu,%llu,%i,", btn[0].firstPulseLength[btn[0].counter], btn[0]._median, btn[0].value, btn[0].nextTogglePoint, btn[0].isButtonPressed);
|
||||||
uint32_t time = millis();
|
Serial.printf("%llu,%llu,%llu,%llu,%i\n", btn[1].firstPulseLength[btn[1].counter], btn[1]._median, btn[1].value, btn[1].nextTogglePoint, btn[1].isButtonPressed);
|
||||||
if (time - lastTime >= 1)
|
|
||||||
{
|
|
||||||
Serial.printf("%d,%d,%llu,%llu,%i,", btn[0].isFirstClick, btn[0].maxValue, btn[0].value, btn[0].nextTogglePoint, btn[0].isButtonPressed);
|
|
||||||
Serial.printf("%d,%d,%llu,%llu,%i\n", btn[1].isFirstClick, btn[1].maxValue, btn[1].value, btn[1].nextTogglePoint, btn[1].isButtonPressed);
|
|
||||||
lastTime = time;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user