mirror of
https://github.com/qmk/qmk_firmware.git
synced 2024-11-22 03:19:24 +00:00
joy stick
This commit is contained in:
parent
27e232c877
commit
14946e23e8
5
keyboards/takashicompany/left_slinger/config.h
Normal file
5
keyboards/takashicompany/left_slinger/config.h
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#define ANALOG_JOYSTICK_X_AXIS_PIN GP28
|
||||
#define ANALOG_JOYSTICK_Y_AXIS_PIN GP29
|
||||
#define ANALOG_JOYSTICK_READ_INTERVAL 1
|
49
keyboards/takashicompany/left_slinger/custom_joystick.c
Normal file
49
keyboards/takashicompany/left_slinger/custom_joystick.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include QMK_KEYBOARD_H
|
||||
#include "analog.h"
|
||||
#include "gpio.h"
|
||||
#include "wait.h"
|
||||
#include "timer.h"
|
||||
#include <stdlib.h>
|
||||
#include "print.h"
|
||||
#include "custom_joystick.h"
|
||||
|
||||
int16_t xOrigin, yOrigin;
|
||||
uint16_t lastCursor = 0;
|
||||
int16_t joystick_ratio = 100;
|
||||
|
||||
int16_t axisCoordinate_custom(pin_t pin, uint16_t origin) {
|
||||
int8_t direction; // 符号
|
||||
int16_t distanceFromOrigin; // 原点からの距離。負数にはならない
|
||||
|
||||
int16_t position = analogReadPin(pin); // 多分だけどデフォルトだと512が中心に来るようになっている
|
||||
|
||||
if (origin == position) { // 原点と同じなら0とする
|
||||
return 0;
|
||||
} else if (origin > position) { // 原点よりマイナス方向の場合の処理
|
||||
distanceFromOrigin = origin - position;
|
||||
direction = -1;
|
||||
} else { // 原点よりプラス方向の処理
|
||||
distanceFromOrigin = position - origin;
|
||||
direction = 1;
|
||||
}
|
||||
|
||||
return distanceFromOrigin * direction;
|
||||
}
|
||||
|
||||
void pointing_device_driver_init(void) {
|
||||
xOrigin = analogReadPin(ANALOG_JOYSTICK_X_AXIS_PIN);
|
||||
yOrigin = analogReadPin(ANALOG_JOYSTICK_Y_AXIS_PIN);
|
||||
}
|
||||
report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report) {
|
||||
|
||||
if (timer_elapsed(lastCursor) > ANALOG_JOYSTICK_READ_INTERVAL) { // 多分、指定のミリ秒経過したかを見て処理を走らせている
|
||||
lastCursor = timer_read();
|
||||
mouse_report.x = axisCoordinate_custom(ANALOG_JOYSTICK_X_AXIS_PIN, xOrigin) / joystick_ratio;
|
||||
mouse_report.y = axisCoordinate_custom(ANALOG_JOYSTICK_Y_AXIS_PIN, yOrigin) / joystick_ratio;
|
||||
}
|
||||
|
||||
return mouse_report;
|
||||
}
|
||||
|
||||
uint16_t pointing_device_driver_get_cpi(void) { return 0; }
|
||||
void pointing_device_driver_set_cpi(uint16_t cpi) {}
|
6
keyboards/takashicompany/left_slinger/custom_joystick.h
Normal file
6
keyboards/takashicompany/left_slinger/custom_joystick.h
Normal file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
extern int16_t joystick_ratio;
|
4
keyboards/takashicompany/left_slinger/rules.mk
Normal file
4
keyboards/takashicompany/left_slinger/rules.mk
Normal file
@ -0,0 +1,4 @@
|
||||
POINTING_DEVICE_ENABLE = yes
|
||||
POINTING_DEVICE_DRIVER = custom
|
||||
ANALOG_DRIVER_REQUIRED = yes
|
||||
SRC += custom_joystick.c
|
Loading…
Reference in New Issue
Block a user