Skip to content

Commit

Permalink
rename iot package to led and add port flag
Browse files Browse the repository at this point in the history
  • Loading branch information
error2215 committed Mar 27, 2022
1 parent 6f009b8 commit 4ad723d
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 54 deletions.
3 changes: 2 additions & 1 deletion cmd/clef/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ func init() {
networkIdFlag,
utils.LightKDFFlag,
utils.NoUSBFlag,
utils.IoTFlag,
utils.LedFlag,
utils.LedGPIOPortFlag,
utils.SmartCardDaemonPathFlag,
utils.HTTPListenAddrFlag,
utils.HTTPVirtualHostsFlag,
Expand Down
13 changes: 7 additions & 6 deletions cmd/gocore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package main

import (
"fmt"
"github.com/core-coin/go-core/core/iot"
"github.com/core-coin/go-core/core/led"
"math"
"os"
"runtime"
Expand Down Expand Up @@ -69,7 +69,8 @@ var (
utils.KeyStoreDirFlag,
utils.ExternalSignerFlag,
utils.NoUSBFlag,
utils.IoTFlag,
utils.LedFlag,
utils.LedGPIOPortFlag,
utils.SmartCardDaemonPathFlag,
utils.TxPoolLocalsFlag,
utils.TxPoolNoLocalsFlag,
Expand Down Expand Up @@ -438,10 +439,10 @@ func startNode(ctx *cli.Context, stack *node.Node) {
}
}

// Enable Pin if iot flag is enabled
if stack.Config().IoT {
if err := iot.EnablePin(); err != nil {
utils.Fatalf("Failed to switch on IoT: %v", err)
// Enable Led if led flag is enabled
if stack.Config().Led {
if err := led.EnableLed(stack.Config().LedGPIOPort); err != nil {
utils.Fatalf("Failed to switch on Led: %v", err)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/gocore/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ var AppHelpFlagGroups = []flagGroup{
utils.AncientFlag,
utils.KeyStoreDirFlag,
utils.NoUSBFlag,
utils.IoTFlag,
utils.LedFlag,
utils.LedGPIOPortFlag,
utils.SmartCardDaemonPathFlag,
utils.NetworkIdFlag,
utils.DevinFlag,
Expand Down
15 changes: 10 additions & 5 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,13 @@ var (
Name: "nousb",
Usage: "Disables monitoring for and managing USB hardware wallets",
}
IoTFlag = cli.BoolFlag{
Name: "iot",
Usage: "Enables Pin to indicate if node is operational",
LedFlag = cli.BoolFlag{
Name: "led",
Usage: "Enables Led to indicate if node is operational",
}
LedGPIOPortFlag = cli.IntFlag{
Name: "led.gpio.port",
Usage: "Led GPIO port number (default = 23)",
}
SmartCardDaemonPathFlag = cli.StringFlag{
Name: "pcscdpath",
Expand Down Expand Up @@ -1185,8 +1189,9 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
if ctx.GlobalIsSet(NoUSBFlag.Name) {
cfg.NoUSB = ctx.GlobalBool(NoUSBFlag.Name)
}
if ctx.GlobalIsSet(IoTFlag.Name) {
cfg.IoT = ctx.GlobalBool(IoTFlag.Name)
if ctx.GlobalIsSet(LedFlag.Name) {
cfg.Led = ctx.GlobalBool(LedFlag.Name)
cfg.LedGPIOPort = ctx.GlobalInt(LedGPIOPortFlag.Name)
}
if ctx.GlobalIsSet(InsecureUnlockAllowedFlag.Name) {
cfg.InsecureUnlockAllowed = ctx.GlobalBool(InsecureUnlockAllowedFlag.Name)
Expand Down
33 changes: 0 additions & 33 deletions core/iot/pin_unix.go

This file was deleted.

44 changes: 44 additions & 0 deletions core/led/led_unix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//+build !windows

package led

import "github.com/stianeikeland/go-rpio/v4"

const (
defautPin = 23
)

func EnableLed(port int) error {
var pin rpio.Pin
if port == 0 {
pin = rpio.Pin(defautPin)
} else {
pin = rpio.Pin(port)
}

err := rpio.Open()
if err != nil {
return err
}

// Switch on
pin.Output()
pin.High()

return nil
}

func DisableLed(port int) error {
var pin rpio.Pin
if port == 0 {
pin = rpio.Pin(defautPin)
} else {
pin = rpio.Pin(port)
}

// Switch off
pin.Output()
pin.Low()

return rpio.Close()
}
2 changes: 1 addition & 1 deletion core/iot/pin_windows.go → core/led/led_windows.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//+build windows

package iot
package led

func EnablePin() error {
return nil
Expand Down
7 changes: 5 additions & 2 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,11 @@ type Config struct {
// NoUSB disables hardware wallet monitoring and connectivity.
NoUSB bool `toml:",omitempty"`

// IoT enables Pin to indicate if node is operational.
IoT bool `toml:",omitempty"`
// Led enables Led to indicate if node is operational.
Led bool `toml:",omitempty"`

// LedGPIOPort is the GPIO port number where to enable led.
LedGPIOPort int `toml:",omitempty"`

// SmartCardDaemonPath is the path to the smartcard daemon's socket
SmartCardDaemonPath string `toml:",omitempty"`
Expand Down
8 changes: 4 additions & 4 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package node
import (
"errors"
"fmt"
"github.com/core-coin/go-core/core/iot"
"github.com/core-coin/go-core/core/led"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -466,9 +466,9 @@ func (n *Node) Stop() error {
// unblock n.Wait
close(n.stop)

// Disable Pin
if n.config.IoT {
if err := iot.DisablePin(); err != nil {
// Disable Led
if n.config.Led {
if err := led.DisableLed(n.config.LedGPIOPort); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
const (
VersionMajor = 1 // Major version component of the current release
VersionMinor = 0 // Minor version component of the current release
VersionPatch = 62 // Patch version component of the current release
VersionPatch = 63 // Patch version component of the current release
VersionMeta = "stable" // Version metadata to append to the version string
)

Expand Down

0 comments on commit 4ad723d

Please sign in to comment.