mirror of
https://github.com/wisplite/parchment.git
synced 2026-06-27 13:47:08 -05:00
updated the app to use tview because the bubbletea code was unmaintainable
This commit is contained in:
@@ -10,8 +10,8 @@ import (
|
||||
|
||||
// Device manages the serial connection to the Cardputer.
|
||||
type Device struct {
|
||||
PortName string
|
||||
Port serial.Port
|
||||
PortName string
|
||||
Port serial.Port
|
||||
Connected bool
|
||||
}
|
||||
|
||||
@@ -59,9 +59,22 @@ func (d *Device) Connect() error {
|
||||
d.Close()
|
||||
return fmt.Errorf("failed to send dev mode request: %w", err)
|
||||
}
|
||||
|
||||
// Allow some time for the device to respond or settle if needed
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
// Allow some time for the device to respond or settle if needed
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// ExitDevMode sends the command to exit dev mode.
|
||||
func (d *Device) ExitDevMode() error {
|
||||
if !d.Connected || d.Port == nil {
|
||||
return fmt.Errorf("device not connected")
|
||||
}
|
||||
|
||||
// Send exit dev mode command
|
||||
// TODO: Replace with the actual command sequence to exit dev mode
|
||||
// This is currently not implemented on the Cardputer side.
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -69,6 +82,12 @@ func (d *Device) Connect() error {
|
||||
// Close closes the serial port.
|
||||
func (d *Device) Close() error {
|
||||
if d.Port != nil {
|
||||
// Try to exit dev mode before closing
|
||||
_ = d.ExitDevMode()
|
||||
|
||||
// Allow some time for the command to be processed
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
err := d.Port.Close()
|
||||
d.Port = nil
|
||||
d.Connected = false
|
||||
|
||||
Reference in New Issue
Block a user