Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add factory reset button documentation #76

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ func ParseFromFile(configPath string) (*Device, error) {

func ParseFromReader(defConfig *Device, rdr io.Reader) (*Device, error) {
dec := yaml.NewDecoder(rdr)
dec.KnownFields(false)
dec.KnownFields(true)

if err := dec.Decode(defConfig); err != nil {
return nil, fmt.Errorf("unmarshal config: %w", err)
return nil, fmt.Errorf("decode: %w", err)
}

// This may contain environment variables,
Expand Down
17 changes: 17 additions & 0 deletions docs/features/factory_reset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
In some situations it is necessary to have a way to disconnect device from the network it was connected to.

For example:
* Device will be used in different network.
* Previous network is not available (i.e. on configuration change).
* Device was not correctly disconnected from network, resulting in device having network configuration, but network does not accept the device.

To resolve this issues firmware provides a way to set a button that will act as a factory reset button:
```yml
board:
factory_reset_button: btn1
buttons:
- id: btn1
```

To perform a factory reset user needs to hold `btn1` for more than 5 seconds and then release.
After this the device will remove current network configuration and automatically try to pair with any open Zigbee network.
9 changes: 9 additions & 0 deletions examples/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ func TestGenerateAllExamples(t *testing.T) {
}
}

// This test will generate the configuration from the repository root.
// Hopefuly resulting in less issues and up-to-date configuration.
func TestGenerateRootConfiguration(t *testing.T) {
cwdAbsPath, err := filepath.Abs("./../")
require.NoError(t, err)

runExample(t, cwdAbsPath)
}

func runExample(t *testing.T, exampleDir string) {
// FIXME: This is needed for config parser to
// resolve includes in config files.
Expand Down
6 changes: 3 additions & 3 deletions types/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ func (p *Pin) UnmarshalYAML(value *yaml.Node) error {

matches := pinRegex.FindStringSubmatch(value.Value)
if matches == nil {
return fmt.Errorf("pin definition must be in a form of X.XX, where X is a number")
return fmt.Errorf("pin definition must be in a form of X.XX, where X is a number, but got: %q", value.Value)
}

port, err := strconv.ParseUint(matches[1], 10, 8)
if err != nil {
return fmt.Errorf("pin's port is invalid: %w", err)
return fmt.Errorf("pin's port %q is invalid: %w", matches[1], err)
}

pin, err := strconv.ParseUint(matches[2], 10, 8)
if err != nil {
return fmt.Errorf("pin's pin is invalid: %w", err)
return fmt.Errorf("pin's pin %q is invalid: %w", matches[2], err)
}

p.Port = NewOption(uint8(port))
Expand Down
27 changes: 24 additions & 3 deletions zigbee.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ board:
# to be selected one, even if the value is empty string.
#bootloader: nrf52_legacy

# This will make "btn1" factory reset button.
# Pressing this button for at least 5 seconds
# would remove current network configuration,
# allowing it to be connected to another network.
factory_reset_button: btn1

# This option will add UART loging functionality.
# User can choose which console to use(usb or uart).
# UART has to be defined either in default device tree,
Expand Down Expand Up @@ -85,6 +91,20 @@ board:
# By default device will be configured as sleepy end device.
# Note: Enabling router will increase the size of the firmware.
is_router: false
# Buttons is optional, to provide information about available buttons on the board.
# Available button is not necessary a physical button, but can also be a pin.
buttons:
# If only ID is provided it means that this button is already present in board definition,
# and it will be just referenced from it.
- id: btn1
# Button can also have a pin, which will create new "button" on specified pin.
# To make it active-low - set "inverted" configuration option to "true".
- id: btn2
pin:
port: 0
pin: 18
inverted: true

# I2C is optional, only to provide different pins for i2c instance(s)
i2c:
# ID of instance is the same as defined in the SoC definition.
Expand All @@ -104,9 +124,10 @@ board:
leds:
- id: led_green
# The pin definition is optional, if led is already present in board definition.
port: 0
pin: 6
inverted: true
pin:
port: 0
pin: 6
inverted: true

sensors:
# - type: bme680
Expand Down