From 9efa3f9074099b0926a7748ca1eaf17fdec9c9c9 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 30 Jul 2024 15:42:35 +0100 Subject: [PATCH] Adds serial port to serial transport Change-type: minor Signed-off-by: Alex Bucknall --- notecard/main.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/notecard/main.go b/notecard/main.go index 3c9e954..8cb2a6d 100644 --- a/notecard/main.go +++ b/notecard/main.go @@ -16,6 +16,8 @@ const ( I2C = "i2c" ) +const SerialDevice = "/dev/tty.usbmodemNOTE1" + type server struct { card *notecard.Context initError error @@ -86,7 +88,14 @@ func setupNotecard(protocol string) (*notecard.Context, error) { } if protocol == Serial { - card, err := notecard.OpenSerial("/dev/tty.usbmodemNOTE1", 9600) + serialPort := getEnv("NOTECARD_SERIAL_DEVICE", SerialDevice) + + baud, err := strconv.Atoi(getEnv("NOTECARD_SERIAL_BAUD", "9600")) + if err != nil { + return nil, fmt.Errorf("error parsing NOTECARD_SERIAL_BAUD: %v", err) + } + + card, err := notecard.OpenSerial(serialPort, baud) if err != nil { return nil, fmt.Errorf("error opening Notecard: %v", err) }