-
Notifications
You must be signed in to change notification settings - Fork 0
/
Suspension.hh
65 lines (59 loc) · 1.73 KB
/
Suspension.hh
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
/**
* @file Suspension.h
* @version 0.9
*
* @section License
* Copyright (C) 2014, Jimmy Hedman
*
*
*
*/
#ifndef SUSPENSION_H
#define SUSPENSION_H
#define STRUT(var,name,sensor,vent,eepromlocation) \
Strut var(sensor, vent, &compressor, eepromlocation); \
const char var ## _name[] PROGMEM = name; \
const Menu::int_range_t var ## _menu PROGMEM = { \
{ \
Menu::INT_RANGE, \
(str_P) var ## _name \
}, \
0, \
1023, \
&var.desired \
};
class Compressor {
private:
OutputPin compr;
int8_t count;
int8_t maxon;
public:
Compressor(Board::DigitalPin _comp, int8_t _max=4) : compr(_comp), count(0), maxon(_max) {};
void on() { if (count==0) { compr.on(); };
if (count<=maxon) { count++; };
};
void off() { if (count>0) { count--; };
if (count==0) { compr.off(); };
};
};
class Strut : public Periodic {
private:
int16_t actual;
int16_t saveddesired;
int16_t smoothed;
AnalogPin sensor;
OutputPin vent;
Compressor* compr;
bool comprstate;
int16_t* eepromlocation;
public:
Strut(Board::AnalogPin _sensor, Board::DigitalPin _vent, Compressor *_compr, int8_t _eepromlocation, uint16_t ms=2000);
virtual void run();
int16_t GetDesired();
int16_t SetDesired();
int16_t SetDesired(int16_t newdesired);
int16_t GetActual();
int16_t desired;
bool is_leveled;
};
#endif