Add support for software reset of the teensy
parent
4a6885e6e4
commit
a26aece61c
|
@ -71,6 +71,11 @@ const int config = WS2811_800kHz; // color config is on the PC side
|
||||||
|
|
||||||
OctoWS2811 leds;
|
OctoWS2811 leds;
|
||||||
|
|
||||||
|
// Required for soft reboot
|
||||||
|
#define RESTART_ADDR 0xE000ED0C
|
||||||
|
#define READ_RESTART() (*(volatile uint32_t *)RESTART_ADDR)
|
||||||
|
#define WRITE_RESTART(val) ((*(volatile uint32_t *)RESTART_ADDR) = (val))
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(13, OUTPUT);
|
pinMode(13, OUTPUT);
|
||||||
digitalWrite(13, HIGH);
|
digitalWrite(13, HIGH);
|
||||||
|
@ -96,7 +101,11 @@ void loop() {
|
||||||
digitalWrite(13, HIGH);
|
digitalWrite(13, HIGH);
|
||||||
leds.show();
|
leds.show();
|
||||||
digitalWrite(13, LOW);
|
digitalWrite(13, LOW);
|
||||||
} else if (startChar >= 0) {
|
}
|
||||||
|
else if (startChar == '!') {
|
||||||
|
WRITE_RESTART(0x5FA0004);
|
||||||
|
}
|
||||||
|
else if (startChar >= 0) {
|
||||||
// discard unknown characters
|
// discard unknown characters
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import redis
|
import redis
|
||||||
import time
|
import time
|
||||||
from serial import Serial, SerialException
|
from serial import Serial, SerialException
|
||||||
|
from serial.tools import list_ports
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -11,7 +12,7 @@ max_width = 20
|
||||||
max_framerate = 40
|
max_framerate = 40
|
||||||
|
|
||||||
# Use dummy to test the Processing code without have access to actual hardware
|
# Use dummy to test the Processing code without have access to actual hardware
|
||||||
serialDevice = 'dummy'
|
# serialDevice = 'dummy'
|
||||||
|
|
||||||
# OSX serial device for teensy (not the same everywhere but gives a good indications what it might look like)
|
# OSX serial device for teensy (not the same everywhere but gives a good indications what it might look like)
|
||||||
# serialDevice = '/dev/tty.usbmodem807701'
|
# serialDevice = '/dev/tty.usbmodem807701'
|
||||||
|
@ -19,6 +20,10 @@ serialDevice = 'dummy'
|
||||||
# Linux Serial device
|
# Linux Serial device
|
||||||
# serialDevice = '/dev/ttyACM0'
|
# serialDevice = '/dev/ttyACM0'
|
||||||
|
|
||||||
|
# Automatically find the first serial port used, works on Linux. TODO: test on other OSes
|
||||||
|
# Required if you want to reboot the teensy
|
||||||
|
serialDevice = 'auto'
|
||||||
|
|
||||||
wait_time = None
|
wait_time = None
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,6 +49,23 @@ def send(r, s):
|
||||||
time.sleep(end - now)
|
time.sleep(end - now)
|
||||||
|
|
||||||
|
|
||||||
|
def reboot(port_name):
|
||||||
|
ser = Serial()
|
||||||
|
ser.port = port_name
|
||||||
|
ser.open()
|
||||||
|
# Send reboot command
|
||||||
|
ser.write(ord('!').to_bytes(4, byteorder='little'))
|
||||||
|
ser.close()
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
|
|
||||||
|
def find_serial():
|
||||||
|
for path, name, details in list_ports.comports():
|
||||||
|
if details != 'n/a':
|
||||||
|
return path
|
||||||
|
raise Exception('No open ports found.')
|
||||||
|
|
||||||
|
|
||||||
def serialConfigure(port_name, baudrate=9600):
|
def serialConfigure(port_name, baudrate=9600):
|
||||||
'''
|
'''
|
||||||
We use a very low baudrate by default because the USB port on the teensy
|
We use a very low baudrate by default because the USB port on the teensy
|
||||||
|
@ -54,6 +76,13 @@ def serialConfigure(port_name, baudrate=9600):
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
ser = 'dummyMode'
|
ser = 'dummyMode'
|
||||||
return ser
|
return ser
|
||||||
|
elif port_name == 'auto':
|
||||||
|
print("Auto detected, search for open port")
|
||||||
|
port_name = find_serial()
|
||||||
|
print("Port found: ", port_name, ' reboot.')
|
||||||
|
reboot(port_name)
|
||||||
|
port_name = find_serial()
|
||||||
|
print("Done, new port: ", port_name)
|
||||||
|
|
||||||
ser = Serial()
|
ser = Serial()
|
||||||
ser.port = port_name
|
ser.port = port_name
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
from serial import Serial, SerialException
|
||||||
|
import sys
|
||||||
|
|
||||||
|
# OSX serial device for teensy (not the same everywhere but gives a good indications what it might look like)
|
||||||
|
# serialDevice = '/dev/tty.usbmodem807701'
|
||||||
|
|
||||||
|
# Linux Serial device
|
||||||
|
serialDevice = '/dev/ttyACM1'
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
ser = Serial()
|
||||||
|
ser.port = serialDevice
|
||||||
|
try:
|
||||||
|
ser.open()
|
||||||
|
ser.timeout = 1
|
||||||
|
ser.write(ord('!').to_bytes(4, byteorder='little'))
|
||||||
|
except SerialException as e:
|
||||||
|
sys.stderr.write("Could not open serial port %s: %s\n" % (ser.portstr, e))
|
Loading…
Reference in New Issue