Skip to content

Commit

Permalink
pmon: autodetect platformio baud rate
Browse files Browse the repository at this point in the history
  • Loading branch information
samyk committed May 12, 2024
1 parent 1714afc commit 9b1168c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pmon
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ if ($pini)
my $env = "env:$pio{platformio}{default_envs}";
push(@pio, "-p", $pio{$env}{upload_port} ) if $pio{$env}{upload_port};
push(@pio, "-b", $pio{$env}{monitor_speed}) if $pio{$env}{monitor_speed};

# if no baud rate, let's see if we can find it in code
if (!$pio{$env}{monitor_speed})
{
my $src = $pio{$env}{src_dir} || "src";
my @files = glob("$src/*.{c,cpp,h,ino}");
my $baud;
foreach my $file (@files)
{
open(F, "<$file") || die "Can't read $file: $!";
while (<F>)
{
if (/Serial\.begin\(\s*(\d+)\s*\)/)
{
$baud = $1;
last;
}
}
close(F);
last if $baud;
}
push(@pio, "-b", $baud) if $baud;
}
}

my @run = ($pini ? @pio : @particle, @ARGV);
Expand Down

0 comments on commit 9b1168c

Please sign in to comment.