0%

Minecraft Java 版并不支持通过手柄进行游戏,而只能够使用鼠标和键盘,这无疑是令人遗憾的。如果要用手柄玩 Minecraft,有以下几种比较简单的解决方案:

本文将介绍通过硬件方法映射的步骤。这里用到的硬件包括

  • Arduino Leonardo
  • USB Host Shield

在文章将电键变为鼠标和键盘 —— 实现篇中,笔者正是通过 Arduino Leonardo 模拟了鼠标和键盘。这里也是类似的,通过 Arduino 读取手柄的按键信息,然后转换为对应的鼠标和键盘操作,实现用手柄控制 Minecraft。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
Example sketch for the Xbox ONE USB library - by guruthree, based on work by
Kristian Lauszus.
*/

#define SENSITIVITY 4

#include <XBOXONE.h>
#include "Keyboard.h"
#include "Mouse.h"

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif
#include <SPI.h>

USB Usb;
XBOXONE Xbox(&Usb);

bool click_d = false;
bool click_a = false;
bool click_w = false;
bool click_s = false;
bool click_shift = false;

void setup() {
Serial.begin(115200);
Mouse.begin();
Keyboard.begin();
//while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
if (Usb.Init() == -1) {
Serial.print(F("\r\nOSC did not start"));
while (1); //halt
}
Serial.print(F("\r\nXBOX USB Library Started"));
}

void loop() {
Usb.Task();
if (Xbox.XboxOneConnected) {
if (Xbox.getAnalogHat(LeftHatX) > 7500 && !click_d) {
Keyboard.press('d');
click_d = true;
}
if (Xbox.getAnalogHat(LeftHatX) < -7500 && !click_a) {
Keyboard.press('a');
click_a = true;
}
else if (Xbox.getAnalogHat(LeftHatX) < 2000 && Xbox.getAnalogHat(LeftHatX) > -2000) {
if (click_d) {
Keyboard.release('d');
click_d = false;
}
if (click_a) {
Keyboard.release('a');
click_a = false;
}
}

if (Xbox.getAnalogHat(LeftHatY) > 7500 && !click_w) {
Keyboard.press('w');
click_w = true;
}
if (Xbox.getAnalogHat(LeftHatY) < -7500 && !click_s) {
Keyboard.press('s');
click_s = true;
}
else if (Xbox.getAnalogHat(LeftHatY) < 2000 && Xbox.getAnalogHat(LeftHatY) > -2000) {
if (click_s) {
Keyboard.release('s');
click_s = false;
}
if (click_w) {
Keyboard.release('w');
click_w = false;
}
}

if (Xbox.getAnalogHat(RightHatX) > 7500) {
// move mouse right
Mouse.move(SENSITIVITY, 0);
}
if (Xbox.getAnalogHat(RightHatX) < -7500) {
// move mouse left
Mouse.move(-SENSITIVITY, 0);
}

if (Xbox.getAnalogHat(RightHatY) > 7500) {
// move mouse up
Mouse.move(0, -SENSITIVITY);
}
if (Xbox.getAnalogHat(RightHatY) < -7500) {
// move mouse down
Mouse.move(0, SENSITIVITY);
}

// Set rumble effect
static uint16_t oldL2Value, oldR2Value;
if (Xbox.getButtonPress(L2) != oldL2Value || Xbox.getButtonPress(R2) != oldR2Value) {
oldL2Value = Xbox.getButtonPress(L2);
oldR2Value = Xbox.getButtonPress(R2);
uint8_t leftRumble = map(oldL2Value, 0, 1023, 0, 255); // Map the trigger values into a byte
uint8_t rightRumble = map(oldR2Value, 0, 1023, 0, 255);
}

if (Xbox.getButtonClick(UP))
Serial.println(F("Up"));
if (Xbox.getButtonClick(DOWN))
Serial.println(F("Down"));
if (Xbox.getButtonClick(LEFT))
Serial.println(F("Left"));
if (Xbox.getButtonClick(RIGHT))
Serial.println(F("Right"));

if (Xbox.getButtonClick(START)) {
Keyboard.press(KEY_ESC);
Keyboard.release(KEY_ESC);
Serial.println(F("Start"));
}
if (Xbox.getButtonClick(BACK))
Serial.println(F("Back"));
if (Xbox.getButtonClick(XBOX))
Serial.println(F("Xbox"));
if (Xbox.getButtonClick(SYNC))
Serial.println(F("Sync"));

if (Xbox.getButtonClick(L1))
Serial.println(F("L1"));
if (Xbox.getButtonClick(R1))
Serial.println(F("R1"));
if (Xbox.getButtonPress(L2) > 768 && !click_shift) {
Keyboard.press(KEY_LEFT_SHIFT);
click_shift = true;
}
else if (Xbox.getButtonPress(L2) < 256 && click_shift) {
Keyboard.release(KEY_LEFT_SHIFT);
click_shift = false;
}
if (Xbox.getButtonClick(R2))
Serial.println(F("R2"));
if (Xbox.getButtonClick(L3))
Serial.println(F("L3"));
if (Xbox.getButtonClick(R3))
Serial.println(F("R3"));

if (Xbox.getButtonPress(A)) {
Keyboard.press(0x20);
Serial.println(F("A"));
} else {
Keyboard.release(0x20);
}
if (Xbox.getButtonClick(B))
Serial.println(F("B"));
if (Xbox.getButtonClick(X)) {
Keyboard.print("/");
delay(200);
Keyboard.println("time set 0");
Serial.println(F("X"));
}
if (Xbox.getButtonClick(Y))
Serial.println(F("Y"));
}
delay(1);
}

