🐛 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("Authorization", token)
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
res, err := http.DefaultClient.Do(req)
|
res, err := http.DefaultClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -119,8 +120,8 @@ func main() {
|
|||||||
Action: test,
|
Action: test,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "get",
|
Name: "open",
|
||||||
Usage: "get door state",
|
Usage: "get door state (opened or closed)",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "raw",
|
Name: "raw",
|
||||||
|
@ -7,7 +7,6 @@ from machine import Pin
|
|||||||
THRESHOLD_DISTANCE = 15 # cm
|
THRESHOLD_DISTANCE = 15 # cm
|
||||||
SOUND_SPEED = 340 * 100 # m/s * centi = cm/s
|
SOUND_SPEED = 340 * 100 # m/s * centi = cm/s
|
||||||
MAX_CONNECTION_RETRIES = 50
|
MAX_CONNECTION_RETRIES = 50
|
||||||
ULTRA_OPENED_THRESHOLD = 2
|
|
||||||
|
|
||||||
|
|
||||||
class App:
|
class App:
|
||||||
@ -18,7 +17,6 @@ class App:
|
|||||||
|
|
||||||
opened: bool = False
|
opened: bool = False
|
||||||
previously_opened: bool = False
|
previously_opened: bool = False
|
||||||
ultra_opened_counter: int = 0
|
|
||||||
|
|
||||||
led = Pin(15, Pin.OUT)
|
led = Pin(15, Pin.OUT)
|
||||||
trigger = Pin(2, Pin.OUT)
|
trigger = Pin(2, Pin.OUT)
|
||||||
@ -146,18 +144,15 @@ class App:
|
|||||||
|
|
||||||
if not self.opened:
|
if not self.opened:
|
||||||
self.led.low()
|
self.led.low()
|
||||||
self.ultra_opened_counter = 0
|
|
||||||
|
|
||||||
# was it just closed?
|
# was it just closed?
|
||||||
if self.previously_opened:
|
if self.previously_opened:
|
||||||
self.update_server()
|
self.update_server()
|
||||||
self.previously_opened = False
|
self.previously_opened = False
|
||||||
else:
|
else:
|
||||||
self.led.high()
|
|
||||||
self.ultra_opened_counter += 1
|
|
||||||
|
|
||||||
# was it just opened? +wait delay
|
# 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.update_server()
|
||||||
self.previously_opened = True
|
self.previously_opened = True
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user