Added connection delay to account for Arduino auto-reset
Tweaked values for 320 kV motor
This commit is contained in:
parent
bf94dc733c
commit
3f68e6d8d9
|
@ -176,4 +176,11 @@ object MainForm: TMainForm
|
|||
Left = 424
|
||||
Top = 80
|
||||
end
|
||||
object ConnectWaitTimer: TTimer
|
||||
Enabled = False
|
||||
Interval = 100
|
||||
OnTimer = ConnectWaitTimerTimer
|
||||
Left = 504
|
||||
Top = 24
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,6 +34,7 @@ type
|
|||
SimulatorPanel: TPanel;
|
||||
SimulatorSelectionPanel: TPanel;
|
||||
SimulatorLockButton: TSpeedButton;
|
||||
ConnectWaitTimer: TTimer;
|
||||
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure PortComboBoxClick(Sender: TObject);
|
||||
|
@ -43,6 +44,7 @@ type
|
|||
procedure CalibrationButtonClick(Sender: TObject);
|
||||
procedure SimulatorComboBoxClick(Sender: TObject);
|
||||
procedure SimulatorLockButtonClick(Sender: TObject);
|
||||
procedure ConnectWaitTimerTimer(Sender: TObject);
|
||||
private
|
||||
FComPort: TComPort;
|
||||
FReceived: string;
|
||||
|
@ -63,6 +65,7 @@ type
|
|||
procedure StartCommand;
|
||||
procedure EndCommand;
|
||||
procedure OnReceiveChar(Sender: TObject; Count: Integer);
|
||||
procedure OnAfterClose(Sender: TObject);
|
||||
|
||||
function ValidFanIndex(AFan: Byte): Boolean; inline;
|
||||
|
||||
|
@ -368,6 +371,7 @@ begin
|
|||
FComPort := TComPort.Create(Self);
|
||||
FComPort.BaudRate := br19200;
|
||||
FComPort.OnRxChar := OnReceiveChar;
|
||||
FComPort.OnAfterClose := OnAfterClose;
|
||||
end;
|
||||
|
||||
newPort := PortComboBox.Items[PortComboBox.ItemIndex];
|
||||
|
@ -378,7 +382,24 @@ begin
|
|||
try
|
||||
ComPort.Open;
|
||||
|
||||
SendCommand('>Info',
|
||||
{ The Arduino resets when a serial connection is made, wait for a bit
|
||||
before sending the first Info command }
|
||||
ConnectWaitTimer.Enabled := True;
|
||||
except
|
||||
on E:Exception do
|
||||
begin
|
||||
PortStatusLabel.Caption := 'Failed to connect';
|
||||
ConnectTimer.Enabled := True;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TMainForm.ConnectWaitTimerTimer(Sender: TObject);
|
||||
begin
|
||||
ConnectWaitTimer.Enabled := False;
|
||||
|
||||
SendCommand(#10'>Info',
|
||||
procedure(Response: string)
|
||||
begin
|
||||
if AnsiStartsText('<Info:', Response) then
|
||||
|
@ -398,16 +419,10 @@ begin
|
|||
PortStatusLabel.Caption := 'No response';
|
||||
ConnectTimer.Enabled := True;
|
||||
end);
|
||||
except
|
||||
on E:Exception do
|
||||
begin
|
||||
PortStatusLabel.Caption := 'Failed to connect';
|
||||
ConnectTimer.Enabled := True;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
procedure TMainForm.OnReceiveChar(Sender: TObject; Count: Integer);
|
||||
var
|
||||
data: string;
|
||||
|
@ -430,6 +445,13 @@ begin
|
|||
end;
|
||||
|
||||
|
||||
procedure TMainForm.OnAfterClose(Sender: TObject);
|
||||
begin
|
||||
PortStatusLabel.Caption := 'Not connected';
|
||||
ConnectTimer.Enabled := True;
|
||||
end;
|
||||
|
||||
|
||||
function TMainForm.ValidFanIndex(AFan: Byte): Boolean;
|
||||
begin
|
||||
Result := AFan < Length(FFanValues);
|
||||
|
|
|
@ -83,7 +83,7 @@ const byte FanPin[FanCount] =
|
|||
|
||||
// The minimum value at which the fan still spins reliably. Anything below
|
||||
// will be considered as 0.
|
||||
#define MinimumValue 70
|
||||
#define MinimumValue 30
|
||||
|
||||
|
||||
/*
|
||||
|
@ -105,7 +105,7 @@ const byte FanPin[FanCount] =
|
|||
|
||||
// The pulse width when the input value is 255, in microseconds.
|
||||
// Use this to limit the maximum "throttle" to the ESC.
|
||||
#define ServoMaxValue (ServoMinPulseWidth + (ServoPulseRange / 4))
|
||||
#define ServoMaxValue ServoMinPulseWidth + ServoPulseRange
|
||||
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue