diff options
author | dakkar <dakkar@thenautilus.net> | 2018-03-30 16:32:34 +0100 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2018-03-30 16:32:34 +0100 |
commit | b4852871721b2ca07c9a46d23cd7151ef7fabf35 (patch) | |
tree | 2ad647189a06ff5f0f6cf138a117a63668feb45e /trasmitter | |
parent | notes for sensor (diff) | |
download | thermostat-b4852871721b2ca07c9a46d23cd7151ef7fabf35.tar.gz thermostat-b4852871721b2ca07c9a46d23cd7151ef7fabf35.tar.bz2 thermostat-b4852871721b2ca07c9a46d23cd7151ef7fabf35.zip |
we may be able to send from the CHIP
Diffstat (limited to 'trasmitter')
-rw-r--r-- | trasmitter/README.rst.txt | 9 | ||||
-rw-r--r-- | trasmitter/sender-chip.pl | 62 |
2 files changed, 71 insertions, 0 deletions
diff --git a/trasmitter/README.rst.txt b/trasmitter/README.rst.txt index e231527..4b9e310 100644 --- a/trasmitter/README.rst.txt +++ b/trasmitter/README.rst.txt @@ -29,3 +29,12 @@ The two sequences are: Actually no, the pulses are not ½ high and ½ low, they're shaped weird. The source code has the correct widths. + +Without Arduino +=============== + +The GPIO / XIO pins on NextThing's CHIP, even when driven via the `slow +sysfs interface`_, seem to be fast enough for our purposes. + +See the ``sender-chip.pl`` test program. + diff --git a/trasmitter/sender-chip.pl b/trasmitter/sender-chip.pl new file mode 100644 index 0000000..27ae20e --- /dev/null +++ b/trasmitter/sender-chip.pl @@ -0,0 +1,62 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Time::HiRes qw(usleep sleep gettimeofday tv_interval); + +my $base = do { + open my $fh,'<','/sys/class/gpio/gpiochip405/base' or die "can't get base: $!"; + my $line = <$fh>; + chomp($line); + $line; +}; + +sub gpio_enable { + my ($pin,$state) = @_; + + if ($state) { + open my $fh,'>','/sys/class/gpio/export' or die "Can't export: $!"; + print $fh $pin,"\n"; + } + else { + open my $fh,'>','/sys/class/gpio/unexport' or die "Can't unexport: $!"; + print $fh $pin,"\n"; + } +} + +sub gpio_direction { + my ($pin,$direction) = @_; + + my $file = "/sys/class/gpio/gpio$pin/direction"; + open my $fh,'>',$file + or die "Can't direction $file: $!"; + print $fh ($direction ? 'out' : 'in' ),"\n"; +} + +sub gpio_write { + my ($pin,$value) = @_; + + open my $fh,'>',"/sys/class/gpio/gpio$pin/value" + or die "Can't write: $!"; + print $fh $value,"\n"; +} + +my $pin = 132; # CSID0 +#my $pin = $base+0; # XIO0 + +gpio_enable($pin,1); +gpio_direction($pin,1); +gpio_write($pin,0); +$SIG{INT} = sub {warn"disabling";gpio_enable($pin,0) }; +END { warn"disabling";gpio_enable($pin,0) } + +my $width = 400; # this seems to provide pulse widths close enough to + # what we need, it's 106 samples at 192kHz +while (1) { + for (0..50) { + gpio_write($pin,1); + usleep($width); + gpio_write($pin,0); + usleep($width); + } + sleep(0.5); +} |