AppImage 是一种在 Linux 系统中用于分发便携式软件的格式。但是,如果在初次安装 AppImage 程序后,移动了 AppImage 文件的位置,将导致其图标无法加载。解决方案是进入以下两个目录中:

1
2
~/.config/
~/.local/share/applications/

然后找到并删除有关的文件,例如与程序名称相关的文件夹,和 appimagekit-*.desktop
完成后重新启动程序并再次安装即可。

ESP8266 是一款非常小巧的物联网芯片,在烧录了 AT 固件后,可以通过串口传递指令,进行 Wi-Fi 连接和发起 HTTP 请求。

市面上有许多集成了 ESP8266 芯片的开发板,例如 ESP-01 或 ESP-01S。笔者使用的是 ESP-01,已经预先刷好了 AT 固件。

准备工作

要将 ESP-01 连接到电脑上,需要准备一个 USB 转 TTL 模块,其输出接口应包括 VCC,GND,TX 和 RX。值得注意的是,ESP8266 芯片的供电电压是 3.3V,如果模块输出的 VCC 是 USB 的 5V 电压,那么不能直接接上 ESP-01,否则会造成损坏。市面上也可以买到专门为 ESP-01 设计的 USB 烧录下载器,如果需要经常烧录固件,入手一个可以免去接线的烦恼。

如果没有现成的硬件,用一块 Arduino 单片机也可以代替,因为 Arduino 单片机上是有 USB 转 UART 芯片的。向 Arduino 烧录一个空程序(即 setuploop 函数都为空的程序),就可以利用单片机上的 TX 和 RX 接口与 ESP-01 进行串口通讯了。不过这时要注意供电问题,ESP-01 在连接网络时功耗会增加,Arduino Nano 的 3.3V 输出能力可能带不动,会导致 ESP-01 重启。

连接方式

ESP-01 的引脚定义如下图所示。

使用时,将 VCC 和 CH-PD 接 3.3V 高电平,GND 接地,TX 和 RX 则连接到 USB 转 TTL 的模块(或者 Arduino 单片机)的 RX 和 TX 上。

串口测试

连接好之后,ESP-01 开发板上的电源指示灯会亮起。在电脑上打开串口通讯软件,例如 Arduino IDE 自带的串口监视器。AT 固件默认的参数是:串口波特率为 115200,换行符为 NL 和 CR。

接下来,可以通过 AT+GMR 命令查看固件信息:

其它常见的 AT 命令可以参考以下文章:
ESP8266_AT Wiki
ESP8266 - AT Command Reference

Wi-Fi 连接

首先将 ESP8266 重置,然后设置为 AP + Station 模式。

1
2
3
AT+RST
AT+CWMODE=3
AT+CWLAP

最后一个 AT+CWLAP 命令将搜索附近的 Wi-Fi 并显示出来。
随后,使用 AT+CWJAP 命令,指定 SSID 和密码用于连接 Wi-Fi:

1
AT+CWJAP="ssid","pwd"

ssidpwd 根据情况替换。如果连接成功,将返回

1
2
WIFI CONNECTED
WIFI GOT IP

接下来就可以发起请求了。我们以 World Time API 为例,这个网站可以根据客户端 IP 获得时间。

阅读全文 »

Seen here is the Norwich City Council’s first computer, being delivered to the City Treasurer’s Department in Bethel Street, Norwich in 1957. The City of Norwich, and its forward-thinking Treasurer, Mr A.J. Barnard, were pioneers in the application of computer technology to the work of UK local authorities and businesses. In 1953-4, Mr Barnard and his team began looking for an electronic system to handle its rates and payroll. They began discussions with Elliott Brothers of London in 1955, and the City Council ordered the first Elliott 405 computer from them in January 1956. It was delivered to City Hall in February 1957 and became operational in April 1957. The event was celebrated by a demonstration of the machine in front of the Lord Mayor of Norwich and the press on 3 April 1957. (Norfolk Record Office, ACC 2005/170)

Below is a picture of the new $5 Raspberry Pi Zero at the same location. The Raspberry Pi is a tiny and affordable computer, designed and built in the UK, that you can use to learn programming through fun, practical projects. I own 2 older models.

Wonders never cease.


本文转载自:UK Computing: Elliott 405 (1957) vs $5 Raspberry Pi Zero (2015) by Ben Ward • Findery
图片来源:
Norfolk Record Office
BlazePress — 58 years later.