Skip to content

Commit b90d40e

Browse files
author
Björn Schmidt
committed
added system passcode, autolock and offroad auto off
1 parent d107e7e commit b90d40e

File tree

10 files changed

+69
-10
lines changed

10 files changed

+69
-10
lines changed

ACAcommons.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,27 @@ void updatePasStatus(void) {
256256
}
257257
}
258258

259-
void updateOffroadStatus(void) {
260-
259+
void updateSlowLoopStates(void) {
260+
261+
if (ui16_motor_speed_erps == 0) {
262+
ui16_idle_counter++;
263+
} else {
264+
ui16_idle_counter = 0;
265+
}
266+
267+
//disable lock if passcode is 0
268+
if (ui16_passcode == 0){
269+
ui8_lockstatus = 0;
270+
}else if (((ui16_aca_flags & IDLE_LOCKS_CONTROLLER) == IDLE_LOCKS_CONTROLLER) && (ui16_idle_counter > 3000)) {
271+
//lock after 60 seconds idle
272+
ui8_lockstatus = 1;
273+
}
274+
275+
if (((ui16_aca_flags & IDLE_DISABLES_OFFROAD) == IDLE_DISABLES_OFFROAD) && (ui8_offroad_state > 4) && (ui16_idle_counter > 3000)) {
276+
//disable after 60 seconds idle
277+
ui8_offroad_state = 0;
278+
}
279+
261280
if (((ui16_aca_flags & BRAKE_DISABLES_OFFROAD) == BRAKE_DISABLES_OFFROAD) && (ui8_offroad_state > 4)) {
262281
// if disabling is enabled :)
263282
if (!GPIO_ReadInputPin(BRAKE__PORT, BRAKE__PIN)) {

ACAcommons.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ float int2float(uint8_t in, float maxRange);
3030
void setSignal(uint8_t signal);
3131
uint8_t readAndClearSignal(uint8_t signal);
3232
void updateHallOrder(uint8_t hall_sensors);
33-
void updateOffroadStatus(void);
33+
void updateSlowLoopStates(void);
3434
void initErpsRatio(void);
3535
void updateSpeeds(void);
3636
void updatePasStatus(void);

ACAcontrollerState.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ uint16_t ui16_time_ticks_for_speed_calculation = 0; //time tics for speed measur
108108
uint16_t ui16_time_ticks_for_uart_timeout = 0;
109109
uint8_t ui8_SPEED_Flag = 0; //flag for SPEED interrupt
110110
uint8_t ui8_offroad_counter = 0; //counter for offroad switching procedure
111+
uint16_t ui16_idle_counter = 0;
112+
uint16_t ui16_passcode = 0;
113+
uint8_t ui8_lockstatus = 1;
111114

112115
uint16_t ui16_aca_flags = 0;
113116
uint16_t ui16_aca_experimental_flags = 0;
@@ -169,6 +172,10 @@ void controllerstate_init(void) {
169172
eepromVal = eeprom_read(OFFSET_BATTERY_CURRENT_MAX_VALUE);
170173
if (eepromVal > 0 || eepromHighVal > 0) ui16_battery_current_max_value = ((uint16_t) eepromHighVal << 8) + (uint16_t) eepromVal;
171174

175+
eepromHighVal = eeprom_read(OFFSET_PASSCODE_HIGH_BYTE);
176+
eepromVal = eeprom_read(OFFSET_PASSCODE);
177+
if (eepromVal > 0 || eepromHighVal > 0) ui16_passcode = ((uint16_t) eepromHighVal << 8) + (uint16_t) eepromVal;
178+
172179
eepromHighVal = eeprom_read(OFFSET_ACA_FLAGS_HIGH_BYTE);
173180
eepromVal = eeprom_read(OFFSET_ACA_FLAGS);
174181
if (eepromVal > 0 || eepromHighVal > 0) ui16_aca_flags = ((uint16_t) eepromHighVal << 8) + (uint16_t) eepromVal;

ACAcontrollerState.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ extern uint16_t ui16_time_ticks_between_speed_interrupt; //Counter for bike spee
8686
extern uint8_t ui8_SPEED_Flag; //Flag for PAS Interrupt detected
8787
extern uint16_t ui16_time_ticks_between_speed_interrupt; //Speed duration of one wheel revolution (tics * 64us)
8888
extern uint8_t ui8_offroad_counter;
89+
extern uint16_t ui16_idle_counter;
90+
extern uint16_t ui16_passcode;
91+
extern uint8_t ui8_lockstatus;
8992

9093
extern uint16_t ui16_aca_flags;
9194
extern uint16_t ui16_aca_experimental_flags;
@@ -148,7 +151,12 @@ typedef enum {
148151

149152
POWER_BASED_CONTROL= ((uint16_t) 1024),
150153
TQ_SENSOR_MODE = ((uint16_t) 2048),
151-
ANGLE_CORRECTION_ENABLED = ((uint16_t) 4096)
154+
ANGLE_CORRECTION_ENABLED = ((uint16_t) 4096),
155+
156+
IDLE_LOCKS_CONTROLLER = ((uint16_t) 8192),
157+
IDLE_DISABLES_OFFROAD = ((uint16_t) 16384)
158+
159+
152160
} ACA_FLAGS;
153161

154162
typedef enum {

ACAeeprom.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ typedef enum {
7272
OFFSET_ASSIST_PERCENT_LEVEL_5 = ((uint8_t) 0x24),
7373

7474
OFFSET_BATTERY_VOLTAGE_MIN = ((uint8_t) 0x25),
75-
OFFSET_BATTERY_VOLTAGE_MAX = ((uint8_t) 0x26)
75+
OFFSET_BATTERY_VOLTAGE_MAX = ((uint8_t) 0x26),
76+
77+
OFFSET_PASSCODE_HIGH_BYTE = ((uint8_t) 0x27),
78+
OFFSET_PASSCODE = ((uint8_t) 0x28)
7679

7780
} BO_EEPROM_OFFSETS;
7881

BOdisplay.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void addDetailStateInfos(void) {
213213
addPayload(CODE_PAS_COUNTER, ui16_time_ticks_between_pas_interrupt);
214214
addPayload(CODE_VER_SPEED_HIGH_BYTE, ui16_virtual_erps_speed >> 8);
215215
addPayload(CODE_VER_SPEED, ui16_virtual_erps_speed);
216-
216+
addPayload(CODE_LOCKSTATUS, ui8_lockstatus);
217217
// 9 more elements left/avail (max30)
218218
}
219219

@@ -279,6 +279,23 @@ void digestConfigRequest(uint8_t configAddress, uint8_t requestedCodeLowByte, ui
279279
ui8_offroad_state = requestedValue;
280280
addPayload(requestedCodeLowByte, ui8_offroad_state);
281281
break;
282+
case CODE_PASSCODE:
283+
if ((ui8_lockstatus == 0) && (configAddress == EEPROM_ADDRESS)){
284+
// write new passcode only if unlocked
285+
ui16_passcode == ((uint16_t) requestedValueHighByte << 8)+(uint16_t) requestedValue;
286+
eeprom_write(OFFSET_PASSCODE_HIGH_BYTE, requestedValueHighByte);
287+
eeprom_write(OFFSET_PASSCODE, requestedValue);
288+
addPayload(CODE_PASSCODE_HIGH_BYTE, ui16_aca_flags >> 8);
289+
addPayload(requestedCodeLowByte, ui16_aca_flags);
290+
}else if ((ui8_lockstatus == 1) && (configAddress != EEPROM_ADDRESS) && (ui16_passcode == (((uint16_t) requestedValueHighByte << 8)+(uint16_t) requestedValue))){
291+
// unlock if locked and correct code
292+
ui8_lockstatus = 0;
293+
addPayload(CODE_PASSCODE_HIGH_BYTE, ui16_aca_flags >> 8);
294+
addPayload(requestedCodeLowByte, ui16_aca_flags);
295+
}else{
296+
addPayload(CODE_ERROR, CODE_ERROR);
297+
}
298+
break;
282299
case CODE_ACA_FLAGS:
283300
ui16_aca_flags = ((uint16_t) requestedValueHighByte << 8)+(uint16_t) requestedValue;
284301
if (configAddress == EEPROM_ADDRESS) {

BOdisplay.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ typedef enum {
6464
CODE_ASSIST_PERCENT_LEVEL_3 = ((uint8_t) 0xB2),
6565
CODE_ASSIST_PERCENT_LEVEL_4 = ((uint8_t) 0xB3),
6666
CODE_ASSIST_PERCENT_LEVEL_5 = ((uint8_t) 0xB4),
67+
68+
CODE_PASSCODE_HIGH_BYTE = ((uint8_t) 0xBE),
69+
CODE_PASSCODE = ((uint8_t) 0xBF),
6770

6871
CODE_MOTOR_STATE = ((uint8_t) 0xC0),
6972
CODE_BATTERY_VOLTAGE = ((uint8_t) 0xC1),
@@ -112,6 +115,8 @@ typedef enum {
112115

113116
CODE_CURRENT_CAL_B_HIGH_BYTE = ((uint8_t) 0x88),
114117
CODE_CURRENT_CAL_B = ((uint8_t) 0x89),
118+
119+
CODE_LOCKSTATUS = ((uint8_t) 0x83),
115120

116121
CODE_EEPROM_MAGIC_BYTE = ((uint8_t) 0x84),
117122
CODE_MAX_SPEED_DEFAULT = ((uint8_t) 0x85),

config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#define limit_with_throttle_override 25
4242
#define CORRECTION_AT_ANGLE 127
4343
#define PWM_CYCLES_SECOND 15625L
44-
#define DISPLAY_TYPE_KT_LCD3
44+
#define BLUOSEC
4545
#define SPEEDSENSOR_INTERNAL
4646
#define ANGLE_4_0 1
4747
#define ANGLE_6_60 43

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ int main(void) {
158158

159159
checkPasInActivity();
160160
updateRequestedTorque(); //now calculates tq for sensor as well
161-
updateOffroadStatus();
161+
updateSlowLoopStates();
162162

163163
ui16_setpoint = (uint16_t) aca_setpoint(ui16_time_ticks_between_speed_interrupt, ui16_time_ticks_between_pas_interrupt, ui16_setpoint); //update setpoint
164164

test/offRoadTest.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ int kbhit(void) {
7979
return 0;
8080
}
8181

82-
void updateOffroadStatus(void) {
82+
void updateSlowLoopStates(void) {
8383

8484
if (((ui16_aca_flags & BRAKE_DISABLES_OFFROAD) == BRAKE_DISABLES_OFFROAD) && (ui8_offroad_state > 4)) {
8585
// if disabling is enabled :)
@@ -177,7 +177,7 @@ void main() {
177177
nanosleep((const struct timespec[]){
178178
{0, 20000000L}
179179
}, NULL);
180-
updateOffroadStatus();
180+
updateSlowLoopStates();
181181

182182
if (((ui16_aca_flags & BRAKE_DISABLES_OFFROAD) == BRAKE_DISABLES_OFFROAD) && 1 == 1) {
183183
printf(" disabler on ");

0 commit comments

Comments
 (0)