Add support for software reset of the teensy

master
Raphaël Vinot 2015-04-27 23:40:07 +02:00
parent 4a6885e6e4
commit a26aece61c
3 changed files with 63 additions and 4 deletions

View File

@ -71,6 +71,11 @@ const int config = WS2811_800kHz; // color config is on the PC side
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() {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
@ -96,7 +101,11 @@ void loop() {
digitalWrite(13, HIGH);
leds.show();
digitalWrite(13, LOW);
} else if (startChar >= 0) {
}
else if (startChar == '!') {
WRITE_RESTART(0x5FA0004);
}
else if (startChar >= 0) {
// discard unknown characters
}
}

View File

@ -3,6 +3,7 @@
import redis
import time
from serial import Serial, SerialException
from serial.tools import list_ports
import sys
import os
@ -11,13 +12,17 @@ max_width = 20
max_framerate = 40
# 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)
#serialDevice = '/dev/tty.usbmodem807701'
# serialDevice = '/dev/tty.usbmodem807701'
# 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
@ -44,6 +49,23 @@ def send(r, s):
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):
'''
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)
ser = 'dummyMode'
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.port = port_name

View File

@ -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))