【问题标题】:rn-42 bluesmirf HID not sending scancodes?rn-42 bluesmirf HID 不发送扫描码?
【发布时间】:2013-03-06 16:53:31
【问题描述】:

我正在尝试使用带有蓝牙 HID 模块 (bluesmirf) 的 arduino 来控制我的 Galaxy 标签上的音量。我有 arduino 设置,所以我按下一个连接的小按钮,它就像键盘一样将 ascii 文本发送到平板电脑,这工作正常。我想为这个“蓝牙键盘”创建一个自定义键盘布局文件,这样当平板电脑通过蓝牙接收来自 arduino 的按键时,它将控制适当的项目,如音量、静音等。但是,当使用 keytest 来从蓝牙模块捕获传入的按钮按下,扫描码始终为 0。Keytest 正在读取密钥并在发送 A 时将其显示为 keycode_a(例如),但该键的扫描码始终为 0 而不是唯一的标识符。奇怪的是,arduino 自动在 serial.println 命令(我用来发送按钮按下蓝牙的命令)末尾的回车正确显示为 ENTER 并且确实有扫描码。

我不明白。我一定是做错了什么,但我还是新手/正在学习,所以我一定会错过它。如果没有扫描码供平板电脑查看,我无法设置自定义键盘布局来执行我想要的操作。

如有必要,我可以发布我的 arduino 代码。非常感谢任何和所有帮助。我非常接近完成我需要的东西,这让我发疯。

编辑 - 代码如下:

// test code for sending keystrokes from arduino
// to computer via HID bluetooth module
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);     
// initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);   
// begin serial communication at 115200 baud rate 
  Serial.begin(115200);
}
void loop() {
// read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH,
  //the LED turns on, and the line is printed via bluetooth.
  if (buttonState == HIGH) {   
    digitalWrite(ledPin, HIGH); // turn LED on:
    Serial.println("A"); // write the line via bluetooth
    delay(1000); // delay one second 
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  } 

}

所以在上面的代码中,Serial.println("A");发送到平板电脑,我可以在文本编辑器中看到打印的 A。平板电脑看到在 keytest 应用程序中按下了 A,但它显示扫描码为 0。由于某种原因,发送的每个字符都显示为 0,除了草图在 Serial.println 之后抛出的自动回车。我什至尝试使用 Serial.print 代替,因为它不会抛出回车,而且我也得到了相同的扫描码 0。

【问题讨论】:

  • 您的 arduino 代码会有所帮助,同时发布您在 Android 端使用的代码也会有所帮助。
  • 我编辑了原始帖子以包含 arduino 代码。我没有在 android 端使用任何代码。这个想法是,使用扫描码,我可以编写一个键盘布局文件,或者修改一个默认的布局文件,它基本上只是一个文本文件,上面写着“当收到带有这个扫描码的键时,就执行这个操作”。就像制作自定义键盘快捷键一样。
  • 您能发布一个指向您拥有的 bluesmirf 模块的链接吗?有一些,它们的工作方式略有不同 IIRC。您还可以发布您在 android 端看到的输出吗?就像您在哪里看到它以 keycode_a 和 ENTER 以及它们各自的扫描码(或缺少扫描码)返回?
  • 这是我的模块sparkfun.com/products/10938。 android 端的输出是通过一个名为 keytest 的应用程序看到的,它只在屏幕上显示按键及其标识符(键码、扫描码等)github.com/chrisboyle/keytest/downloads

标签: android bluetooth arduino hid scancodes


【解决方案1】:

不要从 Arduino 发送它,而是先通过 Cool-Term 尝试它,具有 3ms 的字符间和 3ms 的数据包间延迟。在行结尾只使用 0D 而不是 0D 0A 在发送任何内容之前请注意,您的 BlueSMiRF 应该处于 HID 模式,我在上面发布的代码中看不到该部分。对于 HID 模式,您应该从很酷的术语中执行以下操作 $$$ (CR) S~,6 (CR) R,1 (CR) $$$ 现在红色 LED 应该会快速闪烁,连接您的手机,然后从很酷的期限发送 A(回车),您应该会直接在手机上收到它。

享受吧!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-21
    • 2018-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-11
    • 2018-04-18
    相关资源
    最近更新 更多