Hi,
I'm currently trying to get an Arduino to decode HEX Data that it gets thru a serial connection.
I have 2 issues.
The first issue being that it doesn't record all the data.
For exemple I'm sending this :
<FF735AFFFF748F6D80000000000000>
The arduino reads this with weird symbols at the end (or it could be my way of writing it to the serial monitor):
FF735AFFFF74808487000
I'm reading it with this Function :
void ReadSerial() {
static boolean recvInProgress = false;
static byte ndx = 0;
char startMarker = '<';
char endMarker = '>';
char rc;
while (Wemos.available() > 0 && newData == false) {
rc = Wemos.read();
if (recvInProgress == true) {
if (rc != endMarker) {
GamePadData[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
// GamePadData[ndx] = '\0'; // terminate the string
recvInProgress = false;
ndx = 0;
newData = true;
}
}
else if (rc == startMarker) {
recvInProgress = true;
}
}
}
Then i'm trying to find certain HEX codes in this hex Data
//Defining every Key hex code
#define PSB_SELECT 0x0001
#define PSB_L3 0x0002
#define PSB_R3 0x0004
#define PSB_START 0x0008
#define PSB_PAD_UP 0x0010
#define PSB_PAD_RIGHT 0x0020
#define PSB_PAD_DOWN 0x0040
#define PSB_PAD_LEFT 0x0080
#define PSB_L2 0x0100
#define PSB_R2 0x0200
#define PSB_L1 0x0400
#define PSB_R1 0x0800
#define PSB_GREEN 0x1000
#define PSB_RED 0x2000
#define PSB_BLUE 0x4000
#define PSB_PINK 0x8000
#define PSB_TRIANGLE 0x1000
#define PSB_CIRCLE 0x2000
#define PSB_CROSS 0x4000
#define PSB_SQUARE 0x8000
////These are analog buttons
//#define PSAB_PAD_RIGHT 9
//#define PSAB_PAD_UP 11
//#define PSAB_PAD_DOWN 12
//#define PSAB_PAD_LEFT 10
//#define PSAB_L2 19
//#define PSAB_R2 20
//#define PSAB_L1 17
//#define PSAB_R1 18
//#define PSAB_GREEN 13
//#define PSAB_RED 14
//#define PSAB_BLUE 15
//#define PSAB_PINK 16
//#define PSAB_TRIANGLE 13
//#define PSAB_CIRCLE 14
//#define PSAB_CROSS 15
//#define PSAB_SQUARE 16
//These are stick values
#define PSS_RX 5
#define PSS_RY 6
#define PSS_LX 7
#define PSS_LY 8
unsigned char GamePadData[21] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; //where Hex Values are stored.
boolean Button(uint16_t button) { //IF button is pressed then Button(PSB_Key) is true.
return ((~buttons & button) > 0);
}
buttons = (uint16_t)(GamePadData[4] << 8) + GamePadData[3];
Is this the "right way" of doing it ?
Thanks a lot.
I've been struggling with this for a full week now, and don't get it. I struggle with data types and serial.
