summaryrefslogtreecommitdiffstats
path: root/src/js_signal_event.c
diff options
context:
space:
mode:
authorzheng_wenlong <wenlong_zheng@nexty-ele.com>2019-02-06 17:12:28 +0900
committerzheng_wenlong <wenlong_zheng@nexty-ele.com>2019-02-06 17:13:49 +0900
commit1fed2c5a38fed8bc91bb6b8a08982303eb9c2e82 (patch)
tree502b5c63a0570d78863311fbd930f1c96b8a2990 /src/js_signal_event.c
parenta98fcb4b99e5a7b14b671e6014ea0b1cc1ea199d (diff)
Change steering to systemd service for ces2019halibut_7.90.0halibut/7.90.07.90.0
Change steering to systemd service for ces2019 Change-Id: I319fb56a302f4f980b43a1b90dee1f36820355fb 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, 174 insertions, 85 deletions
diff --git a/src/js_signal_event.c b/src/js_signal_event.c
index 712d51c..ad3035a 100644
--- a/src/js_signal_event.c
+++ b/src/js_signal_event.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017 TOYOTA MOTOR CORPORATION
+ * Copyright (c) 2017-2019 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,20 +22,13 @@
#include <string.h>
#include <sys/ioctl.h>
#include <alloca.h>
+#include <math.h>
+#include <time.h>
+#include <signal.h>
-#include "af-steering-wheel-binding.h"
+#include "wheel-service.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"
@@ -45,56 +38,89 @@
#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 eTransmissionGearInfo
-{
+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 {
eTransmissionGearInfoLeft = 0,
eTransmissionGearInfoRight = 1,
};
-enum eTurnSignalStatus
-{
+enum eTurnSignalStatus {
eTurnSignalStatusOff = 0,
- eTurnSignalStatusRight = 1,
+ eTurnSignalStatusRight = 4,
eTurnSignalStatusLeft = 2,
- eTurnSignalStatusHazard = 3
+ eTurnSignalStatusHazard = 1
};
-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 gAcceleratorPedalPosition = 0;
+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 gLightStatusBrake = 0;
-static int gTransmissionGearInfo = 1;
+static int gTransmissionGearInfo = 0;
static int gSteeringWheelAngle = 0;
+static int gParkingStatusBrake = 0;
+static int gFuelLevel = 0;
static enum eTurnSignalStatus gTurnSignalStatus = eTurnSignalStatusOff;
-// Method to set value
-static void setAcceleratorPedalPosition(int val)
+static void setLightStatusBrake(int val)
{
- if(gAcceleratorPedalPosition != val)
+ if(gLightStatusBrake != val)
{
- gAcceleratorPedalPosition = val;
+ gLightStatusBrake = val;
}
}
-static void setLightStatusBrake(int val)
+static void setFuelLevel(int val)
{
- if(gLightStatusBrake != val)
+ if(gFuelLevel != val)
{
- gLightStatusBrake = val;
+ gFuelLevel = val;
}
}
@@ -136,6 +162,10 @@ static void setTurnSignalStatus(int val, enum eTurnSignalStatus turn)
{
gTurnSignalStatus = eTurnSignalStatusLeft;
}
+ else if(turn == eTurnSignalStatusHazard)
+ {
+ gTurnSignalStatus = eTurnSignalStatusHazard;
+ }
}
else
{
@@ -143,27 +173,12 @@ static void setTurnSignalStatus(int val, enum eTurnSignalStatus turn)
}
}
-// Method to calculate property
-static int calcAcceleratorPedalPosition()
+static void setParkingStatusBrake(int 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;
+ if(gParkingStatusBrake != val)
+ {
+ gParkingStatusBrake = val;
+ }
}
static int calcSteeringWheelAngle()
@@ -174,7 +189,7 @@ static int calcSteeringWheelAngle()
}
// Method to update property
-static void updateValue(char *prop, int val)
+static void setCanValue(char *prop, int val)
{
unsigned int nProp = wheel_info->nData;
for(unsigned int i = 0; i < nProp; i++)
@@ -193,38 +208,36 @@ static void updateValue(char *prop, int val)
void updateTransmissionGearInfo()
{
- updateValue(TRANSMISSION_GEAR_INFO, gTransmissionGearInfo);
+ setCanValue(TRANSMISSION_GEAR_INFO, 5);
}
void updateTransmissionMode()
{
- updateValue(TRANSMISSION_MODE, gTransmissionGearInfo);
+ setCanValue(TRANSMISSION_MODE, 0);
}
static void updateAcceleratorPedalPosition()
{
- int acceleratorPedalPosition;
-
- acceleratorPedalPosition = calcAcceleratorPedalPosition();
- updateValue(ACCELERATOR_PEDAL_POSITION, acceleratorPedalPosition);
+ setCanValue(ACCELERATOR_PEDAL_POSITION, gAccPedalPos);
+ DBG_NOTICE("acceleratorPedalPosition : %d\n", gAccPedalPos);
}
static void updateEngineSpeed()
{
// Update EngineSpeed
- int engineSpeed;
-
- engineSpeed = calcEngineSpeed();
- updateValue(ENGINE_SPEED, engineSpeed);
+ gEngineSpeed = gBaseValue*3000+1000;
+ setCanValue(ENGINE_SPEED, gEngineSpeed);
+ DBG_DEBUG("engineSpeed : %d\n", gEngineSpeed);
}
static void updateVehicleSpeed()
{
// Update VehicleSpeed
- int vehicleSpeed;
-
- vehicleSpeed = calcVehicleSpeed();
- updateValue(VEHICLE_SPEED, vehicleSpeed);
+ if(gBaseValue < 0)
+ gBaseValue = 0;
+ gVehicleSpeed = (int)(gBaseValue*9550/100)*100;
+ setCanValue(VEHICLE_SPEED, gVehicleSpeed);
+ DBG_DEBUG("vehicleSpeed : %d\n", gVehicleSpeed);
}
static void updateLightStatusBrake()
@@ -232,18 +245,30 @@ static void updateLightStatusBrake()
int lightStatusBrake;
lightStatusBrake = (gLightStatusBrake < 20000);
- updateValue(LIGHT_STATUS_BRAKE, lightStatusBrake);
+ 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);
}
static void updateSteeringWheelAngle()
{
int steering = calcSteeringWheelAngle();
- updateValue(STEERING_WHEEL_ANGLE, steering);
+ setCanValue(STEERING_WHEEL_ANGLE, steering);
}
static void updateTurnSignalStatus()
{
- updateValue(TURN_SIGNAL_STATUS, gTurnSignalStatus);
+ setCanValue(TURN_SIGNAL_STATUS, gTurnSignalStatus);
}
// Method to handle joy stick event
@@ -251,7 +276,7 @@ void newButtonValue(char number, int val)
{
switch (number)
{
- case JS_LEFT_PADDLE_SHIFTER: //Left paddle shifter
+ case JS_BUTTON_R1: //Left paddle shifter
// Set gear position
setTransmissionGearInfo(val, eTransmissionGearInfoLeft);
@@ -261,7 +286,7 @@ void newButtonValue(char number, int val)
updateVehicleSpeed();
break;
- case JS_RIGHT_PADDLE_SHIFTER: //Right paddle shifter
+ case JS_BUTTON_L1: //Right paddle shifter
// Set gear position
setTransmissionGearInfo(val, eTransmissionGearInfoRight);
@@ -271,7 +296,7 @@ void newButtonValue(char number, int val)
updateVehicleSpeed();
break;
- case JS_TURN_SIGNAL_RIGHT: //Right upper wheel button
+ case JS_BUTTON_R2: //Right upper wheel button
// Set value
setTurnSignalStatus(val, eTurnSignalStatusRight);
@@ -279,14 +304,27 @@ void newButtonValue(char number, int val)
updateTurnSignalStatus();
break;
- case JS_TURN_SIGNAL_LEFT: //Left upper wheel button
+ case JS_BUTTON_L2: //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;
}
@@ -294,9 +332,24 @@ 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_STEERING: //Wheel angle, -32767 - 32767
+ case JS_AXIS_STEERING: //Wheel angle, -32767 - 32767
// Set value
setSteeringWheelAngle(val);
@@ -304,17 +357,29 @@ void newAxisValue(char number, int val)
updateSteeringWheelAngle();
break;
- case JS_THROTTLE: //Throttle, -32767 (depressed) - 32767 (undepressed)
+ case JS_AXIS_ACCEL: //Throttle, -32767 (depressed) - 32767 (undepressed)
// Set origin value
- setAcceleratorPedalPosition(val);
+ 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);
+ }
// Update property
updateAcceleratorPedalPosition();
- updateEngineSpeed();
- updateVehicleSpeed();
+ if (gAccPedalPos > gCurAccPedalPos){
+ gCurAccPedalPos = gAccPedalPos;
+ gBaseValue = sin((float)gCurAccPedalPos/100.0);
+
+ updateEngineSpeed();
+ updateVehicleSpeed();
+ }
break;
- case JS_BRAKE:
+ case JS_AXIS_BRAKE:
// Set value
setLightStatusBrake(val);
@@ -322,7 +387,31 @@ 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