Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 68 additions & 49 deletions backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@
import RPi.GPIO
conf['hardware'] = 'raspberrypi'
except ImportError:
# try to import Adafruit GPIO library for Debian 9 based official BB image
try:
global GPIO
import Adafruit_BBIO.GPIO as GPIO
except ImportError:
# Adafruit GPIO library unavailable. Do nothing and continue.
pass
# os.uname() on BBB:
# ('Linux', 'lasersaur', '3.8.13-bone20',
# '#1 SMP Wed May 29 06:14:59 UTC 2013', 'armv7l')
Expand Down Expand Up @@ -180,24 +187,28 @@
for pin46 in pin46list:
os.system("echo gpio > %s" % (pin46))

try:
fw = file("/sys/class/gpio/export", "w")
fw.write("%d" % (71))
if ('GPIO' in globals()):
GPIO.setup("P8_46", GPIO.OUT)
GPIO.output("P8_46", GPIO.HIGH)
else:
try:
fw = file("/sys/class/gpio/export", "w")
fw.write("%d" % (71))
fw.close()
except IOError:
# probably already exported
pass
# set the gpio pin to output
# echo out > /sys/class/gpio/gpio71/direction
fw = file("/sys/class/gpio/gpio71/direction", "w")
fw.write("out")
fw.close()
# set the gpio pin high
# echo 1 > /sys/class/gpio/gpio71/value
fw = file("/sys/class/gpio/gpio71/value", "w")
fw.write("1")
fw.flush()
fw.close()
except IOError:
# probably already exported
pass
# set the gpio pin to output
# echo out > /sys/class/gpio/gpio71/direction
fw = file("/sys/class/gpio/gpio71/direction", "w")
fw.write("out")
fw.close()
# set the gpio pin high
# echo 1 > /sys/class/gpio/gpio71/value
fw = file("/sys/class/gpio/gpio71/value", "w")
fw.write("1")
fw.flush()
fw.close()

### Set up atmega328 reset control - BeagleBone Black
# The reset pin is connected to GPIO2_9 (2*32+9 = 73).
Expand All @@ -209,24 +220,28 @@
for pin44 in pin44list:
os.system("echo gpio > %s" % (pin44))

try:
fw = file("/sys/class/gpio/export", "w")
fw.write("%d" % (73))
if ('GPIO' in globals()):
GPIO.setup("P8_44", GPIO.OUT)
GPIO.output("P8_44", GPIO.HIGH)
else:
try:
fw = file("/sys/class/gpio/export", "w")
fw.write("%d" % (73))
fw.close()
except IOError:
# probably already exported
pass
# set the gpio pin to output
# echo out > /sys/class/gpio/gpio73/direction
fw = file("/sys/class/gpio/gpio73/direction", "w")
fw.write("out")
fw.close()
# set the gpio pin high
# echo 1 > /sys/class/gpio/gpio73/value
fw = file("/sys/class/gpio/gpio73/value", "w")
fw.write("1")
fw.flush()
fw.close()
except IOError:
# probably already exported
pass
# set the gpio pin to output
# echo out > /sys/class/gpio/gpio73/direction
fw = file("/sys/class/gpio/gpio73/direction", "w")
fw.write("out")
fw.close()
# set the gpio pin high
# echo 1 > /sys/class/gpio/gpio73/value
fw = file("/sys/class/gpio/gpio73/value", "w")
fw.write("1")
fw.flush()
fw.close()

### read stepper driver configure pin GPIO2_12 (2*32+12 = 76).
# Low means Geckos, high means SMC11s
Expand All @@ -236,22 +251,26 @@
for pin39 in pin39list:
os.system("echo gpio > %s" % (pin39))

try:
fw = file("/sys/class/gpio/export", "w")
fw.write("%d" % (76))
if ('GPIO' in globals()):
GPIO.setup("P8_39", GPIO.IN)
ret = GPIO.input("P8_39")
else:
try:
fw = file("/sys/class/gpio/export", "w")
fw.write("%d" % (76))
fw.close()
except IOError:
# probably already exported
pass
# set the gpio pin to input
fw = file("/sys/class/gpio/gpio76/direction", "w")
fw.write("in")
fw.close()
# set the gpio pin high
fw = file("/sys/class/gpio/gpio76/value", "r")
ret = fw.read()
fw.close()
except IOError:
# probably already exported
pass
# set the gpio pin to input
fw = file("/sys/class/gpio/gpio76/direction", "w")
fw.write("in")
fw.close()
# set the gpio pin high
fw = file("/sys/class/gpio/gpio76/value", "r")
ret = fw.read()
fw.close()
# print "Stepper driver configure pin is: " + str(ret)
# print "Stepper driver configure pin is: " + str(ret)

