Skip to content

Commit

Permalink
update APA102 from upstream
Browse files Browse the repository at this point in the history
update configuration for raspbian 9 + systemctl
set up unit tests
  • Loading branch information
Ellery Newcomer committed Nov 10, 2018
1 parent 19247db commit ea3e1d8
Show file tree
Hide file tree
Showing 25 changed files with 424 additions and 448 deletions.
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,49 @@
Based on https://github.com/tinue/APA102_Pi

# Prerequisites

see above, but basically

* pi should have raspbian 9 on it

* pi should have SPI enabled

```
raspi-config
# Interfacing Options > SPI
reboot
```

* Adafruit_Python_GPIO should be installed

see https://github.com/adafruit/Adafruit_Python_GPIO, but basically

```
apt-get install build-essential python3-pip python3-dev python3-smbus git
git clone https://github.com/adafruit/Adafruit_Python_GPIO.git
cd Adafruit_Python_GPIO
python setup.py install
```

for testing on a not-raspberry pi this seemed to work:
```
git clone https://github.com/adafruit/Adafruit_Python_GPIO.git
python setup.py install
```


# Deploy

```
python deploy.sh
```

will push code and restart the script. To make it run on boot up, you will have to run

```
systemctl enable lightshow.service
```

manually on the pi
6 changes: 5 additions & 1 deletion deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
ssh.ssh("mkdir -p /home/pi/squiggly")
ssh.ssh("rm -rf /home/pi/squiggly/*")
ssh.sftp('./src', '/home/pi/squiggly')
ssh.ssh("sudo /etc/init.d/lightshow restart")
ssh.sftp('./etc', '/home/pi/squiggly' )
ssh.ssh("sudo cp /home/pi/squiggly/etc/systemd/system/lightshow.service /etc/systemd/system/lightshow.service")
#ssh.ssh("sudo cp /home/pi/squiggly/etc/init.d/lightshow /etc/init.d/lightshow")
#ssh.ssh("sudo cp /home/pi/squiggly/etc/default/lightshow /etc/default/lightshow")
ssh.ssh("sudo systemctl restart lightshow.service")
1 change: 1 addition & 0 deletions etc/default/lightshow
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PIDFILE=/var/run/lightshow.pid
35 changes: 35 additions & 0 deletions etc/init.d/lightshow
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

### BEGIN INIT INFO
# Provides: lightshow
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: led service
# Description: leds!
### END INIT INFO

source /etc/default/lightshow

startthings() {
echo "starty $(date)" >> /home/pi/lighty
start-stop-daemon --pidfile=$PIDFILE -b -m --start --exec /usr/bin/python3 /home/pi/squiggly/src/run.py
}

stopthings() {
start-stop-daemon --pidfile=$PIDFILE --stop && rm -f $PIDFILE
}

case "$1" in
start)
startthings
;;
stop)
stopthings
;;
force-reload|restart|reload)
stopthings
startthings
;;
esac
13 changes: 13 additions & 0 deletions etc/systemd/system/lightshow.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=leds!
After=network.target

[Service]
ExecStart=/usr/bin/python3 run.py
WorkingDirectory=/home/pi/squiggly/src
StandardOutput=inherit
StandardError=inherit
Restart=always

[Install]
WantedBy=multi-user.target
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pyfrc
pytest
5 changes: 5 additions & 0 deletions runtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
echo $PYTHONPATH
export PYTHONPATH=$(pwd)/src

echo $PYTHONPATH
python -m pytest tests
Empty file added src/__init__.py
Empty file.
87 changes: 0 additions & 87 deletions src/colorcycletemplate.py

This file was deleted.

75 changes: 0 additions & 75 deletions src/colorschemes.py

This file was deleted.

Empty file added src/commands/__init__.py
Empty file.
55 changes: 47 additions & 8 deletions src/commands/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ def __init__(self):
self.state = False

def initialize(self):
self.leds.clearStrip()
self.leds.clear_strip()
self.timer.start()

def execute(self):
# this method is executed approximately once every 5 ms
if self.timer.get() > 0.5:
self.timer.reset()
if self.state:
self.leds.setPixel(1, 135, 206, 250)
self.leds.set_pixel(1, 135, 206, 250)
else:
self.leds.setPixel(1, 135, 0, 0)
self.leds.set_pixel(1, 135, 0, 0)

self.state = not self.state
self.leds.show()
Expand All @@ -31,7 +31,7 @@ def isFinished(self):
pass

def end(self):
self.leds.clearStrip()
self.leds.clear_strip()


class OtherBlinkyCommand(Command):
Expand All @@ -44,7 +44,7 @@ def __init__(self):
self.counter = 0

def initialize(self):
self.leds.clearStrip()
self.leds.clear_strip()
self.timer.start()

def execute(self):
Expand All @@ -53,9 +53,9 @@ def execute(self):
self.counter += 1
self.timer.reset()
if self.state:
self.leds.setPixel(1, 135, 206, 250)
self.leds.set_pixel(1, 135, 206, 250)
else:
self.leds.setPixel(1, 0, 0, 234)
self.leds.set_pixel(1, 0, 0, 234)

self.state = not self.state
self.leds.show()
Expand All @@ -64,4 +64,43 @@ def isFinished(self):
return self.counter > 10

def end(self):
self.leds.clearStrip()
self.leds.clear_strip()


class StrafeCommand(Command):
def __init__(self):
super().__init__()
self.leds = LEDSubsystem.getInstance()
self.requires(self.leds)
self.timer = wpilib.Timer()

self.color1 = (135, 206, 250)

self.pos = 0

def initialize(self):
self.leds.clear_strip()
self.timer.start()
self.paint()

def execute(self):
if self.timer.get() > 0.015:
print (self.timer.get())
self.timer.reset()
self.pos = (self.pos + 1) % self.leds.num_led
self.paint()


def paint(self):
for i in range(0, self.leds.num_led):
self.leds.set_pixel(i, 0,0,0)
for i in range(self.pos, min(self.pos+10, self.leds.num_led)):
self.leds.set_pixel(i, *self.color1)

self.leds.show()

def isFinished(self):
return False

def end(self):
self.leds.clear_strip()
Loading

0 comments on commit ea3e1d8

Please sign in to comment.