#include "j1939_joystick.h"
int16_t J1939_Pgn64982( uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV);
static uint16_t uwAxis_X_ValueS;
static uint16_t uwAxis_X_Neutral_MinS;
static uint16_t uwAxis_X_Neutral_MaxS;
static uint16_t uwAxis_Y_ValueS;
static uint16_t uwAxis_Y_Neutral_MinS;
static uint16_t uwAxis_Y_Neutral_MaxS;
static uint8_t ubButtonGrp1S = J1939_UNUSED_UINT8;
static uint8_t ubButtonGrp2S = J1939_UNUSED_UINT8;
static uint8_t ubButtonGrp3S = J1939_UNUSED_UINT8;
(uint32_t) 64982,
(uint16_t) 100,
(uint16_t) 0,
(uint8_t) 0x00,
(uint8_t) 0x00,
(uint16_t) 0x0008,
J1939_Pgn64982
},
{ (uint16_t) 0xFFFF, 0, 0, 0, 0, 0, 0, CPP_NULL }
};
void J1939_JoystickSetButton(uint8_t ubButtonV, uint8_t ubStateV)
{
uint8_t ubButtonMaskT;
uint8_t ubButtonValueT;
switch(ubButtonV)
{
case eJ1939_JOYSTICK_BUTTON_1:
ubButtonMaskT = (uint8_t) 0x3F;
ubStateV <<= 6;
ubButtonValueT = ubStateV;
ubButtonGrp1S = ubButtonGrp1S & ubButtonMaskT;
ubButtonGrp1S = ubButtonGrp1S | ubButtonValueT;
break;
case eJ1939_JOYSTICK_BUTTON_2:
ubButtonMaskT = (uint8_t) 0xCF;
ubStateV <<= 4;
ubButtonValueT = ubStateV;
ubButtonGrp1S = ubButtonGrp1S & ubButtonMaskT;
ubButtonGrp1S = ubButtonGrp1S | ubButtonValueT;
break;
case eJ1939_JOYSTICK_BUTTON_3:
ubButtonMaskT = (uint8_t) 0xF3;
ubStateV <<= 2;
ubButtonValueT = ubStateV;
ubButtonGrp1S = ubButtonGrp1S & ubButtonMaskT;
ubButtonGrp1S = ubButtonGrp1S | ubButtonValueT;
break;
case eJ1939_JOYSTICK_BUTTON_4:
ubButtonMaskT = (uint8_t) 0xFC;
ubButtonValueT = ubStateV;
ubButtonGrp1S = ubButtonGrp1S & ubButtonMaskT;
ubButtonGrp1S = ubButtonGrp1S | ubButtonValueT;
break;
case eJ1939_JOYSTICK_BUTTON_5:
ubButtonMaskT = (uint8_t) 0x3F;
ubStateV <<= 6;
ubButtonValueT = ubStateV;
ubButtonGrp2S = ubButtonGrp2S & ubButtonMaskT;
ubButtonGrp2S = ubButtonGrp2S | ubButtonValueT;
break;
case eJ1939_JOYSTICK_BUTTON_6:
ubButtonMaskT = (uint8_t) 0xCF;
ubStateV <<= 4;
ubButtonValueT = ubStateV;
ubButtonGrp2S = ubButtonGrp2S & ubButtonMaskT;
ubButtonGrp2S = ubButtonGrp2S | ubButtonValueT;
break;
case eJ1939_JOYSTICK_BUTTON_7:
ubButtonMaskT = (uint8_t) 0xF3;
ubStateV <<= 2;
ubButtonValueT = ubStateV;
ubButtonGrp2S = ubButtonGrp2S & ubButtonMaskT;
ubButtonGrp2S = ubButtonGrp2S | ubButtonValueT;
break;
case eJ1939_JOYSTICK_BUTTON_8:
ubButtonMaskT = (uint8_t) 0xFC;
ubButtonValueT = ubStateV;
ubButtonGrp2S = ubButtonGrp2S & ubButtonMaskT;
ubButtonGrp2S = ubButtonGrp2S | ubButtonValueT;
break;
case eJ1939_JOYSTICK_BUTTON_9:
ubButtonMaskT = (uint8_t) 0x3F;
ubStateV <<= 6;
ubButtonValueT = ubStateV;
ubButtonGrp3S = ubButtonGrp3S & ubButtonMaskT;
ubButtonGrp3S = ubButtonGrp3S | ubButtonValueT;
break;
case eJ1939_JOYSTICK_BUTTON_10:
ubButtonMaskT = (uint8_t) 0xCF;
ubStateV <<= 4;
ubButtonValueT = ubStateV;
ubButtonGrp3S = ubButtonGrp3S & ubButtonMaskT;
ubButtonGrp3S = ubButtonGrp3S | ubButtonValueT;
break;
case eJ1939_JOYSTICK_BUTTON_11:
ubButtonMaskT = (uint8_t) 0xF3;
ubStateV <<= 2;
ubButtonValueT = ubStateV;
ubButtonGrp3S = ubButtonGrp3S & ubButtonMaskT;
ubButtonGrp3S = ubButtonGrp3S | ubButtonValueT;
break;
case eJ1939_JOYSTICK_BUTTON_12:
ubButtonMaskT = (uint8_t) 0xFC;
ubButtonValueT = ubStateV;
ubButtonGrp3S = ubButtonGrp3S & ubButtonMaskT;
ubButtonGrp3S = ubButtonGrp3S | ubButtonValueT;
break;
default:
break;
}
}
void J1939_JoystickSetNeutralRange( uint8_t ubAxisV, uint16_t uwMinValueV, uint16_t uwMaxValueV)
{
switch(ubAxisV)
{
case eJ1939_JOYSTICK_AXIS_X:
uwAxis_X_Neutral_MinS = uwMinValueV;
uwAxis_X_Neutral_MaxS = uwMaxValueV;
break;
case eJ1939_JOYSTICK_AXIS_Y:
uwAxis_Y_Neutral_MinS = uwMinValueV;
uwAxis_Y_Neutral_MaxS = uwMaxValueV;
break;
default:
break;
}
}
void J1939_JoystickSetValue(uint8_t ubAxisV, uint16_t uwValueV)
{
uint16_t uwAxisValueT = 0;
if (uwValueV > (uint16_t) 1022)
{
uwValueV = (uint16_t) 1022;
}
uwAxisValueT = uwValueV & (uint16_t) 0x03FF;
uwAxisValueT <<= 6;
uwAxisValueT = uwAxisValueT | (uint16_t) 0x0001;
switch(ubAxisV)
{
case eJ1939_JOYSTICK_AXIS_X:
if(uwValueV < uwAxis_X_Neutral_MinS)
{
uwAxisValueT &= (uint16_t) 0xFFC0;
uwAxisValueT |= (uint16_t) 0x0004;
}
if(uwValueV > uwAxis_X_Neutral_MaxS)
{
uwAxisValueT &= (uint16_t) 0xFFC0;
uwAxisValueT |= (uint16_t) 0x0010;
}
uwAxis_X_ValueS = uwAxisValueT;
break;
case eJ1939_JOYSTICK_AXIS_Y:
if(uwValueV < uwAxis_Y_Neutral_MinS)
{
uwAxisValueT &= (uint16_t) 0xFFC0;
uwAxisValueT |= (uint16_t) 0x0004;
}
if(uwValueV > uwAxis_Y_Neutral_MaxS)
{
uwAxisValueT &= (uint16_t) 0xFFC0;
uwAxisValueT |= (uint16_t) 0x0010;
}
uwAxis_Y_ValueS = uwAxisValueT;
break;
default:
break;
}
}
int16_t J1939_Pgn64982(uint8_t * pubDataV, uint16_t uwSizeV, uint8_t ubSrcAddrV, uint8_t ubNetV)
{
J1939_Payload_ts *ptsPayloadT = (J1939_Payload_ts *) pubDataV;
(void) uwSizeV;
(void) ubSrcAddrV;
(void) ubNetV;
ptsPayloadT->aubByte[0] = (uint8_t) uwAxis_X_ValueS;
ptsPayloadT->aubByte[1] = (uint8_t) (uwAxis_X_ValueS >> 8);
ptsPayloadT->aubByte[2] = (uint8_t) uwAxis_Y_ValueS;
ptsPayloadT->aubByte[3] = (uint8_t) (uwAxis_Y_ValueS >> 8);
ptsPayloadT->aubByte[4] = J1939_UNUSED_UINT8;
ptsPayloadT->aubByte[5] = ubButtonGrp1S;
ptsPayloadT->aubByte[6] = ubButtonGrp2S;
ptsPayloadT->aubByte[7] = ubButtonGrp3S;
}
{
{
uwAxis_X_ValueS = (uint16_t) 500;
uwAxis_X_Neutral_MinS = (uint16_t) 490;
uwAxis_X_Neutral_MaxS = (uint16_t) 510;
uwAxis_Y_ValueS = (uint16_t) 500;
uwAxis_Y_Neutral_MinS = (uint16_t) 490;
uwAxis_Y_Neutral_MaxS = (uint16_t) 510;
}
}
#define J1939_MSG_TRM
Definition j1939_defs.h:257
#define J1939_PRIORITY_CTRL
Definition j1939_defs.h:222
@ eJ1939_NET_1
Definition j1939_defs.h:117
@ eJ1939_HANDLER_RESULT_OK
Definition j1939_defs.h:515
J1939_PGN_Entry_ts atsPgnListJoystick[]
J1939 Identifier calculation functions .
void J1939_PgnListUserInit(uint8_t ubNetV)
Manage a single PGN.
Definition j1939_defs.h:572