Skip to content

Commit 54f141e

Browse files
authored
feat: add factory reset button documentation (#76)
1 parent ef533cd commit 54f141e

File tree

5 files changed

+55
-8
lines changed

5 files changed

+55
-8
lines changed

config/device.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ func ParseFromFile(configPath string) (*Device, error) {
9191

9292
func ParseFromReader(defConfig *Device, rdr io.Reader) (*Device, error) {
9393
dec := yaml.NewDecoder(rdr)
94-
dec.KnownFields(false)
94+
dec.KnownFields(true)
9595

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

100100
// This may contain environment variables,

docs/features/factory_reset.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
In some situations it is necessary to have a way to disconnect device from the network it was connected to.
2+
3+
For example:
4+
* Device will be used in different network.
5+
* Previous network is not available (i.e. on configuration change).
6+
* Device was not correctly disconnected from network, resulting in device having network configuration, but network does not accept the device.
7+
8+
To resolve this issues firmware provides a way to set a button that will act as a factory reset button:
9+
```yml
10+
board:
11+
factory_reset_button: btn1
12+
buttons:
13+
- id: btn1
14+
```
15+
16+
To perform a factory reset user needs to hold `btn1` for more than 5 seconds and then release.
17+
After this the device will remove current network configuration and automatically try to pair with any open Zigbee network.

examples/examples_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ func TestGenerateAllExamples(t *testing.T) {
3434
}
3535
}
3636

37+
// This test will generate the configuration from the repository root.
38+
// Hopefuly resulting in less issues and up-to-date configuration.
39+
func TestGenerateRootConfiguration(t *testing.T) {
40+
cwdAbsPath, err := filepath.Abs("./../")
41+
require.NoError(t, err)
42+
43+
runExample(t, cwdAbsPath)
44+
}
45+
3746
func runExample(t *testing.T, exampleDir string) {
3847
// FIXME: This is needed for config parser to
3948
// resolve includes in config files.

types/pin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,17 @@ func (p *Pin) UnmarshalYAML(value *yaml.Node) error {
108108

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

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

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

124124
p.Port = NewOption(uint8(port))

zigbee.yaml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ board:
5656
# to be selected one, even if the value is empty string.
5757
#bootloader: nrf52_legacy
5858

59+
# This will make "btn1" factory reset button.
60+
# Pressing this button for at least 5 seconds
61+
# would remove current network configuration,
62+
# allowing it to be connected to another network.
63+
factory_reset_button: btn1
64+
5965
# This option will add UART loging functionality.
6066
# User can choose which console to use(usb or uart).
6167
# UART has to be defined either in default device tree,
@@ -85,6 +91,20 @@ board:
8591
# By default device will be configured as sleepy end device.
8692
# Note: Enabling router will increase the size of the firmware.
8793
is_router: false
94+
# Buttons is optional, to provide information about available buttons on the board.
95+
# Available button is not necessary a physical button, but can also be a pin.
96+
buttons:
97+
# If only ID is provided it means that this button is already present in board definition,
98+
# and it will be just referenced from it.
99+
- id: btn1
100+
# Button can also have a pin, which will create new "button" on specified pin.
101+
# To make it active-low - set "inverted" configuration option to "true".
102+
- id: btn2
103+
pin:
104+
port: 0
105+
pin: 18
106+
inverted: true
107+
88108
# I2C is optional, only to provide different pins for i2c instance(s)
89109
i2c:
90110
# ID of instance is the same as defined in the SoC definition.
@@ -104,9 +124,10 @@ board:
104124
leds:
105125
- id: led_green
106126
# The pin definition is optional, if led is already present in board definition.
107-
port: 0
108-
pin: 6
109-
inverted: true
127+
pin:
128+
port: 0
129+
pin: 6
130+
inverted: true
110131

111132
sensors:
112133
# - type: bme680

0 commit comments

Comments
 (0)