Lydia - Printhead
Main Page
Related Pages
Modules
Classes
Files
File List
File Members
MotorLoad.h
Go to the documentation of this file.
1
#ifndef MOTOR_OVERLOAD_H
2
#define MOTOR_OVERLOAD_H
3
4
#include <Arduino.h>
5
#include <Component.h>
6
#include <macros.h>
7
#include <xmath.h>
8
#include <ModbusValue.h>
9
10
#include "../enums.h"
11
#include "../config.h"
12
13
// test MotorLoad::info <<210;2;64;210:info:1:0>>
14
15
class
MotorLoad
:
public
Component,
public
ModbusValue<int>
16
{
17
public
:
18
enum
MSTATE
19
{
20
NONE
= 0,
21
IDLE
= 1,
22
LOAD
= 2,
23
OVERLOAD
= 2,
24
ERROR
= 3
25
};
26
27
MotorLoad
(Component *_owner,
28
short
_pin,
29
short
_id,
30
int
_addr) :
dt
(0),
31
pin
(_pin),
32
value
(0),
33
lastIdle
(0),
34
lastLoad
(0),
35
lastOverload
(0),
36
currentState
(
NONE
),
37
lastState
(
NONE
),
38
ModbusValue<int>(_addr, MB_FC::MB_FC_READ_REGISTERS),
39
Component(
"MotorLoad"
, _id, Component::COMPONENT_DEFAULT, _owner)
40
{
41
//this->setFlag(OBJECT_RUN_FLAGS::E_OF_DEBUG);
42
SBI(nFlags, OBJECT_NET_CAPS::E_NCAPS_MODBUS);
43
setRegisterMode(MB_REGISTER_MODE::E_MB_REGISTER_MODE_READ);
44
}
45
46
short
overload
()
47
{
48
return
RANGE(abs(
value
),
MOTOR_OVERLOAD_RANGE_MIN
,
MOTOR_OVERLOAD_RANGE_MAX
);
49
}
50
51
short
idle
()
52
{
53
return
RANGE(
value
,
MOTOR_IDLE_LOAD_RANGE_MIN
,
MOTOR_IDLE_LOAD_RANGE_MAX
);
54
}
55
56
short
working
()
57
{
58
return
RANGE(
value
,
MOTOR_LOAD_RANGE_MIN
,
MOTOR_LOAD_RANGE_MAX
);
59
}
60
61
short
setup
()
62
{
63
return
E_OK
;
64
}
65
66
short
loop
()
67
{
68
if
(now - last >
MOTOR_LOAD_READ_INTERVAL
)
69
{
70
value
= analogRead(
pin
);
71
last = now;
72
uchar newState =
NONE
;
73
if
(
idle
())
74
{
75
lastIdle
= now;
76
newState =
IDLE
;
77
}
78
else
if
(
overload
())
79
{
80
Log.errorln(
"MotorLoad::loop - Overload detected : %d"
,
value
);
81
lastOverload
= now;
82
newState =
OVERLOAD
;
83
}
84
else
if
(
working
())
85
{
86
lastLoad
= now;
87
newState =
LOAD
;
88
}
89
90
if
(newState !=
currentState
)
91
{
92
dt
= now;
93
lastState
=
currentState
;
94
currentState
= newState;
95
}
96
onSet(
value
);
97
}
98
return
E_OK
;
99
}
100
101
short
debug
()
102
{
103
return
E_OK
;
104
// return info();
105
}
106
107
short
info
()
108
{
109
// Log.verboseln("MotorLoad::info - Pin=%d | Key=%d | Addr=%d | Val=%d | NetVal=%d ", pin, id, addr, value, netVal());
110
return
E_OK
;
111
}
112
113
millis_t
dt
;
114
short
lastState
;
115
short
currentState
;
116
millis_t
lastIdle
;
117
millis_t
lastLoad
;
118
millis_t
lastOverload
;
119
/*
120
short onRegisterMethods(Bridge *bridge)
121
{
122
// bridge->registerMemberFunction(id, this, C_STR("setFlag"), (ComponentFnPtr)&MotorLoad::setFlag);
123
// bridge->registerMemberFunction(id, this, C_STR("clearFlag"), (ComponentFnPtr)&MotorLoad::clearFlag);
124
// bridge->registerMemberFunction(id, this, C_STR("info"), (ComponentFnPtr)&MotorLoad::info);
125
return E_OK;
126
}
127
*/
128
short
value
;
129
short
pin
;
130
};
131
#endif
MotorLoad::setup
short setup()
Definition:
MotorLoad.h:61
MotorLoad::MotorLoad
MotorLoad(Component *_owner, short _pin, short _id, int _addr)
Definition:
MotorLoad.h:27
MotorLoad::lastIdle
millis_t lastIdle
Definition:
MotorLoad.h:116
MOTOR_OVERLOAD_RANGE_MAX
#define MOTOR_OVERLOAD_RANGE_MAX
Definition:
config_adv.h:61
MOTOR_LOAD_RANGE_MAX
#define MOTOR_LOAD_RANGE_MAX
Definition:
config_adv.h:57
MotorLoad::lastLoad
millis_t lastLoad
Definition:
MotorLoad.h:117
MotorLoad::lastOverload
millis_t lastOverload
Definition:
MotorLoad.h:118
MotorLoad::MSTATE
MSTATE
Definition:
MotorLoad.h:18
MotorLoad::value
short value
Definition:
MotorLoad.h:128
MotorLoad::idle
short idle()
Definition:
MotorLoad.h:51
MotorLoad::debug
short debug()
Definition:
MotorLoad.h:101
MotorLoad::NONE
@ NONE
Definition:
MotorLoad.h:20
MotorLoad::loop
short loop()
Definition:
MotorLoad.h:66
MOTOR_IDLE_LOAD_RANGE_MAX
#define MOTOR_IDLE_LOAD_RANGE_MAX
Definition:
config_adv.h:53
MOTOR_LOAD_READ_INTERVAL
#define MOTOR_LOAD_READ_INTERVAL
Definition:
config_adv.h:49
MotorLoad::working
short working()
Definition:
MotorLoad.h:56
MotorLoad::pin
short pin
Definition:
MotorLoad.h:129
MotorLoad::lastState
short lastState
Definition:
MotorLoad.h:114
MotorLoad::LOAD
@ LOAD
Definition:
MotorLoad.h:22
MOTOR_IDLE_LOAD_RANGE_MIN
#define MOTOR_IDLE_LOAD_RANGE_MIN
Definition:
config_adv.h:52
MotorLoad::currentState
short currentState
Definition:
MotorLoad.h:115
MOTOR_LOAD_RANGE_MIN
#define MOTOR_LOAD_RANGE_MIN
Definition:
config_adv.h:56
MOTOR_OVERLOAD_RANGE_MIN
#define MOTOR_OVERLOAD_RANGE_MIN
Definition:
config_adv.h:60
MotorLoad::IDLE
@ IDLE
Definition:
MotorLoad.h:21
E_OK
#define E_OK
Definition:
enums.h:11
MotorLoad::OVERLOAD
@ OVERLOAD
Definition:
MotorLoad.h:23
MotorLoad::info
short info()
Definition:
MotorLoad.h:107
MotorLoad::overload
short overload()
Definition:
MotorLoad.h:46
MotorLoad
Definition:
MotorLoad.h:15
MotorLoad::dt
millis_t dt
Definition:
MotorLoad.h:113
ERROR
ERROR
Definition:
enums.h:71
firmware
firmware_v2_cm
components
MotorLoad.h
Generated by
1.8.17