Skip to content

Commit

Permalink
Add battery registry temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
fish-sauce committed Oct 17, 2024
1 parent 4120842 commit 67ba804
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
18 changes: 18 additions & 0 deletions ios/diagnostics/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@ func Reboot(device ios.DeviceEntry) error {
return service.Close()
}

func (diagnosticsConn *Connection) Battery() (IORegistry, error) {
req := map[string]string{"Request": "IORegistry", "EntryClass": "IOPMPowerSource"}
reader := diagnosticsConn.deviceConn.Reader()
bytes, err := diagnosticsConn.plistCodec.Encode(req)
if err != nil {
return IORegistry{}, err
}
err = diagnosticsConn.deviceConn.Send(bytes)
if err != nil {
return IORegistry{}, err
}
response, err := diagnosticsConn.plistCodec.Decode(reader)
if err != nil {
return IORegistry{}, err
}
return diagnosticsfromBytes(response).Diagnostics.IORegistry, nil
}

func (diagnosticsConn *Connection) Reboot() error {
req := rebootRequest{Request: "Restart", WaitForDisconnect: true, DisplayFail: true, DisplayPass: true}
reader := diagnosticsConn.deviceConn.Reader()
Expand Down
13 changes: 9 additions & 4 deletions ios/diagnostics/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ type allDiagnosticsResponse struct {
}

type Diagnostics struct {
GasGauge GasGauge
HDMI HDMI
NAND NAND
WiFi WiFi
GasGauge GasGauge
HDMI HDMI
NAND NAND
WiFi WiFi
IORegistry IORegistry
}

type IORegistry struct {
Temperature int
}

type WiFi struct {
Expand Down
26 changes: 24 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ Usage:
ios zoomtouch (enable | disable | toggle | get) [--force] [options]
ios diskspace [options]
ios batterycheck [options]
ios batteryregistry [options]
ios tunnel start [options] [--pair-record-path=<pairrecordpath>] [--userspace]
ios tunnel ls [options]
ios tunnel stopagent
Expand Down Expand Up @@ -245,6 +246,7 @@ The commands work as following:
ios timeformat (24h | 12h | toggle | get) [--force] [options] Sets, or returns the state of the "time format". iOS 11+ only (Use --force to try on older versions).
ios diskspace [options] Prints disk space info.
ios batterycheck [options] Prints battery info.
ios batteryregistry [options] Prints battery stats.
ios tunnel start [options] [--pair-record-path=<pairrecordpath>] [--enabletun] Creates a tunnel connection to the device. If the device was not paired with the host yet, device pairing will also be executed.
> On systems with System Integrity Protection enabled the argument '--pair-record-path=default' can be used to point to /var/db/lockdown/RemotePairing/user_501.
> If nothing is specified, the current dir is used for the pair record.
Expand Down Expand Up @@ -962,6 +964,11 @@ The commands work as following:
}
}

b, _ = arguments.Bool("batteryregistry")
if b {
printBatteryRegistry(device)
}

b, _ = arguments.Bool("reboot")
if b {
err := diagnostics.Reboot(device)
Expand Down Expand Up @@ -1622,8 +1629,8 @@ func startAx(device ios.DeviceEntry, arguments docopt.Opts) {
/* conn.GetElement()
time.Sleep(time.Second)
conn.TurnOff()*/
//conn.GetElement()
//conn.GetElement()
// conn.GetElement()
// conn.GetElement()

exitIfError("ax failed", err)
}()
Expand Down Expand Up @@ -1739,6 +1746,21 @@ func printBatteryDiagnostics(device ios.DeviceEntry) {
fmt.Println(convertToJSONString(battery))
}

func printBatteryRegistry(device ios.DeviceEntry) {
conn, err := diagnostics.New(device)
if err != nil {
exitIfError("failed diagnostics service", err)
}
defer conn.Close()

stats, err := conn.Battery()
if err != nil {
exitIfError("failed to get battery stats", err)
}

fmt.Println(convertToJSONString(stats))
}

func printDeviceDate(device ios.DeviceEntry) {
allValues, err := ios.GetValues(device)
exitIfError("failed getting values", err)
Expand Down

0 comments on commit 67ba804

Please sign in to comment.