mirror of
https://github.com/Genaker/LoraSA.git
synced 2026-05-05 21:12:59 +02:00
mark: wip work to move stuff around
This commit is contained in:
47
lib/input/input.cpp
Normal file
47
lib/input/input.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "input.h"
|
||||
|
||||
int cursor_x_position = 0;
|
||||
bool joy_btn_clicked = false;
|
||||
|
||||
static int joyXMid = 0;
|
||||
|
||||
bool joy_btn_click()
|
||||
{
|
||||
joy_btn_clicked = true;
|
||||
return digitalRead(JOY_BTN_PIN) == HIGH ? false : true;
|
||||
}
|
||||
|
||||
void calibrate_joy()
|
||||
{
|
||||
int cal_X = 0;
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
cal_X += analogRead(JOY_X_PIN);
|
||||
}
|
||||
joyXMid = cal_X / 100;
|
||||
}
|
||||
|
||||
static const int MID = 100;
|
||||
|
||||
int get_joy_x(bool logical)
|
||||
{
|
||||
int joyX = analogRead(JOY_X_PIN);
|
||||
|
||||
if (logical)
|
||||
{
|
||||
if (joyX < joyXMid - MID)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (joyX > joyXMid + MID)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return joyX;
|
||||
}
|
||||
Reference in New Issue
Block a user