-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathMain.h
More file actions
119 lines (102 loc) · 3 KB
/
Main.h
File metadata and controls
119 lines (102 loc) · 3 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* Copyright (C) 2020 Anthony Doud & Joel Baranick
* All rights reserved
*
* SPDX-License-Identifier: GPL-2.0-only
*/
#pragma once
#include "HTTP_Server_Basic.h"
#include "SmartSpin_parameters.h"
#include "BLE_Common.h"
// #include "LittleFS_Upgrade.h"
#include "boards.h"
#include "SensorCollector.h"
#include "SS2KLog.h"
#define MAIN_LOG_TAG "Main"
// Function Prototypes
enum ButtonState {
RELEASED,
PRESSED
};
class SS2K {
private:
unsigned long int lastDebounceTime = 0;
ButtonState upButtonState;
ButtonState downButtonState;
int lastShifterPosition;
int shiftersHoldForScan;
unsigned long int scanDelayTime;
unsigned long int scanDelayStart;
int32_t targetPosition;
int32_t currentPosition;
void handleShiftButtons();
public:
bool stepperIsRunning;
bool externalControl;
bool syncMode;
int txCheck;
bool pelotonIsConnected;
bool rebootFlag = false;
bool saveFlag = false;
bool resetDefaultsFlag = false;
bool resetPowerTableFlag = false;
bool isUpdating = false;
static void ARDUINO_ISR_ATTR maintenanceLoop(void *pvParameters);
static void ARDUINO_ISR_ATTR handleUpShift();
static void ARDUINO_ISR_ATTR handleDownShift();
static void moveStepper();
void _findEndStop(bool moveForward);
void _findFTMSHome(bool bothDirections = false);
void _resistanceMove();
// the position the stepper motor will move to
int32_t getTargetPosition() { return targetPosition; }
void setTargetPosition(int32_t tp) { targetPosition = tp; }
// the position the stepper motor is currently at
int32_t getCurrentPosition() { return currentPosition; }
void setCurrentPosition(int32_t cp) { currentPosition = cp; }
int getLastShifterPosition() { return lastShifterPosition; }
void setLastShifterPosition(int sp) { lastShifterPosition = sp; }
void resetIfShiftersHeld();
void startTasks();
void stopTasks();
void restartWifi();
void setupTMCStepperDriver(bool reset = false);
void updateStepperPower(int pwr = 0);
void updateStealthChop();
void updateStepperSpeed(int speed = 0);
void FTMSModeShiftModifier();
static void rxSerial(void);
void txSerial();
bool pelotonConnected();
void goHome(bool bothDirections = false);
SS2K() {
upButtonState = RELEASED;
downButtonState = RELEASED;
targetPosition = 0;
currentPosition = 0;
stepperIsRunning = false;
externalControl = false;
syncMode = false;
lastShifterPosition = 0;
shiftersHoldForScan = SHIFTERS_HOLD_FOR_SCAN;
scanDelayTime = 10000;
scanDelayStart = 0;
pelotonIsConnected = false;
txCheck = TX_CHECK_INTERVAL;
}
};
class AuxSerialBuffer {
public:
uint8_t data[AUX_BUF_SIZE];
size_t len;
AuxSerialBuffer() {
for (int i = 0; i < AUX_BUF_SIZE; i++) {
this->data[i] = 0;
}
this->len = 0;
}
};
extern SS2K *ss2k;
// Main program variable that stores most everything
extern userParameters *userConfig;
extern RuntimeParameters *rtConfig;