mirror of
https://github.com/clockworkpi/DevTerm.git
synced 2025-12-12 18:28:50 +01:00
add TrackSpeed in devterm_keyboard
This commit is contained in:
parent
ec9d220daf
commit
bf187a9518
@ -5,7 +5,7 @@
|
||||
|
||||
#include <USBComposite.h>
|
||||
|
||||
#define SER_NUM_STR "20210515"
|
||||
#define SER_NUM_STR "20210531"
|
||||
|
||||
USBHID HID;
|
||||
DEVTERM dev_term;
|
||||
|
||||
@ -5,10 +5,12 @@
|
||||
|
||||
#include "keys_io_map.h"
|
||||
|
||||
#define BOUNCE_INTERVAL 100
|
||||
#define BASE_MOVE_PIXELS 3
|
||||
#define EXPONENTIAL_BOUND 10
|
||||
/*
|
||||
#define BOUNCE_INTERVAL 30
|
||||
#define BASE_MOVE_PIXELS 5
|
||||
#define EXPONENTIAL_BOUND 15
|
||||
#define EXPONENTIAL_BASE 1.2
|
||||
*/
|
||||
|
||||
#define BTN_PIN KEY0
|
||||
#define RIGHT_PIN HO3
|
||||
@ -16,7 +18,13 @@
|
||||
#define DOWN_PIN HO4
|
||||
#define UP_PIN HO2
|
||||
|
||||
|
||||
typedef struct _track_speed {
|
||||
uint8_t bounce_interval;
|
||||
uint8_t base_move_pixels;
|
||||
uint8_t exponential_bound;
|
||||
double exponential_base;
|
||||
|
||||
}TrackSpeed;
|
||||
|
||||
class Direction {
|
||||
public:
|
||||
@ -33,22 +41,24 @@ class Direction {
|
||||
this->current_action_times[i] = millis();
|
||||
if(this->current_actions[i] != this->last_actions[i]) {
|
||||
this->last_actions[i] = this->current_actions[i];
|
||||
exponential = (EXPONENTIAL_BOUND - (this->current_action_times[i] - this->last_action_times[i]));
|
||||
exponential = ( ts->exponential_bound - (this->current_action_times[i] - this->last_action_times[i]));
|
||||
exponential = (exponential > 0) ? exponential : 1;
|
||||
move_multiply = EXPONENTIAL_BASE;
|
||||
move_multiply = ts->exponential_base;
|
||||
for(int i = 0; i < exponential; ++i) {
|
||||
move_multiply *= EXPONENTIAL_BASE;
|
||||
move_multiply *= ts->exponential_base;
|
||||
}
|
||||
this->last_action_times[i] = this->current_action_times[i];
|
||||
if(i == 0) {
|
||||
return (-1) * BASE_MOVE_PIXELS * move_multiply;
|
||||
return (-1) * ts->base_move_pixels * move_multiply;
|
||||
} else {
|
||||
return BASE_MOVE_PIXELS * move_multiply;
|
||||
return ts->base_move_pixels * move_multiply;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
TrackSpeed *ts;
|
||||
|
||||
private:
|
||||
int pins[2];
|
||||
@ -58,6 +68,7 @@ class Direction {
|
||||
double move_multiply;
|
||||
unsigned long current_action_times[2];
|
||||
unsigned long last_action_times[2];
|
||||
|
||||
};
|
||||
|
||||
void trackball_init(DEVTERM*);
|
||||
|
||||
@ -22,12 +22,26 @@ int x_move, y_move;
|
||||
Direction x_direction(LEFT_PIN, RIGHT_PIN);
|
||||
Direction y_direction(UP_PIN, DOWN_PIN);
|
||||
|
||||
TrackSpeed Normal_ts;
|
||||
TrackSpeed Detail_ts;
|
||||
TrackSpeed *ts_ptr;
|
||||
|
||||
void trackball_task(DEVTERM*dv) {
|
||||
|
||||
if(dv-> Keyboard_state.fn_on > 0) {
|
||||
ts_ptr = &Detail_ts;
|
||||
}else {
|
||||
ts_ptr = &Normal_ts;
|
||||
}
|
||||
|
||||
x_direction.ts = ts_ptr;
|
||||
y_direction.ts = ts_ptr;
|
||||
|
||||
btn_read_state = digitalRead(BTN_PIN);
|
||||
|
||||
if(btn_read_state != btn_state) {
|
||||
btn_current_action_time = millis();
|
||||
if(btn_current_action_time - btn_last_action_time > BOUNCE_INTERVAL) {
|
||||
if(btn_current_action_time - btn_last_action_time > ts_ptr->bounce_interval ) {
|
||||
btn_state = btn_read_state;
|
||||
btn_last_action_time = btn_current_action_time;
|
||||
|
||||
@ -50,4 +64,16 @@ void trackball_task(DEVTERM*dv) {
|
||||
|
||||
void trackball_init(DEVTERM*){
|
||||
pinMode(BTN_PIN,INPUT);
|
||||
|
||||
Normal_ts.bounce_interval = 30;
|
||||
Normal_ts.base_move_pixels = 5;
|
||||
Normal_ts.exponential_bound = 14;
|
||||
Normal_ts.exponential_base = 1.2;
|
||||
|
||||
Detail_ts.bounce_interval = 100;
|
||||
Detail_ts.base_move_pixels = 3;
|
||||
Detail_ts.exponential_bound = 10;
|
||||
Detail_ts.exponential_base = 1.2;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user