Input: refactoring, platform agnostic key configuration.
Update input usage across project. Minor queue usage fixes and tick timings. (#330)
This commit is contained in:
@@ -4,27 +4,17 @@
|
||||
|
||||
typedef union {
|
||||
unsigned int packed;
|
||||
InputState state;
|
||||
InputType state;
|
||||
} InputDump;
|
||||
|
||||
static void state_cb(const void* value, void* ctx) {
|
||||
InputDump dump = {.packed = 0};
|
||||
dump.state = *(InputState*)value;
|
||||
|
||||
printf("state: %02x\r\n", dump.packed);
|
||||
}
|
||||
|
||||
static void event_cb(const void* value, void* ctx) {
|
||||
const InputEvent* event = value;
|
||||
|
||||
printf("event: %02x %s\r\n", event->input, event->state ? "pressed" : "released");
|
||||
printf("event: %02x %s\r\n", event->key, event->type ? "pressed" : "released");
|
||||
}
|
||||
|
||||
void application_input_dump(void* p) {
|
||||
// open record
|
||||
ValueManager* state_record = furi_record_open("input_state");
|
||||
subscribe_pubsub(&state_record->pubsub, state_cb, NULL);
|
||||
|
||||
PubSub* event_record = furi_record_open("input_events");
|
||||
subscribe_pubsub(event_record, event_cb, NULL);
|
||||
|
||||
|
@@ -7,11 +7,11 @@ static void event_cb(const void* value, void* ctx) {
|
||||
uint32_t* delay_time = acquire_mutex(ctx, 0);
|
||||
if(delay_time == NULL) return;
|
||||
|
||||
if(event->input == InputUp && *delay_time < 1000) {
|
||||
if(event->key == InputKeyUp && *delay_time < 1000) {
|
||||
*delay_time += 5;
|
||||
}
|
||||
|
||||
if(event->input == InputDown && *delay_time > 10) {
|
||||
if(event->key == InputKeyDown && *delay_time > 10) {
|
||||
*delay_time -= 5;
|
||||
}
|
||||
release_mutex(ctx, delay_time);
|
||||
|
@@ -10,9 +10,14 @@ static void button_handler(const void* value, void* _ctx) {
|
||||
const InputEvent* event = value;
|
||||
Ctx* ctx = (Ctx*)_ctx;
|
||||
|
||||
if(event->input == InputOk) {
|
||||
gpio_write(ctx->vibro, event->state);
|
||||
gpio_write(ctx->led, !event->state);
|
||||
if(event->key != InputKeyOk) return;
|
||||
|
||||
if(event->type == InputTypePress) {
|
||||
gpio_write(ctx->led, false);
|
||||
gpio_write(ctx->vibro, true);
|
||||
} else if(event->type == InputTypeRelease) {
|
||||
gpio_write(ctx->led, true);
|
||||
gpio_write(ctx->vibro, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user