summaryrefslogtreecommitdiffstats
path: root/src/js_signal_event.c
diff options
context:
space:
mode:
authorzheng_wenlong <wenlong_zheng@nexty-ele.com>2019-04-04 09:03:27 +0900
committerzheng_wenlong <wenlong_zheng@nexty-ele.com>2019-04-04 09:04:27 +0900
commitc404f25dcaa4e622a0fe9179bc79393a468093d1 (patch)
treecb53edb66a21a4463cdea12082fbd5b77a057035 /src/js_signal_event.c
parent1fed2c5a38fed8bc91bb6b8a08982303eb9c2e82 (diff)
Revert "Change steering to systemd service for ces2019"
This reverts commit 1fed2c5a38fed8bc91bb6b8a08982303eb9c2e82. Change-Id: Id83b437eef556b8d3fcd95503b9ff5b4d94bc7a5 Signed-off-by: zheng_wenlong <wenlong_zheng@nexty-ele.com>
Diffstat (limited to 'src/js_signal_event.c')
-rw-r--r--src/js_signal_event.c259
1 files changed, 85 insertions, 174 deletions
diff --git a/src/js_signal_event.c b/src/js_signal_event.c
index ad3035a..712d51c 100644
--- a/src/js_signal_event.c
+++ b/src/js_signal_event.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 TOYOTA MOTOR CORPORATION
+ * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,13 +22,20 @@
#include <string.h>
#include <sys/ioctl.h>
#include <alloca.h>
-#include <math.h>
-#include <time.h>
-#include <signal.h>
-#include "wheel-service.h"
+#include "af-steering-wheel-binding.h"
#include "js_signal_event.h"
+// Axis
+#define JS_STEERING 0
+#define JS_THROTTLE 2
+#define JS_BRAKE 3
+// Button
+#define JS_LEFT_PADDLE_SHIFTER 4
+#define JS_RIGHT_PADDLE_SHIFTER 5
+#define JS_TURN_SIGNAL_RIGHT 6
+#define JS_TURN_SIGNAL_LEFT 7
+
// Property string
#define VEHICLE_SPEED "VehicleSpeed"
#define ENGINE_SPEED "EngineSpeed"
@@ -38,89 +45,56 @@
#define STEERING_WHEEL_ANGLE "SteeringWheelAngle"
#define TURN_SIGNAL_STATUS "TurnSignalStatus"
#define LIGHT_STATUS_BRAKE "LightStatusBrake"
-#define PARKING_STATUS_BRAKE "ParkingStatusBrake"
-#define FUEL_LEVEL "FuelLevel"
#define MAX_TRANSMISSION_GEAR_INFO 6
#define MIN_TRANSMISSION_GEAR_INFO 0
-enum eJsButtonEvent {
- JS_BUTTON_X = 0,
- JS_BUTTON_R = 1,
- JS_BUTTON_O = 2,
- JS_BUTTON_T = 3,
- JS_BUTTON_R1 = 4,
- JS_BUTTON_L1 = 5,
- JS_BUTTON_R2 = 6,
- JS_BUTTON_L2 = 7,
- JS_BUTTON_SHARE = 8,
- JS_BUTTON_OPTION = 9,
- JS_BUTTON_R3 = 10,
- JS_BUTTON_L3 = 11,
- JS_BUTTON_PLUS = 19,
- JS_BUTTON_MINUS = 20,
- JS_BUTTON_SCROLL_R = 21,
- JS_BUTTON_SCROLL_L = 22,
- JS_BUTTON_ENTER = 23,
- JS_BUTTON_PS = 24
-};
-
-enum eJsAxisEvent {
- JS_AXIS_STEERING = 0,
- JS_AXIS_CLUTCH = 1,
- JS_AXIS_ACCEL = 2,
- JS_AXIS_BRAKE = 3,
-};
-
-enum eTransmissionGearInfo {
+enum eTransmissionGearInfo
+{
eTransmissionGearInfoLeft = 0,
eTransmissionGearInfoRight = 1,
};
-enum eTurnSignalStatus {
+enum eTurnSignalStatus
+{
eTurnSignalStatusOff = 0,
- eTurnSignalStatusRight = 4,
+ eTurnSignalStatusRight = 1,
eTurnSignalStatusLeft = 2,
- eTurnSignalStatusHazard = 1
+ eTurnSignalStatusHazard = 3
};
-double gearRatio[8] = {
- 0.0, //Neutral
- 1.0/4.12, //First
- 1.0/2.84, //Second
- 1.0/2.28, //Third
- 1.0/1.45, //Fourth
- 1.0/1.0, //Fifth
- 1.0/0.69, //Sixth
- 1.0/3.21 //Reverse
+double gearRatio[8] =
+{
+ 0.0, //Neutral
+ 1.0/4.12, //First
+ 1.0/2.84, //Second
+ 1.0/2.28, //Third
+ 1.0/1.45, //Fourth
+ 1.0/1.0, //Fifth
+ 1.0/0.69, //Sixth
+ 1.0/3.21 //Reverse
};
-static int gJsType=JS_TYPE_STEERING;
-static int gCurAccPedalPos=0, gAccPedalPos=0;
-static int gEngineSpeed=0;
-static int gVehicleSpeed=0;
-static float gBaseValue = 0.0;
-
+static int gAcceleratorPedalPosition = 0;
static int gLightStatusBrake = 0;
-static int gTransmissionGearInfo = 0;
+static int gTransmissionGearInfo = 1;
static int gSteeringWheelAngle = 0;
-static int gParkingStatusBrake = 0;
-static int gFuelLevel = 0;
static enum eTurnSignalStatus gTurnSignalStatus = eTurnSignalStatusOff;
-static void setLightStatusBrake(int val)
+// Method to set value
+static void setAcceleratorPedalPosition(int val)
{
- if(gLightStatusBrake != val)
+ if(gAcceleratorPedalPosition != val)
{
- gLightStatusBrake = val;
+ gAcceleratorPedalPosition = val;
}
}
-static void setFuelLevel(int val)
+static void setLightStatusBrake(int val)
{
- if(gFuelLevel != val)
+ if(gLightStatusBrake != val)
{
- gFuelLevel = val;
+ gLightStatusBrake = val;
}
}
@@ -162,10 +136,6 @@ static void setTurnSignalStatus(int val, enum eTurnSignalStatus turn)
{
gTurnSignalStatus = eTurnSignalStatusLeft;
}
- else if(turn == eTurnSignalStatusHazard)
- {
- gTurnSignalStatus = eTurnSignalStatusHazard;
- }
}
else
{
@@ -173,12 +143,27 @@ static void setTurnSignalStatus(int val, enum eTurnSignalStatus turn)
}
}
-static void setParkingStatusBrake(int val)
+// Method to calculate property
+static int calcAcceleratorPedalPosition()
{
- if(gParkingStatusBrake != val)
- {
- gParkingStatusBrake = val;
- }
+ return (int)(((double)(gAcceleratorPedalPosition - 32767)/(double)-65534.0)*(double)100.0);
+}
+
+static int calcEngineSpeed()
+{
+ int acceleratorPedalPosition = calcAcceleratorPedalPosition();
+ int engineSpeed = (int)acceleratorPedalPosition * 100;
+
+ return engineSpeed;
+}
+
+static int calcVehicleSpeed()
+{
+ int engineSpeed = calcEngineSpeed();
+ double transmissionGearInfoRatio = gearRatio[(gTransmissionGearInfo == 128 ? 7 : gTransmissionGearInfo)];
+ int vehicleSpeed = (int)(engineSpeed * transmissionGearInfoRatio / 100);
+
+ return vehicleSpeed;
}
static int calcSteeringWheelAngle()
@@ -189,7 +174,7 @@ static int calcSteeringWheelAngle()
}
// Method to update property
-static void setCanValue(char *prop, int val)
+static void updateValue(char *prop, int val)
{
unsigned int nProp = wheel_info->nData;
for(unsigned int i = 0; i < nProp; i++)
@@ -208,36 +193,38 @@ static void setCanValue(char *prop, int val)
void updateTransmissionGearInfo()
{
- setCanValue(TRANSMISSION_GEAR_INFO, 5);
+ updateValue(TRANSMISSION_GEAR_INFO, gTransmissionGearInfo);
}
void updateTransmissionMode()
{
- setCanValue(TRANSMISSION_MODE, 0);
+ updateValue(TRANSMISSION_MODE, gTransmissionGearInfo);
}
static void updateAcceleratorPedalPosition()
{
- setCanValue(ACCELERATOR_PEDAL_POSITION, gAccPedalPos);
- DBG_NOTICE("acceleratorPedalPosition : %d\n", gAccPedalPos);
+ int acceleratorPedalPosition;
+
+ acceleratorPedalPosition = calcAcceleratorPedalPosition();
+ updateValue(ACCELERATOR_PEDAL_POSITION, acceleratorPedalPosition);
}
static void updateEngineSpeed()
{
// Update EngineSpeed
- gEngineSpeed = gBaseValue*3000+1000;
- setCanValue(ENGINE_SPEED, gEngineSpeed);
- DBG_DEBUG("engineSpeed : %d\n", gEngineSpeed);
+ int engineSpeed;
+
+ engineSpeed = calcEngineSpeed();
+ updateValue(ENGINE_SPEED, engineSpeed);
}
static void updateVehicleSpeed()
{
// Update VehicleSpeed
- if(gBaseValue < 0)
- gBaseValue = 0;
- gVehicleSpeed = (int)(gBaseValue*9550/100)*100;
- setCanValue(VEHICLE_SPEED, gVehicleSpeed);
- DBG_DEBUG("vehicleSpeed : %d\n", gVehicleSpeed);
+ int vehicleSpeed;
+
+ vehicleSpeed = calcVehicleSpeed();
+ updateValue(VEHICLE_SPEED, vehicleSpeed);
}
static void updateLightStatusBrake()
@@ -245,30 +232,18 @@ static void updateLightStatusBrake()
int lightStatusBrake;
lightStatusBrake = (gLightStatusBrake < 20000);
- setCanValue(LIGHT_STATUS_BRAKE, lightStatusBrake);
-}
-
-static void updateFuelLevel()
-{
- int fuelLevel = (32511 - gFuelLevel)*256.0/65278.0;
- DBG_DEBUG("fuelLevel: %d, gFuelLevel: %d \n", fuelLevel, gFuelLevel);
- setCanValue(FUEL_LEVEL, fuelLevel);
-}
-
-static void updateParkingStatusBrake()
-{
- setCanValue(PARKING_STATUS_BRAKE, gParkingStatusBrake);
+ updateValue(LIGHT_STATUS_BRAKE, lightStatusBrake);
}
static void updateSteeringWheelAngle()
{
int steering = calcSteeringWheelAngle();
- setCanValue(STEERING_WHEEL_ANGLE, steering);
+ updateValue(STEERING_WHEEL_ANGLE, steering);
}
static void updateTurnSignalStatus()
{
- setCanValue(TURN_SIGNAL_STATUS, gTurnSignalStatus);
+ updateValue(TURN_SIGNAL_STATUS, gTurnSignalStatus);
}
// Method to handle joy stick event
@@ -276,7 +251,7 @@ void newButtonValue(char number, int val)
{
switch (number)
{
- case JS_BUTTON_R1: //Left paddle shifter
+ case JS_LEFT_PADDLE_SHIFTER: //Left paddle shifter
// Set gear position
setTransmissionGearInfo(val, eTransmissionGearInfoLeft);
@@ -286,7 +261,7 @@ void newButtonValue(char number, int val)
updateVehicleSpeed();
break;
- case JS_BUTTON_L1: //Right paddle shifter
+ case JS_RIGHT_PADDLE_SHIFTER: //Right paddle shifter
// Set gear position
setTransmissionGearInfo(val, eTransmissionGearInfoRight);
@@ -296,7 +271,7 @@ void newButtonValue(char number, int val)
updateVehicleSpeed();
break;
- case JS_BUTTON_R2: //Right upper wheel button
+ case JS_TURN_SIGNAL_RIGHT: //Right upper wheel button
// Set value
setTurnSignalStatus(val, eTurnSignalStatusRight);
@@ -304,27 +279,14 @@ void newButtonValue(char number, int val)
updateTurnSignalStatus();
break;
- case JS_BUTTON_L2: //Left upper wheel button
+ case JS_TURN_SIGNAL_LEFT: //Left upper wheel button
// Set value
setTurnSignalStatus(val, eTurnSignalStatusLeft);
// Update property
updateTurnSignalStatus();
break;
- case JS_BUTTON_R3:
- // Set value
- setTurnSignalStatus(val, eTurnSignalStatusHazard);
-
- // Update property
- updateTurnSignalStatus();
- break;
- case JS_BUTTON_L3:
- // Set value
- setParkingStatusBrake(val);
- // Update property
- updateParkingStatusBrake();
- break;
default:
break;
}
@@ -332,24 +294,9 @@ void newButtonValue(char number, int val)
void newAxisValue(char number, int val)
{
-// DBG_ERROR("#################number: %d, %d. \n", number, val);
-// DBG_ERROR("#################gJsType: %d. \n", gJsType);
- if ((JS_TYPE_GAME_CTL == gJsType) && (number == JS_AXIS_BRAKE))
- {
- number = JS_AXIS_ACCEL;
- }
- else if ((JS_TYPE_GAME_CTL == gJsType) && (number == JS_AXIS_ACCEL))
- {
- number = JS_AXIS_BRAKE;
- }
- else
- {
- //do nothing
- }
-
switch (number)
{
- case JS_AXIS_STEERING: //Wheel angle, -32767 - 32767
+ case JS_STEERING: //Wheel angle, -32767 - 32767
// Set value
setSteeringWheelAngle(val);
@@ -357,29 +304,17 @@ void newAxisValue(char number, int val)
updateSteeringWheelAngle();
break;
- case JS_AXIS_ACCEL: //Throttle, -32767 (depressed) - 32767 (undepressed)
+ case JS_THROTTLE: //Throttle, -32767 (depressed) - 32767 (undepressed)
// Set origin value
- if (JS_TYPE_GAME_CTL == gJsType)
- {
- gAccPedalPos = (int)(((double)val/(double)-32767.0)*(double)100.0);
- }
- else
- {
- gAccPedalPos = (int)(((double)(val - 32767)/(double)-65534.0)*(double)100.0);
- }
+ setAcceleratorPedalPosition(val);
// Update property
updateAcceleratorPedalPosition();
- if (gAccPedalPos > gCurAccPedalPos){
- gCurAccPedalPos = gAccPedalPos;
- gBaseValue = sin((float)gCurAccPedalPos/100.0);
-
- updateEngineSpeed();
- updateVehicleSpeed();
- }
+ updateEngineSpeed();
+ updateVehicleSpeed();
break;
- case JS_AXIS_BRAKE:
+ case JS_BRAKE:
// Set value
setLightStatusBrake(val);
@@ -387,31 +322,7 @@ void newAxisValue(char number, int val)
updateLightStatusBrake();
break; //Brake, -32767 (depressed) - 32767 (undepressed)
- case JS_AXIS_CLUTCH:
- setFuelLevel(val);
- updateFuelLevel();
- break;
default:
- DBG_DEBUG("number: %d, %d. \n", number, val);
break;
}
}
-
-void updateTimerHandler(int signum)
-{
- if (gCurAccPedalPos == gAccPedalPos){
- gCurAccPedalPos = gCurAccPedalPos + rand()%2;
- }else if (gAccPedalPos < (gCurAccPedalPos - 5)){
- gCurAccPedalPos = gCurAccPedalPos - 5;
- }else{
- gCurAccPedalPos = gAccPedalPos;
- }
- gBaseValue = sin((float)gCurAccPedalPos/100.0);
- updateEngineSpeed();
- updateVehicleSpeed();
-}
-
-void setJsType(int jstype)
-{
- gJsType = jstype;
-} \ No newline at end of file