elif conf['hardware'] == 'raspberrypi':
if not conf['firmware']:
Expand Down
132 changes: 76 additions & 56 deletions backend/flash.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,39 +86,49 @@ def flash_upload(serial_port=conf['serial_port'], resources_dir=conf['rootdir'],
# Setting it to low triggers a reset.
# echo 71 > /sys/class/gpio/export
try:
fw = file("/sys/class/gpio/export", "w")
fw.write("%d" % (71))
import Adafruit_BBIO.GPIO as GPIO
GPIO.setup("P8_46", GPIO.OUT)
GPIO.output("P8_46", GPIO.LOW)
GPIO.setup("P8_44", GPIO.OUT)
GPIO.output("P8_44", GPIO.LOW)
time.sleep(0.5)
GPIO.output("P8_46", GPIO.HIGH)
GPIO.output("P8_44", GPIO.HIGH)
except ImportError:
try:
fw = file("/sys/class/gpio/export", "w")
fw.write("%d" % (71))
fw.close()
fwb = file("/sys/class/gpio/export", "w")
fwb.write("%d" % (73))
fwb.close()
except IOError:
# probably already exported
pass
# set the gpio pin to output
# echo out > /sys/class/gpio/gpio71/direction
fw = file("/sys/class/gpio/gpio71/direction", "w")
fw.write("out")
fw.close()
fwb = file("/sys/class/gpio/export", "w")
fwb.write("%d" % (73))
fwb = file("/sys/class/gpio/gpio73/direction", "w")
fwb.write("out")
fwb.close()
except IOError:
# probably already exported
pass
# set the gpio pin to output
# echo out > /sys/class/gpio/gpio71/direction
fw = file("/sys/class/gpio/gpio71/direction", "w")
fw.write("out")
fw.close()
fwb = file("/sys/class/gpio/gpio73/direction", "w")
fwb.write("out")
fwb.close()
# set the gpio pin low -> high
# echo 1 > /sys/class/gpio/gpio71/value
fw = file("/sys/class/gpio/gpio71/value", "w")
fw.write("0")
fw.flush()
fwb = file("/sys/class/gpio/gpio73/value", "w")
fwb.write("0")
fwb.flush()
time.sleep(0.5)
fw.write("1")
fw.flush()
fw.close()
fwb.write("1")
fwb.flush()
fwb.close()
time.sleep(0.1)
# set the gpio pin low -> high
# echo 1 > /sys/class/gpio/gpio71/value
fw = file("/sys/class/gpio/gpio71/value", "w")
fw.write("0")
fw.flush()
fwb = file("/sys/class/gpio/gpio73/value", "w")
fwb.write("0")
fwb.flush()
time.sleep(0.5)
fw.write("1")
fw.flush()
fw.close()
fwb.write("1")
fwb.flush()
fwb.close()
time.sleep(0.1)
elif conf['hardware'] == 'raspberrypi':
print "Flashing from Raspberry Pi ..."
import thread
Expand Down Expand Up @@ -148,33 +158,43 @@ def reset_atmega():
print "Resetting Atmega ..."
if conf['hardware'] == 'beaglebone':
try:
fw = file("/sys/class/gpio/export", "w")
fw.write("%d" % (71))
import Adafruit_BBIO.GPIO as GPIO
GPIO.setup("P8_46", GPIO.OUT)
GPIO.output("P8_46", GPIO.LOW)
GPIO.setup("P8_44", GPIO.OUT)
GPIO.output("P8_44", GPIO.LOW)
time.sleep(0.2)
GPIO.output("P8_46", GPIO.HIGH)
GPIO.output("P8_44", GPIO.HIGH)
except ImportError:
try:
fw = file("/sys/class/gpio/export", "w")
fw.write("%d" % (71))
fw.close()
fwb = file("/sys/class/gpio/export", "w")
fwb.write("%d" % (73))
fwb.close()
except IOError:
pass
fw = file("/sys/class/gpio/gpio71/direction", "w")
fw.write("out")
fw.close()
fwb = file("/sys/class/gpio/gpio73/direction", "w")
fwb.write("out")
fwb.close()
fw = file("/sys/class/gpio/gpio71/value", "w")
fw.write("0")
fw.flush()
fwb = file("/sys/class/gpio/gpio73/value", "w")
fwb.write("0")
fwb.flush()
time.sleep(0.2)
fw.write("1")
fw.flush()
fw.close()
fwb = file("/sys/class/gpio/export", "w")
fwb.write("%d" % (73))
fwb.write("1")
fwb.flush()
fwb.close()
except IOError:
pass
fw = file("/sys/class/gpio/gpio71/direction", "w")
fw.write("out")
fw.close()
fwb = file("/sys/class/gpio/gpio73/direction", "w")
fwb.write("out")
fwb.close()
fw = file("/sys/class/gpio/gpio71/value", "w")
fw.write("0")
fw.flush()
fwb = file("/sys/class/gpio/gpio73/value", "w")
fwb.write("0")
fwb.flush()
time.sleep(0.2)
fw.write("1")
fw.flush()
fw.close()
fwb.write("1")
fwb.flush()
fwb.close()
elif conf['hardware'] == 'raspberrypi':
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # use chip pin number
Expand Down
11 changes: 11 additions & 0 deletions scripts/driveboardapp.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Lasersaur driveboardapp
After=network.target

[Service]
Type=simple
Restart=always
ExecStart=/usr/bin/python /root/driveboardapp/backend/app.py

[Install]
WantedBy=multi-user.target