Skip to content

Commit

Permalink
Force slider Tickfrequency now can be 0.1kg
Browse files Browse the repository at this point in the history
1.Bump DAP version to 140
2.remove OTA flag
3.Force slider frequency can be 0.1kg in debug mode
4.bug fix for apply profile not parse int16 value.
  • Loading branch information
tcfshcrw committed Aug 28, 2024
1 parent bf771cf commit 34fd911
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 30 deletions.
8 changes: 4 additions & 4 deletions ESP32/include/DiyActivePedal_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdint.h>

// define the payload revision
#define DAP_VERSION_CONFIG 139
#define DAP_VERSION_CONFIG 140

// define the payload types
#define DAP_PAYLOAD_TYPE_CONFIG 100
Expand Down Expand Up @@ -72,8 +72,8 @@ struct payloadPedalConfig {
uint8_t pedalEndPosition;

// configure pedal forces
uint8_t maxForce;
uint8_t preloadForce;
uint16_t maxForce;
uint16_t preloadForce;

// design force vs travel curve
// In percent
Expand Down Expand Up @@ -178,7 +178,7 @@ struct payloadPedalConfig {
//pedal type, 0= clutch, 1= brake, 2= gas
uint8_t pedal_type;
//OTA flag
uint8_t OTA_flag;
//uint8_t OTA_flag;

uint8_t enableReboot_u8;
//joystick out flag
Expand Down
8 changes: 4 additions & 4 deletions ESP32/src/DiyActivePedal_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void DAP_config_st::initialiseDefaults() {

payLoadPedalConfig_.invertMotorDirection_u8 = 0;
payLoadPedalConfig_.pedal_type=4;
payLoadPedalConfig_.OTA_flag=0;
//payLoadPedalConfig_.OTA_flag=0;
payLoadPedalConfig_.enableReboot_u8=1;
//payLoadPedalConfig_.Joystick_ESPsync_to_ESP=0;
}
Expand Down Expand Up @@ -178,10 +178,10 @@ void DAP_calculationVariables_st::updateFromConfig(DAP_config_st& config_st) {
WS_amp=((float)config_st.payLoadPedalConfig_.WS_amp) / 20.0f;
WS_freq=(float)config_st.payLoadPedalConfig_.WS_freq;
// update force variables
Force_Min = ((float)config_st.payLoadPedalConfig_.preloadForce);
Force_Max = ((float)config_st.payLoadPedalConfig_.maxForce);
Force_Min = ((float)config_st.payLoadPedalConfig_.preloadForce)/10.0f;
Force_Max = ((float)config_st.payLoadPedalConfig_.maxForce)/10.0f;
Force_Range = Force_Max - Force_Min;
Force_Max_default=((float)config_st.payLoadPedalConfig_.maxForce);
Force_Max_default=((float)config_st.payLoadPedalConfig_.maxForce)/10.0f;
pedal_type=config_st.payLoadPedalConfig_.pedal_type;
}

Expand Down
8 changes: 4 additions & 4 deletions ESP_bridge/include/DiyActivePedal_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <stdint.h>

// define the payload revision
#define DAP_VERSION_CONFIG 139
#define DAP_VERSION_CONFIG 140

// define the payload types
#define DAP_PAYLOAD_TYPE_CONFIG 100
Expand Down Expand Up @@ -76,8 +76,8 @@ struct payloadPedalConfig {
uint8_t pedalEndPosition;

// configure pedal forces
uint8_t maxForce;
uint8_t preloadForce;
uint16_t maxForce;
uint16_t preloadForce;

// design force vs travel curve
// In percent
Expand Down Expand Up @@ -182,7 +182,7 @@ struct payloadPedalConfig {
//pedal type, 0= clutch, 1= brake, 2= gas
uint8_t pedal_type;
//OTA flag
uint8_t OTA_flag;
//uint8_t OTA_flag;

uint8_t enableReboot_u8;
//joystick out flag
Expand Down
2 changes: 1 addition & 1 deletion ESP_bridge/src/DiyActivePedal_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void DAP_config_st::initialiseDefaults() {

payLoadPedalConfig_.invertMotorDirection_u8 = 0;
payLoadPedalConfig_.pedal_type=4;
payLoadPedalConfig_.OTA_flag=0;
//payLoadPedalConfig_.OTA_flag=0;
payLoadPedalConfig_.enableReboot_u8=1;
//payLoadPedalConfig_.Joystick_ESPsync_to_ESP=0;
}
Expand Down
10 changes: 5 additions & 5 deletions SimHubPlugin/DataPluginDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
static class Constants
{
// payload revisiom
public const uint pedalConfigPayload_version = 139;
public const uint pedalConfigPayload_version = 140;


// pyload types
Expand Down Expand Up @@ -106,8 +106,8 @@ public struct payloadPedalConfig
public byte pedalEndPosition;

// configure pedal forces
public byte maxForce;
public byte preloadForce;
public Int16 maxForce;
public Int16 preloadForce;

// design force vs travel curve
// In percent
Expand Down Expand Up @@ -216,7 +216,7 @@ public struct payloadPedalConfig
public byte pedal_type;

// OTA update flag
public byte OTA_flag;
//public byte OTA_flag;

// OTA update flag
public byte enableReboot_u8;
Expand Down Expand Up @@ -1944,7 +1944,7 @@ public void Init(PluginManager pluginManager)

dap_config_initial_st.payloadPedalConfig_.spindlePitch_mmPerRev_u8 = 5;
dap_config_initial_st.payloadPedalConfig_.pedal_type = 0;
dap_config_initial_st.payloadPedalConfig_.OTA_flag = 0;
//dap_config_initial_st.payloadPedalConfig_.OTA_flag = 0;
dap_config_initial_st.payloadPedalConfig_.enableReboot_u8 = 1;


Expand Down
2 changes: 1 addition & 1 deletion SimHubPlugin/SettingsControlDemo.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@

<StackPanel Width="50" Height="230" Margin="10,-10,0,0">
<Label x:Name="Label_max_force" Width="50" Height="20" Foreground="White" RenderTransformOrigin="0.5,0.5" Canvas.Top="3" FontSize="8" FontFamily="Arial Black" Canvas.Left="5" HorizontalAlignment="Left" VerticalAlignment="Top" Content="Min" Padding="0,0,0,0" Margin="0,-5,0,0"/>
<controls:RangeSlider x:Name="Rangeslider_force_range" Style="{DynamicResource RangeSliderStyle}" MinRangeWidth="1" Grid.Column="2" Height="180" LowerValueChanged="Rangeslider_force_range_LowerValueChanged" UpperValueChanged="Rangeslider_force_range_UpperValueChanged" MinRange="1" SmallChange="1" IsSnapToTickEnabled="True" LowerValue="10" UpperValue="30" Width="20" Orientation="Vertical" Maximum="200" HorizontalAlignment="Left" LargeChange="10"/>
<controls:RangeSlider x:Name="Rangeslider_force_range" Style="{DynamicResource RangeSliderStyle}" MinRangeWidth="1" Grid.Column="2" Height="180" LowerValueChanged="Rangeslider_force_range_LowerValueChanged" UpperValueChanged="Rangeslider_force_range_UpperValueChanged" MinRange="1" SmallChange="1" IsSnapToTickEnabled="True" LowerValue="10" UpperValue="30" Width="20" Orientation="Vertical" Maximum="2000" HorizontalAlignment="Left" LargeChange="10"/>
<Label x:Name="Label_min_force" Width="50" Height="20" Foreground="White" RenderTransformOrigin="0.5,0.5" Canvas.Top="3" FontSize="8" FontFamily="Arial Black" Canvas.Left="5" HorizontalAlignment="Left" VerticalAlignment="Top" Content="Min" Padding="0,0,0,0"/>
</StackPanel>
</StackPanel>
Expand Down
32 changes: 21 additions & 11 deletions SimHubPlugin/SettingsControlDemo.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public void DAP_config_set_default(uint pedalIdx)
dap_config_st[pedalIdx].payloadHeader_.version = (byte)Constants.pedalConfigPayload_version;
dap_config_st[pedalIdx].payloadPedalConfig_.pedalStartPosition = 35;
dap_config_st[pedalIdx].payloadPedalConfig_.pedalEndPosition = 80;
dap_config_st[pedalIdx].payloadPedalConfig_.maxForce = 50;
dap_config_st[pedalIdx].payloadPedalConfig_.maxForce = 500;
dap_config_st[pedalIdx].payloadPedalConfig_.preloadForce = 0;
dap_config_st[pedalIdx].payloadPedalConfig_.relativeForce_p000 = 0;
dap_config_st[pedalIdx].payloadPedalConfig_.relativeForce_p020 = 20;
Expand Down Expand Up @@ -482,7 +482,7 @@ public void DAP_config_set_default(uint pedalIdx)

dap_config_st[pedalIdx].payloadPedalConfig_.spindlePitch_mmPerRev_u8 = 5;
dap_config_st[pedalIdx].payloadPedalConfig_.pedal_type = (byte)pedalIdx;
dap_config_st[pedalIdx].payloadPedalConfig_.OTA_flag = 0;
//dap_config_st[pedalIdx].payloadPedalConfig_.OTA_flag = 0;
dap_config_st[pedalIdx].payloadPedalConfig_.enableReboot_u8 = 0;
}

Expand Down Expand Up @@ -546,6 +546,7 @@ public SettingsControlDemo()
DrawGridLines_kinematicCanvas(100,20,1.5);
CustomEffectTab.Visibility = Visibility.Hidden;
Label_RSSI.Visibility= Visibility.Hidden;
Rangeslider_force_range.TickFrequency = 10;



Expand Down Expand Up @@ -1090,16 +1091,16 @@ public void updateTheGuiFromConfig()
Rangeslider_force_range.LowerValue = dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.preloadForce;
if (indexOfSelectedPedal_u != 1)
{
Rangeslider_force_range.Maximum = 50;
Rangeslider_force_range.Maximum = 500;
}
else
{
Rangeslider_force_range.Maximum = 200;
Rangeslider_force_range.Maximum = 2000;
}
if (Plugin != null)
{
Label_max_force.Content = "Max force:\n" + dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.maxForce + "kg";
Label_min_force.Content = "Preload:\n" + dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.preloadForce + "kg";
Label_max_force.Content = "Max force:\n" + dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.maxForce / 10 + "kg";
Label_min_force.Content = "Preload:\n" + dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.preloadForce / 10 + "kg";
}

label_damping.Content = "Damping factor: " + (float)(dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.dampingPress * 0.00015f)+"s";
Expand Down Expand Up @@ -3830,6 +3831,12 @@ void Parsefile(uint profile_index)
byte value = (byte)data["payloadPedalConfig_"][field.Name];
field.SetValue(obj, value);
}
if (field.FieldType == typeof(Int16))
{
//byte value = forecastNode["payloadPedalConfig_"][field.Name].GetValue<byte>();
Int16 value = (Int16)data["payloadPedalConfig_"][field.Name];
field.SetValue(obj, value);
}

}
catch (Exception)
Expand Down Expand Up @@ -4318,6 +4325,7 @@ private void Debug_checkbox_Checked(object sender, RoutedEventArgs e)
Line_H_HeaderTab.X2 = 1088;
CustomEffectTab.Visibility = Visibility.Visible;
Slider_LC_rate.TickFrequency = 1;
Rangeslider_force_range.TickFrequency = 1;


}
Expand Down Expand Up @@ -4346,6 +4354,7 @@ private void Debug_checkbox_Unchecked(object sender, RoutedEventArgs e)
Line_H_HeaderTab.X2 = 723;
CustomEffectTab.Visibility = Visibility.Hidden;
Slider_LC_rate.TickFrequency = 10;
Rangeslider_force_range.TickFrequency = 10;
}


