add TrackSpeed in devterm_keyboard

This commit is contained in:
cuu
2021-05-31 17:22:42 +08:00
parent ec9d220daf
commit bf187a9518
3 changed files with 48 additions and 11 deletions

View File

@@ -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*);