From 4ad723dc0f96ecbdac05d45832dd625db688624d Mon Sep 17 00:00:00 2001 From: error2215 Date: Sun, 27 Mar 2022 21:48:23 +0200 Subject: [PATCH] rename iot package to led and add port flag --- cmd/clef/main.go | 3 +- cmd/gocore/main.go | 13 +++--- cmd/gocore/usage.go | 3 +- cmd/utils/flags.go | 15 ++++--- core/iot/pin_unix.go | 33 -------------- core/led/led_unix.go | 44 +++++++++++++++++++ .../pin_windows.go => led/led_windows.go} | 2 +- node/config.go | 7 ++- node/node.go | 8 ++-- params/version.go | 2 +- 10 files changed, 76 insertions(+), 54 deletions(-) delete mode 100644 core/iot/pin_unix.go create mode 100644 core/led/led_unix.go rename core/{iot/pin_windows.go => led/led_windows.go} (89%) diff --git a/cmd/clef/main.go b/cmd/clef/main.go index 9103872f5..bf44c4b1e 100644 --- a/cmd/clef/main.go +++ b/cmd/clef/main.go @@ -221,7 +221,8 @@ func init() { networkIdFlag, utils.LightKDFFlag, utils.NoUSBFlag, - utils.IoTFlag, + utils.LedFlag, + utils.LedGPIOPortFlag, utils.SmartCardDaemonPathFlag, utils.HTTPListenAddrFlag, utils.HTTPVirtualHostsFlag, diff --git a/cmd/gocore/main.go b/cmd/gocore/main.go index ae07e2fca..8c0d8352a 100644 --- a/cmd/gocore/main.go +++ b/cmd/gocore/main.go @@ -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" @@ -69,7 +69,8 @@ var ( utils.KeyStoreDirFlag, utils.ExternalSignerFlag, utils.NoUSBFlag, - utils.IoTFlag, + utils.LedFlag, + utils.LedGPIOPortFlag, utils.SmartCardDaemonPathFlag, utils.TxPoolLocalsFlag, utils.TxPoolNoLocalsFlag, @@ -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) } } } diff --git a/cmd/gocore/usage.go b/cmd/gocore/usage.go index db8eb45b6..14aecfc85 100644 --- a/cmd/gocore/usage.go +++ b/cmd/gocore/usage.go @@ -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, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 728f3eacb..ef828d1f5 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -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", @@ -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) diff --git a/core/iot/pin_unix.go b/core/iot/pin_unix.go deleted file mode 100644 index 8ee48dc68..000000000 --- a/core/iot/pin_unix.go +++ /dev/null @@ -1,33 +0,0 @@ -//+build !windows - -package iot - -import "github.com/stianeikeland/go-rpio/v4" - -const ( - pin = 23 -) - -func EnablePin() error { - err := rpio.Open() - if err != nil { - return err - } - pin := rpio.Pin(pin) - - // Switch on - pin.Output() - pin.High() - - return nil -} - -func DisablePin() error { - pin := rpio.Pin(pin) - - // Switch off - pin.Output() - pin.Low() - - return rpio.Close() -} diff --git a/core/led/led_unix.go b/core/led/led_unix.go new file mode 100644 index 000000000..a52b70d06 --- /dev/null +++ b/core/led/led_unix.go @@ -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() +} diff --git a/core/iot/pin_windows.go b/core/led/led_windows.go similarity index 89% rename from core/iot/pin_windows.go rename to core/led/led_windows.go index 5ce996493..62adcc7ae 100644 --- a/core/iot/pin_windows.go +++ b/core/led/led_windows.go @@ -1,6 +1,6 @@ //+build windows -package iot +package led func EnablePin() error { return nil diff --git a/node/config.go b/node/config.go index 3679f1f55..68d995537 100644 --- a/node/config.go +++ b/node/config.go @@ -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"` diff --git a/node/node.go b/node/node.go index 2359e04eb..de5823d38 100644 --- a/node/node.go +++ b/node/node.go @@ -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" @@ -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 } } diff --git a/params/version.go b/params/version.go index 5688ff4e2..057b0dc83 100644 --- a/params/version.go +++ b/params/version.go @@ -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 )