Skip to content

Commit

Permalink
Adds serial port to serial transport
Browse files Browse the repository at this point in the history
Change-type: minor
Signed-off-by: Alex Bucknall <[email protected]>
  • Loading branch information
Bucknalla committed Jul 30, 2024
1 parent 1822dbd commit 00c2bef
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion notecard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const (
I2C = "i2c"
)

const defaultSerialDevice = "/dev/tty.usbmodemNOTE1"
const defaultSerialBaud = "9600"

type server struct {
card *notecard.Context
initError error
Expand Down Expand Up @@ -86,7 +89,14 @@ func setupNotecard(protocol string) (*notecard.Context, error) {
}

if protocol == Serial {
card, err := notecard.OpenSerial("/dev/tty.usbmodemNOTE1", 9600)
serialPort := getEnv("NOTECARD_SERIAL_DEVICE", defaultSerialDevice)

baud, err := strconv.Atoi(getEnv("NOTECARD_SERIAL_BAUD", defaultSerialBaud))
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)
}
Expand Down

0 comments on commit 00c2bef

Please sign in to comment.