#include <Mouse.h>
#include <Keyboard.h>
#include <IRLib.h>
#include <IRLibMatch.h>
#include <IRLibRData.h>
#include <IRLibTimer.h>
#include <TAH.h>
TAH myTAH;
int mode, joyX, joyY, dPad, Buttonpadtag;
char val; // Store Value of Buttonpadtag
char mem = ' '; // Store Value of Buttonpadtag till getting new Value
void setup()
{
Keyboard.begin();
Mouse.begin();
Keyboard.releaseAll();
Serial.begin(9600);
myTAH.begin(9600);
myTAH.enterCommandMode();
myTAH.setName("Play");
myTAH.setWorkRole(SLAVE);
myTAH.setAuth(OPEN);
myTAH.setWorkMode(REMOTE_CONTROL);
myTAH.setiBeaconMode(ON);
myTAH.exitCommandMode();
}
void loop()
{
// if there's any serial available, read it:
if (myTAH.available())
{
///// Parsing Value From Left Controller
mode = myTAH.parseInt();
joyX = myTAH.parseInt();
joyY = myTAH.parseInt();
dPad = myTAH.parseInt();
Buttonpadtag = myTAH.parseInt();
// joystick value mapping
joyX = map(joyX, -128,128, 0, 255);
joyY = map(joyY, 128, -128, 0, 255);
// look for the newline. That's the end of your
// sentence:
if (myTAH.read() == 'P')
{
if(mode == 0) // App is in PS mode
{
// Always be getting fresh data
dataForController_t SonycontrollerData = SonygetControllerData();
// Then send out the data over the USB connection
// Joystick.set(controllerData) also works.
Joystick.setControllerData(SonycontrollerData);
}
else if(mode == 1) // App is in Computer Joystick Mode
{
///////// Button Pad mapped to User Defined Computer Keys ////////////
if(Buttonpadtag >> 0 && Buttonpadtag != 5 && Buttonpadtag != 6)
{
val = Buttonpadtag;
mem = val;
Keyboard.press(val);
}
else
{
val = mem;
Keyboard.release(val);
}
if(Buttonpadtag == 5)
{
Keyboard.press(KEY_ESC);
}
else
{
Keyboard.release(KEY_ESC);
}
if(Buttonpadtag == 6)
{
Mouse.press(MOUSE_LEFT);
}
else
{
Mouse.release(MOUSE_LEFT);
}
//////////////////////////////////////////////////////////////////////
///////// dPad mapped to Computer Arrow Keys ////////////
if(dPad == 2 )
{
Keyboard.press(KEY_UP_ARROW);
Keyboard.release(KEY_DOWN_ARROW);
Keyboard.release(KEY_RIGHT_ARROW);
Keyboard.release(KEY_LEFT_ARROW);
}
if(dPad == 8 )
{
Keyboard.press(KEY_DOWN_ARROW);
Keyboard.release(KEY_UP_ARROW);
Keyboard.release(KEY_RIGHT_ARROW);
Keyboard.release(KEY_LEFT_ARROW);
}
if(dPad == 6 )
{
Keyboard.press(KEY_RIGHT_ARROW);
Keyboard.release(KEY_UP_ARROW);
Keyboard.release(KEY_DOWN_ARROW);
Keyboard.release(KEY_LEFT_ARROW);
}
if(dPad == 4 )
{
Keyboard.press(KEY_LEFT_ARROW);
Keyboard.release(KEY_UP_ARROW);
Keyboard.release(KEY_DOWN_ARROW);
Keyboard.release(KEY_RIGHT_ARROW);
}
if(dPad == 3 )
{
Keyboard.press(KEY_UP_ARROW);
Keyboard.press(KEY_RIGHT_ARROW);
Keyboard.release(KEY_DOWN_ARROW);
Keyboard.release(KEY_LEFT_ARROW);
}
if(dPad == 9 )
{
Keyboard.press(KEY_DOWN_ARROW);
Keyboard.press(KEY_RIGHT_ARROW);
Keyboard.release(KEY_UP_ARROW);
Keyboard.release(KEY_LEFT_ARROW);
}
if(dPad == 7 )
{
Keyboard.press(KEY_DOWN_ARROW);
Keyboard.press(KEY_LEFT_ARROW);
Keyboard.release(KEY_UP_ARROW);
Keyboard.release(KEY_RIGHT_ARROW);
}
if(dPad == 1 )
{
Keyboard.press(KEY_UP_ARROW);
Keyboard.press(KEY_LEFT_ARROW);
Keyboard.release(KEY_DOWN_ARROW);
Keyboard.release(KEY_RIGHT_ARROW);
}
if(dPad == 5)
{
Keyboard.release(KEY_UP_ARROW);
Keyboard.release(KEY_DOWN_ARROW);
Keyboard.release(KEY_RIGHT_ARROW);
Keyboard.release(KEY_LEFT_ARROW);
}
//////////////////////////////////////////////////////////////////////
}
//print the three numbers in one string as hexadecimal:
Serial.print(mode, DEC);
Serial.print(",");
Serial.print(joyX, DEC);
Serial.print(",");
Serial.print(joyY, DEC);
Serial.print(",");
Serial.print(dPad, DEC);
Serial.print(",");
Serial.println(Buttonpadtag, DEC);
Serial.flush();
}
}
}
我在Git上追寻这段代码,然后按照规定进行设置,它在编译器中给出了一个错误的回调函数(
dataForController_t
)到一个预先指定给其他数据的内存分配。斜线文字注释应该解释得比较清楚,是开发者留在那里的。虽然我的社区资源远没有那么多,但在编码方面,我还是一个正在努力的人。虽然我需要更多的帮助,但我认为我还没有准备好去编码一本书。
从这个草图中的函数和方法的其他代码例子来看,我在两个函数之间加了一个句号,看看能不能有一手。没有给出其他结果。
///////////// Play Station Data Structure /////////////
原文写成 dataForController_t SonygetControllerData(void)
错误来自于给出的语法:dataForController_t SonygetControllerData(void)后面的 "错误"'dataForController_t'没有命名一个类型。
当中间的句号插入如图所示时,同样的错误持续存在。没有尝试更多的东西。
dataForController_t.SonygetControllerData(void)
{
// Set up a place for our controller data
// Use the getBlankDataForController() function, since
// just declaring a fresh dataForController_t tends
// to get you one filled with junk from other, random
// values that were in those memory locations before
dataForController_t controllerData = getBlankDataForController();
// Since our buttons are all held high and
// pulled low when pressed, we use the "!"
// operator to invert the readings from the pins
if(Buttonpadtag == 1)
{
controllerData.crossOn = 1;
Serial.println(" Cross");
}
else if(Buttonpadtag == 2)
{
controllerData.circleOn = 1;
Serial.println(" Circle");
}
else if(Buttonpadtag == 3)
{
controllerData.squareOn = 1;
Serial.println(" Square");
}
else if(Buttonpadtag == 4 )
{
controllerData.triangleOn = 1;
Serial.println(" Triangle");
}
else if(Buttonpadtag == 7 )
{
controllerData.selectOn = 1;
Serial.println(" Select");
}
else if(Buttonpadtag == 8 )
{
controllerData.startOn = 1;
Serial.println(" Start");
}
// Set the analog sticks
controllerData.leftStickX = joyX;
controllerData.leftStickY = joyY;
// And return the data!
return controllerData;
}
你正在使用的库是一个不完整的版本(也是WIP)。首先复制原始库 从此 你会发现缺少的IRxx.libs。然后你必须自己定义dataForController_t结构,因此在 本例程序PS3:
int16_t LeftjoyX;
int16_t LeftjoyY;
int16_t RightjoyX;
int16_t RightjoyY;
int16_t Buttonpadtag;
struct dataForController_t {
int16_t leftStickX;
int16_t leftStickY;
int16_t rightStickX;
int16_t rightStickY;
bool dpadRightOn;
bool dpadLeftOn;
bool dpadUpOn;
bool dpadDownOn;
bool triangleOn;
bool squareOn;
bool circleOn;
bool crossOn;
bool l1On;
bool l2On;
bool r1On;
bool r2On;
bool selectOn;
bool startOn ;
bool homeOn ;
} controllerData;
注释这句话
/Joystick.setControllerData(SonycontrollerData),并添加函数。
dataForController_t getBlankDataForController() {
// Has to be written WIP - JUST DUMMY DATA
controllerData.leftStickX = 0;
controllerData.leftStickY = 0;
controllerData.rightStickX = 0;
controllerData.rightStickY = 0;
// And return the data!
return controllerData;
}
最后一个必须用定义的结构中的所有变量来填充,并将它们设置为0。我怀疑它是否能正常工作,因为 自由基 是2015年留给公众的一个半成品。所以,要么自己完成,要么忘记使用。