Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Keymap] Add new IIDX gamepad keymap for Synth Labs Solo #18741

Merged
merged 7 commits into from
Oct 26, 2022
Merged
2 changes: 1 addition & 1 deletion keyboards/synthlabs/solo/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@
#define BOOTMAGIC_LITE_ROW 1
#define BOOTMAGIC_LITE_COLUMN 1

#define JOYSTICK_BUTTON_COUNT 8
#define JOYSTICK_BUTTON_COUNT 13
#define JOYSTICK_AXES_COUNT 1
#define JOYSTICK_AXES_RESOLUTION 16
2 changes: 1 addition & 1 deletion keyboards/synthlabs/solo/keymaps/gamepad/readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Gamepad Synth Labs Solo Layout

This keymap is intended for usage as a IIDX controller. The rotary encoder is mapped as a virtual 1-axis joystick.
This keymap is intended for usage as a generic gamepad. The rotary encoder is mapped as a virtual 1-axis joystick.
91 changes: 91 additions & 0 deletions keyboards/synthlabs/solo/keymaps/iidx/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2022 Aaron Hong (@hongaaronc)
// SPDX-License-Identifier: GPL-2.0-or-later

#include QMK_KEYBOARD_H

#include "joystick.h"

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT_all(
JS_BUTTON0,JS_BUTTON1,JS_BUTTON2,JS_BUTTON3,JS_BUTTON4,JS_BUTTON5,JS_BUTTON6,
JS_BUTTON8, MO(1), JS_BUTTON7,
JS_BUTTON0,JS_BUTTON1,JS_BUTTON2,JS_BUTTON3,JS_BUTTON4,JS_BUTTON5,JS_BUTTON6
),
[1] = LAYOUT_all(
JS_BUTTON9,JS_BUTTON0,JS_BUTTON10, _______,JS_BUTTON11,JS_BUTTON1,JS_BUTTON12,
_______, _______, _______,
JS_BUTTON10,JS_BUTTON0,JS_BUTTON9, _______,JS_BUTTON11,JS_BUTTON1,JS_BUTTON12
),
};

#if defined(ENCODER_ENABLE)

enum encoder_direction {
DIRECTION_CW,
DIRECTION_CCW
};

#ifdef ENCODERS
int16_t encoder_stationary_release_delay_ms = 25;

static uint8_t encoder_state[] = {0};
static keypos_t encoder_cw[] = ENCODERS_CW_KEY;
static keypos_t encoder_ccw[] = ENCODERS_CCW_KEY;
static uint16_t encoder_last_update_time[] = {0};
static enum encoder_direction encoder_last_direction[] = {DIRECTION_CW};
#endif

void encoder_action_unregister(uint8_t index) {
#ifdef ENCODERS
if (encoder_state[index]) {
keyevent_t encoder_event = (keyevent_t) {
.key = encoder_state[index] >> 1 ? encoder_cw[index] : encoder_ccw[index],
.pressed = false,
.time = (timer_read() | 1)
};
encoder_state[index] = 0;
action_exec(encoder_event);
}
#endif
}

void encoder_action_register(uint8_t index, bool clockwise) {
#ifdef ENCODERS
keyevent_t encoder_event = (keyevent_t) {
.key = clockwise ? encoder_cw[index] : encoder_ccw[index],
.pressed = true,
.time = (timer_read() | 1)
};

/* Record the time that the encoder was detected as rotated */
encoder_last_update_time[index] = timer_read();

/* Check if the encoder direction has reversed, and if so unregister the opposite direction's event */
enum encoder_direction new_direction = clockwise ? DIRECTION_CW : DIRECTION_CCW;
if (encoder_last_direction[index] != new_direction) {
encoder_action_unregister(index);
}
encoder_last_direction[index] = new_direction;

encoder_state[index] = (clockwise ^ 1) | (clockwise << 1);
action_exec(encoder_event);
#endif
}

void matrix_scan_user(void) {
/* If an encoder has been stationary for encoder_stationary_release_delay_ms, then unregister its event */
uint16_t current_time = timer_read();
for (int index = 0; index < ENCODERS; ++index) {
uint16_t elapsed_time_since_last_update = current_time - encoder_last_update_time[index];
if (elapsed_time_since_last_update >= encoder_stationary_release_delay_ms) {
encoder_action_unregister(index);
}
}
}

bool encoder_update_user(uint8_t index, bool clockwise) {
encoder_action_register(index, clockwise);
return false;
}

#endif
15 changes: 15 additions & 0 deletions keyboards/synthlabs/solo/keymaps/iidx/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# IIDX Synth Labs Solo Layout

This keymap is intended for usage as a gamepad for [beatmania IIDX INFINITAS](https://p.eagate.573.jp/game/infinitas/2/index.html).

This keycap follows the default keymapping for the game, shown here:
![Default Keymapping Settings Screen](https://i.imgur.com/Va48FnZ.png)

The face buttons correspond directly to ボタン 1 - ボタン 7

Turning the knob clockwise corresponds to スクラッチ-右回転
Turning the knob counter-clockwise corresponds to スクラッチ-左回転

While holding down the knob button
* The bottom row of face buttons corresponds to ボタン E1 - ボタン E4
* The top-left and top-right face buttons correspond to ボタン 1 and ボタン 2, for adjustment of in-game scroll speed
2 changes: 2 additions & 0 deletions keyboards/synthlabs/solo/keymaps/iidx/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JOYSTICK_ENABLE = yes
DEBOUNCE_TYPE = sym_eager_pk