Automatic Curtain  MVP
Software repository for an automatic curtain using stepper motor, TMC2209 and ESP32
config.h
Go to the documentation of this file.
1 
14 #ifndef _CONFIG_INCLUDE_GUARD
15 #define _CONFIG_INCLUDE_GUARD
16 
17 #include <Arduino.h>
18 
19 #include <chrono>
20 #include <cstdint>
21 #include <deque>
22 #include <iostream>
23 
28 namespace CONFIG_SET {
29 
30 const int LOGGING_BAUD_RATE = 115200;
31 const int MOTOR_DRIVER_BAUD_RATE = 115200;
32 const int TRY_RECONNECT = 3; // 3 seconds
33 const int MAX_SECONDS_LOST_WIFI = 600; // 10 mins
34 const std::string STORAGE_NAMESPACE = "madac";
35 
36 // Vars For Indicator Class
37 const int NUMBER_OF_LEDS = 1;
38 const int LED_BRIGHTNESS = 25;
39 
40 // Freq var for Manual Interaction Class
41 const int DEQUE_ANALYZER_FREQ = 2;
42 
43 /*
44 ****** STORAGE KEYS ******
45 These keys are used by Storage class to retrieve the data from FLASHs
46 */
47 const std::string KEY_SSID = "ssid";
48 const std::string KEY_PASSWORD = "password";
49 const std::string KEY_DEVICE_ID = "deviceID";
50 const std::string KEY_TOTAL_STEP_COUNT = "totalStepCount";
51 const std::string KEY_DIRECTION = "direction";
52 const std::string KEY_MODE = "mode";
53 const String DEFAULT_DEVICE_ID = "madac_blinds";
54 
55 /*
56 ****** MOTOR DRIVER CALIBRATION PARAMETERS ******
57 */
58 const float MOTOR_DRIVER_R_SENSE = 0.11f;
59 const uint8_t MOTOR_DRIVER_ADDRESS = 0b00;
60 const uint8_t MOTOR_DRIVER_TOFF = 4;
61 const uint8_t MOTOR_DRIVER_BLANK_TIME = 24;
62 const uint16_t MOTOR_DRIVER_RMS_CURRENT = 2000;
63 const uint16_t MOTOR_DRIVER_MICROSTEP = 16;
64 const uint32_t MOTOR_DRIVER_TCOOL_THRS = 0xFFFFF;
65 const uint8_t MOTOR_DRIVER_SE_MIN = 0;
66 const uint8_t MOTOR_DRIVER_SE_MAX = 2;
67 const uint8_t MOTOR_DRIVER_SEDN = 0b01;
68 const uint32_t MOTOR_DRIVER_MAX_SPEED = 5000;
69 const int MOTOR_DRIVER_SG_THRESH = 45;
70 const int MOTOR_STOP_TIME_SEC = 120; // 2 mins
71 const float STEP_FRACTION_ALLOWANCE = 0.05; // 5% Allowance allowed for motor reaching destination
72 const int MODE_EXPIRE_TIME_LIMIT = 300; // 5 mins
73 const int WIFI_DISCONNECT_RESTART_TIME_LIMIT = 60; // 1 mins
74 
75 enum class OPERATION_MODE {
76  RESET,
78  USER,
79  NA,
80 };
81 
82 /*
83 ****** ESP32 PINS ******
84 These are hardware ESP32 pin number where each external pin/component is
85 connected
86 PIN_RGB_LED -> RGB LED WS2812
87 PIN_BUTTON_UP -> Up button
88 PIN_BUTTON_DOWN -> Down button
89 
90 Motor Driver (TMC2209) Pins
91 PIN_MD_ENABLE -> Enable
92 PIN_MD_RX -> Serial Receiver
93 PIN_MD_TX -> Serial Transmitter
94 PIN_MD_MS1 -> MS1
95 PIN_MD_MS2 -> MS2
96 PIN_MD_STEP -> Step
97 PIN_MD_DIR -> Dir
98 PIN_MD_INDEX -> Index
99 PIN_MD_DIAG -> Diag (Stall)
100 */
101 const int PIN_RGB_LED = 32;
102 static const int PIN_BUTTON_UP = 33;
103 static const int PIN_BUTTON_DOWN = 25;
104 const int PIN_MD_ENABLE = 4;
105 const int PIN_MD_RX = 16;
106 const int PIN_MD_TX = 17;
107 const int PIN_MD_MS1 = 5;
108 const int PIN_MD_MS2 = 18;
109 const int PIN_MD_STEP = 22;
110 const int PIN_MD_DIR = 23;
111 const int PIN_MD_INDEX = 21;
112 const int PIN_MD_DIAG = 19;
113 
114 enum class LOG_TYPE {
115  INFO,
116  ERROR,
117  WARN,
118 };
119 
120 enum class LOG_CLASS {
121  CONTROLLER,
122  CONNECTIVITY,
123  INDICATOR,
124  LOGGING,
126  MOTOR_DRIVER,
127  STORAGE,
129 };
130 
131 enum class MANUAL_PUSH {
132  NO_PUSH,
139 };
140 
141 enum class BUTTON_PRESS {
142  NO_PUSH,
143  LONG_PRESS,
144  DOUBLE_TAP,
145 };
146 
147 enum class DEVICE_STATUS {
148  FAULT,
150  RESET_MODE,
152 };
153 
154 enum class DRIVER_STATUS {
155  AVAILABLE,
156  BUSY,
157  IN_ACTIVE,
158 };
159 
161  int PERCENTAGE; // 0, 100 for blind traversal
162 };
163 
164 struct DEVICE_CRED {
165  String DEVICE_ID = "MaD Automatic Blinds";
166  String SSID = "madac_blinds";
167  String PASSWORD = "AutomaticCurtain";
168 };
169 
170 struct CALIB_PARAMS {
171  int TOTAL_STEP_COUNT = INT_MAX;
172  bool DIRECTION = false;
173 };
174 
175 // alias for time variables
176 using time_var = std::chrono::time_point<std::chrono::system_clock>;
177 using current_time = std::chrono::system_clock;
178 
179 } // namespace CONFIG_SET
180 
181 #endif
const uint32_t MOTOR_DRIVER_TCOOL_THRS
Definition: config.h:64
OPERATION_MODE
Definition: config.h:75
const int PIN_MD_DIR
Definition: config.h:110
Namespace to be used for constants/enums.
Definition: config.h:28
const std::string KEY_DIRECTION
Definition: config.h:51
std::chrono::time_point< std::chrono::system_clock > time_var
Definition: config.h:176
static const int PIN_BUTTON_DOWN
Definition: config.h:103
const int PIN_MD_STEP
Definition: config.h:109
const int PIN_MD_MS2
Definition: config.h:108
const int LOGGING_BAUD_RATE
Definition: config.h:30
const int PIN_MD_INDEX
Definition: config.h:111
const uint8_t MOTOR_DRIVER_BLANK_TIME
Definition: config.h:61
const int MOTOR_STOP_TIME_SEC
Definition: config.h:70
const uint8_t MOTOR_DRIVER_SEDN
Definition: config.h:67
const std::string KEY_MODE
Definition: config.h:52
Definition: config.h:160
const uint16_t MOTOR_DRIVER_RMS_CURRENT
Definition: config.h:62
const int LED_BRIGHTNESS
Definition: config.h:38
int PERCENTAGE
Definition: config.h:161
const std::string KEY_DEVICE_ID
Definition: config.h:49
const int MOTOR_DRIVER_SG_THRESH
Definition: config.h:69
const int MOTOR_DRIVER_BAUD_RATE
Definition: config.h:31
Definition: config.h:170
const uint8_t MOTOR_DRIVER_SE_MAX
Definition: config.h:66
const int PIN_MD_DIAG
Definition: config.h:112
const int PIN_MD_MS1
Definition: config.h:107
const uint32_t MOTOR_DRIVER_MAX_SPEED
Definition: config.h:68
const int MAX_SECONDS_LOST_WIFI
Definition: config.h:33
const String DEFAULT_DEVICE_ID
Definition: config.h:53
LOG_TYPE
Definition: config.h:114
const std::string STORAGE_NAMESPACE
Definition: config.h:34
const int MODE_EXPIRE_TIME_LIMIT
Definition: config.h:72
const int PIN_MD_TX
Definition: config.h:106
const uint8_t MOTOR_DRIVER_SE_MIN
Definition: config.h:65
const int PIN_MD_RX
Definition: config.h:105
static const int PIN_BUTTON_UP
Definition: config.h:102
const uint8_t MOTOR_DRIVER_TOFF
Definition: config.h:60
Definition: config.h:164
const float MOTOR_DRIVER_R_SENSE
Definition: config.h:58
const int DEQUE_ANALYZER_FREQ
Definition: config.h:41
const uint16_t MOTOR_DRIVER_MICROSTEP
Definition: config.h:63
LOG_CLASS
Definition: config.h:120
DRIVER_STATUS
Definition: config.h:154
const int PIN_RGB_LED
Definition: config.h:101
const int TRY_RECONNECT
Definition: config.h:32
const std::string KEY_TOTAL_STEP_COUNT
Definition: config.h:50
const float STEP_FRACTION_ALLOWANCE
Definition: config.h:71
MANUAL_PUSH
Definition: config.h:131
const std::string KEY_SSID
Definition: config.h:47
const int WIFI_DISCONNECT_RESTART_TIME_LIMIT
Definition: config.h:73
const uint8_t MOTOR_DRIVER_ADDRESS
Definition: config.h:59
BUTTON_PRESS
Definition: config.h:141
const std::string KEY_PASSWORD
Definition: config.h:48
std::chrono::system_clock current_time
Definition: config.h:177
DEVICE_STATUS
Definition: config.h:147
const int PIN_MD_ENABLE
Definition: config.h:104
const int NUMBER_OF_LEDS
Definition: config.h:37