Skip to content

Commit 6588d4d

Browse files
committed
update readme.md and readme.zh.md
1 parent 5d90f6c commit 6588d4d

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

Readme.md

+12-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
## Statement
44

5-
### This is a joy library for Atmega32UX chip with force feedback, which can be used to make game handle with vibration, game steering wheel with force feedback, etc. (equipment requiring multi axis force feedback, such as flight rocker, is not supported temporarily, and will be updated later,maybe this week).
5+
### This is a joy library for Atmega32UX chip with force feedback, which can be used to make game handle with vibration, game steering wheel with force feedback, etc.Multi-axis-force-feedback feature is added.
66

77

88
## Usage
9+
10+
### 0. example:`examples/JoystickWithFFB/JoystickWithFFB.ino`
11+
912
### 1. create `JoyStick` object
1013

1114
| params | describe |
@@ -94,13 +97,17 @@
9497

9598
### 4.Finally,get the force value with
9699

97-
`JoyStick.getForce()`
100+
`JoyStick.getForce(int32_t* forces)`
98101

99-
return type `int32`
102+
params `int32_t* forces` is an `int32` array of length 2
100103

101-
range`[-255,255]`
104+
`forces[0]` is the X-Axis force data
102105

103-
only one axis is supported;
106+
`forces[1]` is the Y-Axis force data
107+
108+
return type `void`
109+
110+
range`[-255,255]`
104111

105112
## Ref
106113

Readme.zh.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22

33
## 声明
44

5-
### 这是一个适用于Atmega32UX芯片带力反馈的Joystick库,可用于制作带震动的游戏手柄、带力反馈的游戏方向盘等(飞行摇杆等需要多轴力反馈的设备暂时不支持,后续更新)
5+
### 这是一个适用于Atmega32UX芯片带力反馈的Joystick库,可用于制作带震动的游戏手柄、带力反馈的游戏方向盘等。支持两轴力反馈
66

77

88
## 用法
9+
10+
### 0.例程:`examples/JoystickWithFFB/JoystickWithFFB.ino`
11+
912
### 1. 创建JoyStick对象
1013

1114
| 参数表 | 描述 |
@@ -96,7 +99,9 @@
9699
#### 8)设置摩擦力最大位置差参数
97100
` JoyStick.setFrictionMaxPositionChange(int32_t value);`
98101

99-
### 4.通过:`JoyStick.getForce()`获取计算好的力,返回值范围`[-255,255]`,目前仅支持单轴;
102+
### 4.通过:`JoyStick.getForce(int32_t* forces)`获取计算好的力
103+
104+
#### 传入参数为一个长度为2的int32_t数组,输出范围`[-255,255]`
100105

101106
## 引用
102107

examples/JoystickWithFFB/JoystickWithFFB.ino

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#include "Joystick.h"
2+
3+
int32_t forces[2] = { 0 };
4+
25
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID,JOYSTICK_TYPE_JOYSTICK,
36
8, 0, // Button Count, Hat Switch Count
47
true, true, false, // X and Y, but no Z Axis
@@ -29,6 +32,9 @@ void loop(){
2932
Joystick.setSpringPosition(0);
3033
Joystick.setSpringMaxPosition(180);
3134
//Get Force [-255,255] you can set PWM with this value
32-
int32_t force = Joystick.getForce();
33-
Serial.println(force);
35+
Joystick.getForce(forces);
36+
Serial.print("XF: ");
37+
Serial.print(forces[0]);
38+
Serial.print(" YF: ");
39+
Serial.println(forces[1]);
3440
}

src/Joystick.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ void Joystick_::ApplyDirection(volatile TEffectState& effect, int32_t force, int
750750
{
751751
float angle = (directionX * 360.0 / 255.0) * DEG_TO_RAD;
752752
forces[0] += (int32_t)(sin(angle) * force);
753-
forces[1] += (int32_t)(cos(angle) * force);
753+
forces[1] += (int32_t)(-1 * cos(angle) * force);
754754
}
755755
else
756756
{
@@ -762,7 +762,7 @@ void Joystick_::ApplyDirection(volatile TEffectState& effect, int32_t force, int
762762
if (effect.enableAxis & Y_AXIS_ENABLE)
763763
{
764764
float angle = (directionY * 360.0 / 255.0) * DEG_TO_RAD;
765-
forces[1] += (int32_t)(cos(angle) * force);
765+
forces[1] += (int32_t)(-1 * cos(angle) * force);
766766
}
767767
}
768768
}

0 commit comments

Comments
 (0)