-
Notifications
You must be signed in to change notification settings - Fork 0
/
ta6586.cpp
121 lines (99 loc) · 3.17 KB
/
ta6586.cpp
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
120
121
#ifndef __rolloff_linear_actuator_ta6586__
#define __rolloff_linear_actuator_ta6586__
#include <ESP8266WiFi.h>
#include "motor.h"
#include "config.h"
#include "Arduino_DebugUtils.h"
#include "functions.h"
const char* TA6586_VERSION_ID = "V1.4-esp-wifimanager-magnet-ta6586";
// Check if roof has fully opened or fully closed and turn off relay if so! GG
bool TA6586::isRoofMoving() {
return bool(MotionStopTime != 0);
}
void TA6586::checkRoofMovement() {
if (!isRoofMoving()) {
if (MotionStartTime != 0) {
if ((millis() - MotionStartTime) > ROOF_MOVEMENT_MIN_TIME_MILLIS) {
if (isSwitchOn(SWITCH_OPENED) || isSwitchOn(SWITCH_CLOSED)) {
DEBUG_INFO("Sensors say roof is open or closed: it is not moving...");
}
MotionStopTime = millis();
}
}
} else {
// Roof is moving
// Add some delay for complete roof opening or closure
if ((millis() - MotionStopTime) > ROOF_MOTION_END_DELAY_MILLIS) {
DEBUG_INFO("STOP");
stopCommand();
MotionStopTime = 0;
}
MotionStartTime = 0;
}
}
void TA6586::motorOff() {
DEBUG_INFO("Motor OFF");
// Make sure motors are stopped
// Set both to high to disable motor.
// HIGH means also that LED_BUILTIN will also switch off in case we are using
// LED_BUILTIN for the motor.
digitalWrite(FUNC_DIRECTION_A, HIGH);
digitalWrite(FUNC_ACTIVATION_A, HIGH);
// Set both to high to disable motor.
digitalWrite(FUNC_DIRECTION_B, HIGH);
digitalWrite(FUNC_ACTIVATION_B, HIGH);
MotionStartTime = 0;
MotionStopTime = 0;
}
void TA6586::motorOn() {
DEBUG_INFO("Motor ON");
}
void TA6586::stopCommand() {
motorOff(); // Disable the motor
// digitalWrite(FUNC_BLINKER, LOW);
}
void TA6586::connectCommand() {
// Do nothing
}
void TA6586::openCommand() {
DEBUG_INFO("OPEN");
// Blink when opening roof
// digitalWrite(FUNC_BLINKER, HIGH);
// Activate the motor
motorOn();
// Set actuator voltage leads to open actuator
// Use PWM to allow different speeds on each motor.
analogWrite(FUNC_DIRECTION_A, map(MOTOR_A_SPEED_FACTOR_OPENING, 0, 100, 0, 255));
// Set actuator in motion
digitalWrite(FUNC_ACTIVATION_A, LOW);
// Use PWM to allow different speeds on each motor.
analogWrite(FUNC_DIRECTION_B, map(MOTOR_B_SPEED_FACTOR_OPENING, 0, 100, 0, 255));
// Set actuator in motion
digitalWrite(FUNC_ACTIVATION_B, LOW);
MotionStartTime = millis();
MotionStopTime = 0;
}
void TA6586::closeCommand() {
DEBUG_INFO("CLOSE");
// Blink when closing roof
// digitalWrite(FUNC_BLINKER, HIGH);
// Activate the motor
motorOn();
// Set actuator voltage leads to open actuator
digitalWrite(FUNC_DIRECTION_A, LOW);
// Use PWM to allow different speeds on each motor.
analogWrite(FUNC_ACTIVATION_A, map(MOTOR_A_SPEED_FACTOR_CLOSING, 0, 100, 0, 255));
// Set actuator voltage leads to open actuator
digitalWrite(FUNC_DIRECTION_B, LOW);
// Use PWM to allow different speeds on each motor.
analogWrite(FUNC_ACTIVATION_B, map(MOTOR_B_SPEED_FACTOR_CLOSING, 0, 100, 0, 255));
MotionStartTime = millis();
MotionStopTime = 0;
}
const char* TA6586::getVersion() {
return TA6586_VERSION_ID;
}
bool TA6586::isStopAllowed() {
return true;
}
#endif