Commit 0a4a89a7 authored by Nelso Jost's avatar Nelso Jost

FIX: firmware management with pio setup

parent 00dcf548
.pio
.venv/
*.pyc
*.swp
......
BOARD := uno
PROJDIR := meteorolog
PIOSETUP := python ../utils/piosetup.py
PIODIR := .pio
.PHONY: monitor uno due nano mega clean
all:
$(MAKE) $(BOARD)
uno:
$(PIOSETUP) --board uno --project-dir $(PROJDIR) --pio-dir $(PIODIR)
$(MAKE) monitor
due:
$(PIOSETUP) --board diecimilaatmega328 --pio-dir $(PIODIR)
nano:
$(PIOSETUP) --board nanoatmega328 --pio-dir $(PIODIR)
mega:
$(PIOSETUP) --board megaatmega2560 --pio-dir $(PIODIR)
monitor:
python3 ../utils/qtsermon.py --baud $(shell $(GET_BAUD))
picocom:
picocom --baud $(shell $(GET_BAUD)) $(shell $(GET_PORT))
clean:
rm -rf .pio .travis.yml
define GET_BAUD
cat $(PROJDIR)/*.ino | grep '^#define BAUDRATE' | awk '{print $$3}'
endef
define GET_PORT
platformio device list | head -1
endef
......@@ -8,12 +8,14 @@
#include "mysensors.h"
#include "boardcommands.h"
#define BAUDRATE 9600
String stream_line;
void setup()
{
Serial.begin(9600);
Serial.begin(BAUDRATE);
mysensors_setup();
}
......
import PyQt5.Qt as qt
import argparse
import serial
import time
import os
class MainWindow(qt.QMainWindow):
def __init__(self, baud, port=None):
''' Initialize UI.
baud (int) -- serial baud rate
port (str|None) -- serial port str name;
if None, will try to auto-find
'''
super().__init__()
self.init_serial(baud, port)
self.setupUi()
self.timer = qt.QTimer()
self.timer.timeout.connect(self.read_serial)
self.timer.start(10);
def setupUi(self):
self.center_widget = qt.QWidget(parent=self)
self.edit_input = qt.QLineEdit()
self.edit_input.returnPressed.connect(self.write_serial)
self.edit_output = qt.QTextEdit()
layout = qt.QVBoxLayout()
layout.addWidget(self.edit_input)
layout.addWidget(self.edit_output)
self.center_widget.setLayout(layout)
self.setCentralWidget(self.center_widget)
self.status_bar = qt.QStatusBar()
self.setStatusBar(self.status_bar)
self.setFixedWidth(500)
self.setGeometry(700, 200, 800, 600)
def init_serial(self, baud, port=None):
''' Attempt to create a PySerial connection.
Port is either argparsed or the auto-find get_port() result
Baud is argparse mandatory
'''
try:
port = port or self.get_serial_port()
self.serial = serial.Serial(port, baud, timeout=0.1)
except Exception as e:
print("Unable to initiate serial monitoring at '{}'".format(port))
time.sleep(0.1)
print(self.serial)
def get_serial_port(self):
try:
print('Trying to find ttyUSB|ttyACM port automatically..')
ports = [x for x in os.listdir("/dev")
if x.startswith("ttyUSB") or x.startswith("ttyACM")]
print('Got: {}'.format(' | '.join(ports)))
return '/dev/' + ports[0]
except Exception as e:
print("Error: Unable to find a ttyUSB/ttyACM serial port")
raise SystemExit(1)
def read_serial(self):
if self.serial.in_waiting:
raw = self.serial.readall()
print(raw)
self.edit_output.append(raw.decode('ASCII')[:-2])
def write_serial(self):
self.serial.write(bytes(self.edit_input.text(), encoding='UTF-8'))
self.edit_input.clear()
def keyPressEvent(self, event):
if event.key() == qt.Qt.Key_Escape:
self.close()
@classmethod
def run(cls, baud, port=None):
app = qt.QApplication([])
window = cls(baud, port)
window.show()
app.exec_()
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='''\
Utility for monitoring serial port in a Arduino IDE like manner''')
parser.add_argument('-p', '--port')
parser.add_argument('-b', '--baud', required=True)
args = vars(parser.parse_args())
MainWindow.run(**args)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment