编辑:它有效!我遇到另一个问题,说它无法为Uno编译,但我已将其修复并且可以正常工作!
我正在尝试使用arduino uno r3从PS2控制器制作Vjoy串行进纸器。 我的代码上出现“ ibus不能命名类型”错误(必须写得不好),我也不知道要寻找什么。 我为此使用2个库: ps2x:https://github.com/madsci1016/Arduino-PS2X,以从ps2控制器获取输入
VjoySerialFeeder:https://github.com/Cleric-K/vJoySerialFeeder,用于将这些输入通过串行发送到供料器应用程序上,以模拟PC的工作控制器。
问题似乎出在VjoySerialFeeder及其IBus类中。
这是我的代码:
#include <PS2X_lib.h> // Bill Porter's PS2 Library
#include <ibus.h>
// //////////////////
// Edit here to customize
// How often to send data?
#define UPDATE_INTERVAL 10 // milliseconds
// 1. Analog channels. Data can be read with the Arduino's 10-bit ADC.
// This gives values from 0 to 1023.
// Specify below the analog pin numbers (as for analogRead) you would like to use.
// Every analog input is sent as a single channel.
#define NUM_ANALOG_INPUTS 4
byte analogPins[] = {0, 1, 2, 3}; // element count MUST be == NUM_ANALOG_INPUTS
// 2. Digital channels. Data can be read from Arduino's digital pins.
// They could be either LOW or HIGH.
// Specify below the digital pin numbers (as for digitalRead) you would like to use.
// Every pin is sent as a single channel. LOW is encoded as 0, HIGH - as 1023
// 3. Digital bit-mapped channels. Sending a single binary state as a 16-bit
// channel is pretty wasteful. Instead, we can encode one digital input
// in each of the 16 channel bits.
// Specify below the digital pins (as for digitalRead) you would like to send as
// bitmapped channel data. Data will be automatically organized in channels.
// The first 16 pins will go in one channel (the first pin goes into the LSB of the channel).
// The next 16 pins go in another channel and so on
// LOW pins are encoded as 0 bit, HIGH - as 1.
// Define the appropriate analog reference source. See
// https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/
#define ANALOG_REFERENCE DEFAULT
// Define the baud rate
#define BAUD_RATE 115200
// /////////////////
#define NUM_CHANNELS ( (NUM_ANALOG_INPUTS) )
PS2X ps2x; //The PS2 Controller Class
#define PS2_DAT 8 //14
#define PS2_CMD 11 //15
#define PS2_SEL 10 //16
#define PS2_CLK 12 //17
void setup()
{
ps2x.config_gamepad(PS2_CLK, PS2_CMD, PS2_SEL, PS2_DAT, false, false);
analogReference(ANALOG_REFERENCE); // use the defined ADC reference voltage source
Serial.begin(BAUD_RATE); // setup serial
}
IBus ibus(NUM_CHANNELS);
void loop()
{
int i, bm_ch = 0;
unsigned long time = millis();
ps2x.read_gamepad(); //This needs to be called at least once a second
int PlyStn[] = {ps2x.Analog(PSS_RY), ps2x.Analog(PSS_RX), ps2x.Analog(PSS_LY), ps2x.Analog(PSS_LX)}; //Left Stick Left and Right
ibus.begin();
// read analog pins - one per channel
for (i = 0; i < NUM_ANALOG_INPUTS; i++)
ibus.write(analogRead(PlyStn[i]));
// read digital pins - one per channel
// read digital bit-mapped pins - 16 pins go in one channel
}
ibus.end();
time = millis() - time; // time elapsed in reading the inputs
if (time < UPDATE_INTERVAL)
// sleep till it is time for the next update
delay(UPDATE_INTERVAL - time);
}
这是ibus.cpp
#include "Arduino.h"
#include "ibus.h"
/*
* See IbusReader.cs for details about the IBUS protocol
*/
#define COMMAND40 0x40
IBus::IBus(int numChannels) {
len = 4 + numChannels*2;
}
void IBus::begin() {
checksum = 0xffff - len - COMMAND40;
Serial.write(len);
Serial.write(COMMAND40);
}
void IBus::end() {
// write checksum
Serial.write(checksum & 0xff);
Serial.write(checksum >> 8);
}
/*
* Write 16bit value in little endian format and update checksum
*/
void IBus::write(unsigned short val) {
byte b = val & 0xff;
Serial.write(b);
checksum -= b;
b = val >> 8;
Serial.write(b);
checksum -= b;
}
和ibus.h:
#pragma once
class IBus {
private:
int len;
int checksum;
public:
IBus(int numChannels);
void begin();
void end();
void write(unsigned short);
};
如果您知道此错误可能来自何处,对不起,如果这是一个简单的解决方案,那么我真的迷失了。
非常感谢。