From 7c9d89495df4a65b92f9adf0e83174fcb1cbaacb Mon Sep 17 00:00:00 2001 From: tcfshcrw <48719709+tcfshcrw@users.noreply.github.com> Date: Thu, 18 Jul 2024 17:27:58 +0800 Subject: [PATCH] Add custom effect 1/2 bump DAP version to 137 --- ESP32/include/ABSOscillation.h | 49 +++++++++ ESP32/include/DiyActivePedal_types.h | 10 +- ESP32/src/Main.cpp | 17 ++- SimHubPlugin/DataPluginDemo.cs | 54 ++++++++-- SimHubPlugin/DataPluginDemoSettings.cs | 11 +- SimHubPlugin/SettingsControlDemo.xaml | 64 ++++++++++- SimHubPlugin/SettingsControlDemo.xaml.cs | 130 +++++++++++++++++++++-- SimHubPlugin/bin/DiyActivePedal.dll | Bin 180224 -> 188928 bytes 8 files changed, 310 insertions(+), 25 deletions(-) diff --git a/ESP32/include/ABSOscillation.h b/ESP32/include/ABSOscillation.h index d822f5ae..e41e725a 100644 --- a/ESP32/include/ABSOscillation.h +++ b/ESP32/include/ABSOscillation.h @@ -7,6 +7,7 @@ static const long ABS_ACTIVE_TIME_PER_TRIGGER_MILLIS = 100; static const long RPM_ACTIVE_TIME_PER_TRIGGER_MILLIS = 100; static const long BP_ACTIVE_TIME_PER_TRIGGER_MILLIS = 100; static const long WS_ACTIVE_TIME_PER_TRIGGER_MILLIS = 100; +static const long CV_ACTIVE_TIME_PER_TRIGGER_MILLIS = 100; static int RPM_VALUE_LAST = 0; class ABSOscillation { @@ -383,3 +384,51 @@ class Road_impact_effect } }; +//Wheel slip +class Custom_vibration { +private: + long _timeLastTriggerMillis; + long _CVTimeMillis; + long _lastCallTimeMillis = 0; + + +public: + Custom_vibration() + : _timeLastTriggerMillis(0) + {} + //float RPM_value =0; + float CV_Force_offset = 0; +public: + void trigger() { + _timeLastTriggerMillis = millis(); + } + + void forceOffset(float CV_freq, float CV_amp) { + + + long timeNowMillis = millis(); + float timeSinceTrigger = (timeNowMillis - _timeLastTriggerMillis); + float CVForceOffset = 0; + + + if (timeSinceTrigger > CV_ACTIVE_TIME_PER_TRIGGER_MILLIS) + { + _CVTimeMillis = 0; + CVForceOffset = 0; + } + else + { + _CVTimeMillis += timeNowMillis - _lastCallTimeMillis; + float CVTimeSeconds = _CVTimeMillis / 1000.0f; + + CVForceOffset = CV_amp/20.0f * sin( 2*PI* CV_freq* CVTimeSeconds); + + + + } + CV_Force_offset=CVForceOffset; + _lastCallTimeMillis = timeNowMillis; + + + } +}; \ No newline at end of file diff --git a/ESP32/include/DiyActivePedal_types.h b/ESP32/include/DiyActivePedal_types.h index 25cec8e3..88d483fb 100644 --- a/ESP32/include/DiyActivePedal_types.h +++ b/ESP32/include/DiyActivePedal_types.h @@ -3,7 +3,7 @@ #include // define the payload revision -#define DAP_VERSION_CONFIG 136 +#define DAP_VERSION_CONFIG 137 // define the payload types #define DAP_PAYLOAD_TYPE_CONFIG 100 @@ -33,6 +33,8 @@ struct payloadPedalAction { uint8_t G_value; uint8_t WS_u8; uint8_t impact_value_u8; + uint8_t Trigger_CV_1; + uint8_t Trigger_CV_2; }; @@ -118,6 +120,12 @@ struct payloadPedalConfig { //Road impact effect uint8_t Road_multi; uint8_t Road_window; + //Custom Vibration 1 + uint8_t CV_amp_1; + uint8_t CV_freq_1; + //Custom Vibration 2 + uint8_t CV_amp_2; + uint8_t CV_freq_2; // cubic spline parameters float cubic_spline_param_a_array[5]; float cubic_spline_param_b_array[5]; diff --git a/ESP32/src/Main.cpp b/ESP32/src/Main.cpp index 118118ae..c347dd11 100644 --- a/ESP32/src/Main.cpp +++ b/ESP32/src/Main.cpp @@ -91,6 +91,8 @@ BitePointOscillation _BitePointOscillation; G_force_effect _G_force_effect; WSOscillation _WSOscillation; Road_impact_effect _Road_impact_effect; +Custom_vibration CV1; +Custom_vibration CV2; #define ABS_OSCILLATION @@ -770,6 +772,8 @@ void pedalUpdateTask( void * pvParameters ) _G_force_effect.forceOffset(&dap_calculationVariables_st, dap_config_st.payLoadPedalConfig_.G_multi); _WSOscillation.forceOffset(&dap_calculationVariables_st); _Road_impact_effect.forceOffset(&dap_calculationVariables_st, dap_config_st.payLoadPedalConfig_.Road_multi); + CV1.forceOffset(dap_config_st.payLoadPedalConfig_.CV_freq_1,dap_config_st.payLoadPedalConfig_.CV_amp_1); + CV2.forceOffset(dap_config_st.payLoadPedalConfig_.CV_freq_2,dap_config_st.payLoadPedalConfig_.CV_amp_2); #endif //update max force with G force effect @@ -930,7 +934,7 @@ void pedalUpdateTask( void * pvParameters ) //Add effect by force - float effect_force=absForceOffset+ _BitePointOscillation.BitePoint_Force_offset+_WSOscillation.WS_Force_offset; + float effect_force=absForceOffset+ _BitePointOscillation.BitePoint_Force_offset+_WSOscillation.WS_Force_offset+CV1.CV_Force_offset+CV2.CV_Force_offset; // use interpolation to determine local linearized spring stiffness double stepperPosFraction = stepper->getCurrentPositionFraction(); @@ -1322,7 +1326,16 @@ void serialCommunicationTask( void * pvParameters ) { systemIdentificationMode_b = true; } - + // trigger Custom effect effect 1 + if (dap_actions_st.payloadPedalAction_.Trigger_CV_1) + { + CV1.trigger(); + } + // trigger Custom effect effect 2 + if (dap_actions_st.payloadPedalAction_.Trigger_CV_2) + { + CV2.trigger(); + } // trigger return pedal position if (dap_actions_st.payloadPedalAction_.returnPedalConfig_u8) { diff --git a/SimHubPlugin/DataPluginDemo.cs b/SimHubPlugin/DataPluginDemo.cs index cd066170..392d0c7b 100644 --- a/SimHubPlugin/DataPluginDemo.cs +++ b/SimHubPlugin/DataPluginDemo.cs @@ -23,7 +23,7 @@ static class Constants { // payload revisiom - public const uint pedalConfigPayload_version = 136; + public const uint pedalConfigPayload_version = 137; // pyload types @@ -57,6 +57,8 @@ public struct payloadPedalAction public byte G_value; public byte WS_u8; public byte impact_value; + public byte Trigger_CV_1; + public byte Trigger_CV_2; }; public struct payloadPedalState_Basic @@ -136,7 +138,13 @@ public struct payloadPedalConfig public byte WS_amp; public byte WS_freq; public byte Impact_multi; - public byte Impact_window; + public byte Impact_window; + //Custom Vibration 1 + public byte CV_amp_1; + public byte CV_freq_1; + //Custom Vibration 2 + public byte CV_amp_2; + public byte CV_freq_2; // cubic spline params public float cubic_spline_param_a_0; public float cubic_spline_param_a_1; @@ -400,6 +408,8 @@ unsafe public void DataUpdate(PluginManager pluginManager, ref GameData data) double _G_force = 128; byte WS_value = 0; byte Road_impact_value = 0; + byte CV1_value = 0; + byte CV2_value = 0; //bool WS_flag = false; if (data.GamePaused | (!data.GameRunning)) @@ -473,6 +483,7 @@ unsafe public void DataUpdate(PluginManager pluginManager, ref GameData data) } game_running_index = 1; + } else @@ -531,6 +542,8 @@ unsafe public void DataUpdate(PluginManager pluginManager, ref GameData data) tmp.payloadPedalAction_.WS_u8 = 0; tmp.payloadPedalAction_.impact_value = 0; + tmp.payloadPedalAction_.Trigger_CV_1 = 0; + tmp.payloadPedalAction_.Trigger_CV_2 = 0; if (Settings.G_force_enable_flag[pedalIdx] == 1) { tmp.payloadPedalAction_.G_value = (Byte)g_force_last_value; @@ -604,9 +617,6 @@ unsafe public void DataUpdate(PluginManager pluginManager, ref GameData data) update_flag = true; } } - - - } //Road impact if (Settings.Road_impact_enable_flag[pedalIdx] == 1) @@ -641,8 +651,34 @@ unsafe public void DataUpdate(PluginManager pluginManager, ref GameData data) } } } - - + if (Settings.CV1_enable_flag[pedalIdx] == true) + { + if (pluginManager.GetPropertyValue(Settings.CV1_bindings[pedalIdx]) != null) + { + + CV1_value = Convert.ToByte(pluginManager.GetPropertyValue(Settings.CV1_bindings[pedalIdx])); + if (CV1_value > (Settings.CV1_trigger[pedalIdx])) + { + tmp.payloadPedalAction_.Trigger_CV_1 = 1; + update_flag = true; + } + } + } + if (Settings.CV2_enable_flag[pedalIdx] == true) + { + if (pluginManager.GetPropertyValue(Settings.CV2_bindings[pedalIdx]) != null) + { + + CV2_value = Convert.ToByte(pluginManager.GetPropertyValue(Settings.CV2_bindings[pedalIdx])); + if (CV2_value > (Settings.CV2_trigger[pedalIdx])) + { + tmp.payloadPedalAction_.Trigger_CV_2 = 1; + update_flag = true; + } + } + } + + if (pedalIdx == 1) @@ -706,6 +742,8 @@ unsafe public void DataUpdate(PluginManager pluginManager, ref GameData data) tmp.payloadPedalAction_.G_value = 128; tmp.payloadPedalAction_.WS_u8 = 0; tmp.payloadPedalAction_.impact_value = 0; + tmp.payloadPedalAction_.Trigger_CV_1 = 0; + tmp.payloadPedalAction_.Trigger_CV_2 = 0; rpm_last_value = 0; Road_impact_last = 0; debug_value = 0; @@ -742,6 +780,8 @@ unsafe public void DataUpdate(PluginManager pluginManager, ref GameData data) tmp.payloadPedalAction_.G_value = 128; tmp.payloadPedalAction_.WS_u8 = 0; tmp.payloadPedalAction_.impact_value = 0; + tmp.payloadPedalAction_.Trigger_CV_1 = 0; + tmp.payloadPedalAction_.Trigger_CV_2 = 0; DAP_action_st* v = &tmp; byte* p = (byte*)v; tmp.payloadFooter_.checkSum = checksumCalc(p, sizeof(payloadHeader) + sizeof(payloadPedalAction)); diff --git a/SimHubPlugin/DataPluginDemoSettings.cs b/SimHubPlugin/DataPluginDemoSettings.cs index 6b416a9d..0a792c11 100644 --- a/SimHubPlugin/DataPluginDemoSettings.cs +++ b/SimHubPlugin/DataPluginDemoSettings.cs @@ -1,4 +1,6 @@ -namespace User.PluginSdkDemo +using System.Linq.Expressions; + +namespace User.PluginSdkDemo { /// /// Settings class, make sure it can be correctly serialized using JSON.net @@ -36,7 +38,12 @@ public class DataPluginDemoSettings public double kinematicDiagram_zeroPos_OY = 20; public double kinematicDiagram_zeroPos_scale = 1.5; public bool[] RTSDTR_False = new bool[3] { true,true,true}; - + public bool[] CV1_enable_flag = new bool[3] { false,false, false }; + public int[] CV1_trigger = new int[3] { 0, 0, 0 }; + public string[] CV1_bindings = new string[3] { "","",""}; + public bool[] CV2_enable_flag = new bool[3] { false, false, false }; + public int[] CV2_trigger = new int[3] { 0, 0, 0 }; + public string[] CV2_bindings = new string[3] { "", "", "" }; } diff --git a/SimHubPlugin/SettingsControlDemo.xaml b/SimHubPlugin/SettingsControlDemo.xaml index a0f5e628..056a83cc 100644 --- a/SimHubPlugin/SettingsControlDemo.xaml +++ b/SimHubPlugin/SettingsControlDemo.xaml @@ -1582,7 +1582,35 @@ - + + + + + + + + + + + + + + + + + + + + + @@ -1593,11 +1621,39 @@ - + + + + + + + + + + + + + + + + + + + + + - + - +