From 0c142ed5772299cf5f0b2e38b177bff7ed35a611 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Sat, 2 Sep 2017 10:51:21 +0200 Subject: [PATCH] Tweaks afters connecting an actual fan Changed PWM frequency to reduce fan motor hum Added minimum value Added custom value entry in the test application --- .gitignore | 1 + AssettoCorsa/source/MainFrm.dfm | 27 ++++++++++++++++++++++++++- AssettoCorsa/source/MainFrm.pas | 21 +++++++++++++++++++++ SimulatorFans.ino | 28 +++++++++++++++++++++++----- 4 files changed, 71 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 4da76bc..4686f0c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ AssettoCorsa/source/__history AssettoCorsa/*.dproj.local +AssettoCorsa/*.identcache AssettoCorsa/bin AssettoCorsa/lib \ No newline at end of file diff --git a/AssettoCorsa/source/MainFrm.dfm b/AssettoCorsa/source/MainFrm.dfm index 79701d3..75643d3 100644 --- a/AssettoCorsa/source/MainFrm.dfm +++ b/AssettoCorsa/source/MainFrm.dfm @@ -4,7 +4,7 @@ object MainForm: TMainForm BorderIcons = [biSystemMenu, biMinimize] BorderStyle = bsSingle Caption = 'SimulatorFans - Assetto Corsa' - ClientHeight = 309 + ClientHeight = 390 ClientWidth = 645 Color = clBtnFace Font.Charset = DEFAULT_CHARSET @@ -87,4 +87,29 @@ object MainForm: TMainForm TabOrder = 7 OnClick = Button6Click end + object Edit1: TEdit + Left = 288 + Top = 253 + Width = 75 + Height = 21 + TabOrder = 8 + Text = '0' + end + object Button7: TButton + Left = 288 + Top = 280 + Width = 171 + Height = 25 + Caption = 'Set' + TabOrder = 9 + OnClick = Button7Click + end + object Edit2: TEdit + Left = 384 + Top = 253 + Width = 75 + Height = 21 + TabOrder = 10 + Text = '0' + end end diff --git a/AssettoCorsa/source/MainFrm.pas b/AssettoCorsa/source/MainFrm.pas index 0b164be..7160412 100644 --- a/AssettoCorsa/source/MainFrm.pas +++ b/AssettoCorsa/source/MainFrm.pas @@ -22,6 +22,9 @@ type Button4: TButton; Button5: TButton; Button6: TButton; + Edit1: TEdit; + Button7: TButton; + Edit2: TEdit; procedure FormCreate(Sender: TObject); procedure RefreshPortsButtonClick(Sender: TObject); @@ -31,6 +34,7 @@ type procedure Button4Click(Sender: TObject); procedure Button5Click(Sender: TObject); procedure Button6Click(Sender: TObject); + procedure Button7Click(Sender: TObject); private FComPort: TComPort; FReceived: string; @@ -70,6 +74,7 @@ end; procedure TMainForm.Button2Click(Sender: TObject); begin + Edit1.Text := '255'; SendCommand('>SetFans:255,0', procedure(Response: string) begin @@ -80,6 +85,7 @@ end; procedure TMainForm.Button3Click(Sender: TObject); begin + Edit2.Text := '255'; SendCommand('>SetFans:0,255', procedure(Response: string) begin @@ -90,6 +96,8 @@ end; procedure TMainForm.Button4Click(Sender: TObject); begin + Edit1.Text := '0'; + Edit2.Text := '0'; SendCommand('>SetFans:0,0', procedure(Response: string) begin @@ -100,6 +108,7 @@ end; procedure TMainForm.Button5Click(Sender: TObject); begin + Edit1.Text := '128'; SendCommand('>SetFans:128,0', procedure(Response: string) begin @@ -110,6 +119,7 @@ end; procedure TMainForm.Button6Click(Sender: TObject); begin + Edit2.Text := '128'; SendCommand('>SetFans:0,128', procedure(Response: string) begin @@ -118,9 +128,20 @@ begin end); end; +procedure TMainForm.Button7Click(Sender: TObject); +begin + SendCommand('>SetFans:' + Edit1.Text + ',' + Edit2.Text, + procedure(Response: string) + begin + if Response <> ' 0) @@ -202,7 +217,11 @@ void checkStartingFans() void setFan(byte fan, byte value) { - if ((fanStatus[fan].value == 0 || fanStatus[fan].startTime > 0) && value > 0) + byte correctedValue = value; + if (correctedValue < MinimumValue) + correctedValue = 0; + + if ((fanStatus[fan].value == 0 || fanStatus[fan].startTime > 0) && correctedValue > 0) { // Fan was off or still starting up, start with full power to kick it off analogWrite(FanPin[fan], 255); @@ -216,9 +235,8 @@ void setFan(byte fan, byte value) { // Already running, simply change the speed and reset the start time if necessary fanStatus[fan].startTime = 0; - analogWrite(FanPin[fan], value); + analogWrite(FanPin[fan], correctedValue); } - fanStatus[fan].value = value; + fanStatus[fan].value = correctedValue; } -