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