-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d02de28
commit 47e73a4
Showing
12 changed files
with
362 additions
and
286 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package mk2core | ||
|
||
import ( | ||
"github.com/diebietse/invertergui/mk2driver" | ||
) | ||
|
||
type Core struct { | ||
mk2driver.Mk2 | ||
plugins map[*subscription]bool | ||
register chan *subscription | ||
} | ||
|
||
func NewCore(m mk2driver.Mk2) *Core { | ||
core := &Core{ | ||
Mk2: m, | ||
register: make(chan *subscription, 255), | ||
plugins: map[*subscription]bool{}, | ||
} | ||
go core.run() | ||
return core | ||
} | ||
|
||
func (c *Core) NewSubscription() mk2driver.Mk2 { | ||
sub := &subscription{ | ||
send: make(chan *mk2driver.Mk2Info), | ||
} | ||
c.register <- sub | ||
return sub | ||
} | ||
|
||
func (c *Core) run() { | ||
for { | ||
select { | ||
case r := <-c.register: | ||
c.plugins[r] = true | ||
case e := <-c.C(): | ||
for plugin := range c.plugins { | ||
select { | ||
case plugin.send <- e: | ||
default: | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
type subscription struct { | ||
send chan *mk2driver.Mk2Info | ||
} | ||
|
||
func (s *subscription) C() chan *mk2driver.Mk2Info { | ||
return s.send | ||
} | ||
|
||
func (s *subscription) Close() { | ||
close(s.send) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
|
||
"github.com/diebietse/invertergui/mk2driver" | ||
) | ||
|
||
type Cli struct { | ||
mk2driver.Mk2 | ||
} | ||
|
||
func NewCli(mk2 mk2driver.Mk2) { | ||
newCli := &Cli{ | ||
Mk2: mk2, | ||
} | ||
go newCli.run() | ||
} | ||
|
||
func (c *Cli) run() { | ||
for e := range c.C() { | ||
if e.Valid { | ||
printInfo(e) | ||
} | ||
} | ||
} | ||
|
||
func printInfo(info *mk2driver.Mk2Info) { | ||
out := fmt.Sprintf("Version: %v\n", info.Version) | ||
out += fmt.Sprintf("Bat Volt: %.2fV Bat Cur: %.2fA \n", info.BatVoltage, info.BatCurrent) | ||
out += fmt.Sprintf("In Volt: %.2fV In Cur: %.2fA In Freq %.2fHz\n", info.InVoltage, info.InCurrent, info.InFrequency) | ||
out += fmt.Sprintf("Out Volt: %.2fV Out Cur: %.2fA Out Freq %.2fHz\n", info.OutVoltage, info.OutCurrent, info.OutFrequency) | ||
out += fmt.Sprintf("In Power %.2fW Out Power %.2fW\n", info.InVoltage*info.InCurrent, info.OutVoltage*info.OutCurrent) | ||
out += fmt.Sprintf("Charge State: %.2f%%\n", info.ChargeState*100) | ||
out += "LEDs state:" | ||
for k, v := range info.LEDs { | ||
out += fmt.Sprintf(" %s %s", mk2driver.LedNames[k], mk2driver.StateNames[v]) | ||
} | ||
|
||
out += "\nErrors:" | ||
for _, v := range info.Errors { | ||
out += " " + v.Error() | ||
} | ||
out += "\n" | ||
log.Printf("System Info: \n%v", out) | ||
} |
Oops, something went wrong.