🐛 Fixes peripheral delay on door open
All checks were successful
Gitea Build Action / build (push) Successful in 25s
All checks were successful
Gitea Build Action / build (push) Successful in 25s
This commit is contained in:
parent
100bab01e4
commit
995bf90efb
@ -85,6 +85,7 @@ func makePostReq(url string, body any) ([]byte, error) {
|
||||
}
|
||||
|
||||
req.Header.Set("Authorization", token)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -119,8 +120,8 @@ func main() {
|
||||
Action: test,
|
||||
},
|
||||
{
|
||||
Name: "get",
|
||||
Usage: "get door state",
|
||||
Name: "open",
|
||||
Usage: "get door state (opened or closed)",
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "raw",
|
||||
|
@ -7,7 +7,6 @@ from machine import Pin
|
||||
THRESHOLD_DISTANCE = 15 # cm
|
||||
SOUND_SPEED = 340 * 100 # m/s * centi = cm/s
|
||||
MAX_CONNECTION_RETRIES = 50
|
||||
ULTRA_OPENED_THRESHOLD = 2
|
||||
|
||||
|
||||
class App:
|
||||
@ -18,7 +17,6 @@ class App:
|
||||
|
||||
opened: bool = False
|
||||
previously_opened: bool = False
|
||||
ultra_opened_counter: int = 0
|
||||
|
||||
led = Pin(15, Pin.OUT)
|
||||
trigger = Pin(2, Pin.OUT)
|
||||
@ -146,18 +144,15 @@ class App:
|
||||
|
||||
if not self.opened:
|
||||
self.led.low()
|
||||
self.ultra_opened_counter = 0
|
||||
|
||||
# was it just closed?
|
||||
if self.previously_opened:
|
||||
self.update_server()
|
||||
self.previously_opened = False
|
||||
self.previously_opened = False
|
||||
else:
|
||||
self.led.high()
|
||||
self.ultra_opened_counter += 1
|
||||
|
||||
# was it just opened? +wait delay
|
||||
if self.ultra_opened_counter >= ULTRA_OPENED_THRESHOLD and not self.previously_opened:
|
||||
if not self.previously_opened:
|
||||
self.led.high()
|
||||
self.update_server()
|
||||
self.previously_opened = True
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user