Expand Down Expand Up @@ -4859,7 +4868,7 @@ private void btn_linearcurve_Click(object sender, RoutedEventArgs e)
Update_BrakeForceCurve();
updateTheGuiFromConfig();
}

/*
private void OTA_update_check_Unchecked(object sender, RoutedEventArgs e)
{
dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.OTA_flag = 0;
Expand All @@ -4869,6 +4878,7 @@ private void OTA_update_check_Checked(object sender, RoutedEventArgs e)
{
dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.OTA_flag = 1;
}
*/

private void EnableReboot_check_Unchecked(object sender, RoutedEventArgs e)
{
Expand Down Expand Up @@ -5618,19 +5628,19 @@ private void Rangeslider_travel_range_UpperValueChanged(object sender, RangePara

private void Rangeslider_force_range_UpperValueChanged(object sender, RangeParameterChangedEventArgs e)
{
dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.maxForce = (byte)e.NewValue;
dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.maxForce = (Int16)e.NewValue;
if (Plugin != null)
{
Label_max_force.Content = "Max force:\n" + dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.maxForce + "kg";
Label_max_force.Content = "Max force:\n" + (float)dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.maxForce/10.0f + "kg";
}
}

private void Rangeslider_force_range_LowerValueChanged(object sender, RangeParameterChangedEventArgs e)
{
dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.preloadForce = (byte)e.NewValue;
dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.preloadForce = (Int16)e.NewValue;
if (Plugin != null)
{
Label_min_force.Content = "Preload:\n" + dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.preloadForce + "kg";
Label_min_force.Content = "Preload:\n" + (float)dap_config_st[indexOfSelectedPedal_u].payloadPedalConfig_.preloadForce/10.0f + "kg";
}
}

Expand Down

0 comments on commit 34fd911

Please sign in to comment.