Skip to content

Instantly share code, notes, and snippets.

@pelwell
Created June 25, 2025 14:45
Show Gist options
  • Save pelwell/b154b07b2e935854ef2613ff26bc6831 to your computer and use it in GitHub Desktop.
Save pelwell/b154b07b2e935854ef2613ff26bc6831 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
my $verbose = ($ARGV[0] eq '-v');
chdir("/sys/bus/platform/drivers/rp1-adc/1f000c8000.adc/hwmon");
runcheck();
for (my $wait = 5; $wait >= 0; $wait--)
{
print ("[ sleep $wait ]\n");
sleep($wait);
runcheck();
}
sub runcheck
{
my (@first, @min, @max);
my $start = time;
while ((time - $start) < 5)
{
my $ph;
die if (!open($ph, '-|', "grep . hwmon*/in*_input | cut -d: -f2"));
for (my $idx = 0; $idx < 4; $idx++)
{
my $value = int(<$ph>);
print(" $value") if ($verbose);
if ($idx >= @first)
{
$first[$idx] = $min[$idx] = $max[$idx] = $value;
}
else
{
$min[$idx] = $value if ($value < $min[$idx]);
$max[$idx] = $value if ($value > $max[$idx]);
}
}
print("\n") if ($verbose);
}
for (my $idx = 0; $idx < 4; $idx++)
{
print("$idx: $min[$idx]-$max[$idx] (first $first[$idx])\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment