-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathreenable-light.hpp
More file actions
38 lines (31 loc) · 838 Bytes
/
reenable-light.hpp
File metadata and controls
38 lines (31 loc) · 838 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#pragma once
#include "state.hpp"
#include "protocol.h"
bool reenableLightsAfterError = false;
static uint8_t reenableLightTimeout = 0;
static bool lightShouldBeOn = false;
void internalSetLight(bool shouldBeOn)
{
reenableLightTimeout = 20;
lightShouldBeOn = shouldBeOn;
setLight(shouldBeOn);
setLight(shouldBeOn);
setLight(shouldBeOn);
}
void reenableLightLoop(docgreen_status_t& scooterStatus)
{
if(!reenableLightsAfterError)
return;
if(reenableLightTimeout > 0)
reenableLightTimeout--;
if(scooterStatus.buttonPress)
reenableLightTimeout = 20;
if(lightShouldBeOn && !scooterStatus.lights && reenableLightTimeout == 0)
{
setLight(true);
}
else if(scooterStatus.lights != lightShouldBeOn)
{
lightShouldBeOn = scooterStatus.lights;
}
}