Added connection delay to account for Arduino auto-reset

Tweaked values for 320 kV motor
This commit is contained in:
Mark van Renswoude 2019-01-12 15:07:44 +01:00
parent bf94dc733c
commit 3f68e6d8d9
3 changed files with 51 additions and 22 deletions

View File

@ -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

View File

@ -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,26 +382,9 @@ begin
try
ComPort.Open;
SendCommand('>Info',
procedure(Response: string)
begin
if AnsiStartsText('<Info:', Response) then
begin
PortStatusLabel.Caption := 'Connected';
InitDevice(Copy(Response, 7, MaxInt));
FReady := True;
end else
begin
PortStatusLabel.Caption := 'Invalid response';
ConnectTimer.Enabled := True;
end;
end,
procedure
begin
PortStatusLabel.Caption := 'No response';
ConnectTimer.Enabled := True;
end);
{ 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
@ -408,6 +395,34 @@ begin
end;
procedure TMainForm.ConnectWaitTimerTimer(Sender: TObject);
begin
ConnectWaitTimer.Enabled := False;
SendCommand(#10'>Info',
procedure(Response: string)
begin
if AnsiStartsText('<Info:', Response) then
begin
PortStatusLabel.Caption := 'Connected';
InitDevice(Copy(Response, 7, MaxInt));
FReady := True;
end else
begin
PortStatusLabel.Caption := 'Invalid response';
ConnectTimer.Enabled := True;
end;
end,
procedure
begin
PortStatusLabel.Caption := 'No response';
ConnectTimer.Enabled := True;
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);

View File

@ -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
/*