Skip to content

Commit

Permalink
Fix leptond errors with bad pixel
Browse files Browse the repository at this point in the history
  • Loading branch information
CameronRP committed Apr 27, 2022
1 parent a009e98 commit 410e396
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
4 changes: 3 additions & 1 deletion _release/postinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ systemctl daemon-reload

systemctl enable thermal-recorder.service
systemctl enable leptond.service
systemctl restart leptond.service
systemctl stop leptond.service
systemctl restart thermal-recorder.service
sleep 1
systemctl start leptond.service
10 changes: 8 additions & 2 deletions cmd/leptond/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func runMain() error {
}

for {
err = runCamera(conf, camera, conn)
err = runCamera(conf, camera, conn, service)
if err != nil {
if _, isNextFrameErr := err.(*nextFrameErr); !isNextFrameErr {
return err
Expand Down Expand Up @@ -233,7 +233,7 @@ func sendCameraSpecs(conf *Config, camera *lepton3.Lepton3, conn *net.UnixConn)
return nil
}

func runCamera(conf *Config, camera *lepton3.Lepton3, conn *net.UnixConn) error {
func runCamera(conf *Config, camera *lepton3.Lepton3, conn *net.UnixConn, service *leptondService) error {
conn.SetWriteBuffer(camera.ResX() * camera.ResY() * 2 * 20)
log.Print("reading frames")
frame := lepton3.NewRawFrame()
Expand All @@ -248,6 +248,12 @@ func runCamera(conf *Config, camera *lepton3.Lepton3, conn *net.UnixConn) error
notifyCount = 0
}

if service.actions.reset {
service.actions.reset = false
log.Println("reset triggered through service")
return nil
}

if _, err := conn.Write(frame[:]); err != nil {
return err
}
Expand Down
16 changes: 14 additions & 2 deletions cmd/leptond/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ const (

var mu sync.Mutex

type actions struct {
reset bool
}

type leptondService struct {
camera *lepton3.Lepton3
camera *lepton3.Lepton3
actions *actions
}

func startService() (*leptondService, error) {
Expand All @@ -49,7 +54,7 @@ func startService() (*leptondService, error) {
if reply != dbus.RequestNameReplyPrimaryOwner {
return nil, errors.New("name already taken")
}
s := &leptondService{}
s := &leptondService{actions: &actions{reset: false}}
conn.Export(s, dbusPath, dbusName)
conn.Export(genIntrospectable(s), dbusPath, "org.freedesktop.DBus.Introspectable")
return s, nil
Expand Down Expand Up @@ -101,6 +106,13 @@ func (s leptondService) SetAutoFFC(automatic bool) *dbus.Error {
return nil
}

func (s leptondService) RestartCamera() *dbus.Error {
mu.Lock()
defer mu.Unlock()
s.actions.reset = true
return nil
}

func makeDbusError(name string, err error) *dbus.Error {
return &dbus.Error{
Name: dbusName + "." + name,
Expand Down
4 changes: 2 additions & 2 deletions cmd/thermal-recorder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ func handleConn(conn net.Conn, conf *Config) error {
Details: map[string]interface{}{"description": map[string]interface{}{"details": err.Error()}},
}
eventclient.AddEvent(event)
// this will cause camera power to be cycled
return err
log.Println("bad frame deteccted, requesting camera to restart")
leptondController.RestartCamera()
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions leptondController/leptondController.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ func RunFFC() error {
}
return obj.Call(methodBase+".RunFFC", 0).Store()
}

func RestartCamera() error {
obj, err := getDbusObj()
if err != nil {
return err
}
return obj.Call(methodBase+".RestartCamera", 0).Store()
}

0 comments on commit 410e396

Please sign in to comment.