Skip to content

Commit

Permalink
status: add basic looping functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
gerryd committed Oct 20, 2023
1 parent 248871d commit ade54d6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 21 deletions.
7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ module github.com/gerryd/ms213x-status
go 1.19

require (
github.com/BertoldVdb/ms-tools v0.0.0-20221129120332-dd3c7641485a
github.com/BertoldVdb/ms-tools v0.0.0-20231004114646-22ddf782f595
github.com/alecthomas/kong v0.8.0
github.com/sstallion/go-hid v0.14.1
)

require golang.org/x/sys v0.8.0 // indirect
require (
github.com/google/renameio v1.0.1 // indirect
golang.org/x/sys v0.8.0 // indirect
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/BertoldVdb/ms-tools v0.0.0-20221129120332-dd3c7641485a h1:HiNl4aayDj6YwzDHtbcRBX79r8BzCY6gBmGkalPkVuQ=
github.com/BertoldVdb/ms-tools v0.0.0-20221129120332-dd3c7641485a/go.mod h1:jmbR3cRIFTGz2Licvnbx5fv/SG6aLRJHpOILmEKTy5M=
github.com/BertoldVdb/ms-tools v0.0.0-20231004114646-22ddf782f595 h1:dUuC+xTDdNG2kl6WF0O4iJKAzabaKhNfedXrdaz6pQs=
github.com/BertoldVdb/ms-tools v0.0.0-20231004114646-22ddf782f595/go.mod h1:jmbR3cRIFTGz2Licvnbx5fv/SG6aLRJHpOILmEKTy5M=
github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0=
github.com/alecthomas/kong v0.2.17/go.mod h1:ka3VZ8GZNPXv9Ov+j4YNLkI8mTuhXyr/0ktSlqIydQQ=
github.com/alecthomas/kong v0.8.0 h1:ryDCzutfIqJPnNn0omnrgHLbAggDQM2VWHikE1xqK7s=
Expand All @@ -8,6 +10,8 @@ github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/google/renameio v1.0.1 h1:Lh/jXZmvZxb0BBeSY5VKEfidcbcbenKjZFzM/q0fSeU=
github.com/google/renameio v1.0.1/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWUAweKUpk=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/inancgumus/screen v0.0.0-20190314163918-06e984b86ed3/go.mod h1:Ey4uAp+LvIl+s5jRbOHLcZpUDnkjLBROl15fZLwPlTM=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand Down
56 changes: 37 additions & 19 deletions status.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"time"
"encoding/binary"
"encoding/json"
)
Expand All @@ -12,7 +13,9 @@ type Region struct {
}

type StatusCmd struct {
Json bool `optional name:"json" help:"Output JSON instead of the default list."`
Json bool `optional name:"json" help:"Output JSON instead of the default list."`
Loop int `optional name:"loop" help:"Run in a loop and sleep every N microseconds"`
Filename string `optional name:"filename" help:"Output to a file instead of stdout"`
}

type outputData struct {
Expand All @@ -22,29 +25,44 @@ type outputData struct {
}

func (s *StatusCmd) Run(c *Context) error {
output := &outputData{}
next := true

buf := readmem(c, Region { Region: "RAM", Addr: 0x0000e184 }, 2)
output.Width = int(binary.LittleEndian.Uint16(buf))
for next {
output := &outputData{}

buf = readmem(c, Region { Region: "RAM", Addr: 0x0000e18c }, 2)
output.Height = int(binary.LittleEndian.Uint16(buf))
buf := readmem(c, Region { Region: "RAM", Addr: 0x0000e184 }, 2)
output.Width = int(binary.LittleEndian.Uint16(buf))

buf = readmem(c, Region { Region: "RAM", Addr: 0x0000e180 }, 1)
buf = readmem(c, Region { Region: "RAM", Addr: 0x0000e18c }, 2)
output.Height = int(binary.LittleEndian.Uint16(buf))

if (len(buf) > 0 && buf[0] > 0) {
output.Signal = "yes"
} else {
output.Signal = "no"
}
buf = readmem(c, Region { Region: "RAM", Addr: 0x0000e180 }, 1)

if (len(buf) == 0) {

} else if (buf[0] > 0) {
output.Signal = "yes"
} else {
output.Signal = "no"
}

var p = ""

if (s.Json) {
data, _ := json.Marshal(output)
p = string(data)

} else {
p = fmt.Sprintf("width: %d\nheight: %d\nsignal: %s\n", output.Width, output.Height, output.Signal)
}

fmt.Print(p)

if (s.Json) {
data, _ := json.Marshal(output)
fmt.Println(string(data))
} else {
fmt.Printf("width: %d\n", output.Width)
fmt.Printf("height: %d\n", output.Height)
fmt.Printf("signal: %s\n", output.Signal)
if (s.Loop == 0) {
next = false
} else {
time.Sleep(time.Duration(s.Loop) * time.Millisecond)
}
}

return nil
Expand Down

0 comments on commit ade54d6

Please sign in to comment.