-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPump.cpp
More file actions
120 lines (93 loc) · 2.61 KB
/
Pump.cpp
File metadata and controls
120 lines (93 loc) · 2.61 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
120
/*
Pump.cpp - DIY 5 channel doser
Copyright (C) 2001-2012 Georgi Todorov
All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
https://github.com/TeraHz/Doser
*/
#include "Pump.h"
#include "EEPROMAnything.h"
Pump::Pump( uint8_t pin, float mlm, uint16_t dose, uint8_t dc, char * desc) {
pinMode(pin, OUTPUT);
this->_pin = pin;
this->_mlm = mlm;
this->_dose = dose;
this->_dc = dc;
this->_desc = desc;
this->_counter = 0;
}
Pump::~Pump(){}
uint8_t Pump::getPin( void ){
return this->_pin;
}
void Pump::setPin( uint8_t pin){
pinMode(pin, OUTPUT); // enable the pin
this->_pin = pin;
}
float Pump::getMlm( void ){
return this->_mlm;
}
void Pump::setMlm( float mlm ){
this->_mlm = mlm;
}
char* Pump::getDescription( void ){
return this->_desc;
}
void Pump::setDescription( char* desc ){
this->_desc = desc;
}
uint16_t Pump::getDose( void ){
return this->_dose;
}
boolean Pump::isOn( void ){
return this->_isOn;
}
void Pump::setDose( uint16_t dose ){
if (dose == 0){
this->_isOn = false;
}else{
this->_isOn = true;
}
this->_dose = dose;
}
void Pump::setEE( uint16_t e ){
this->_ee = e;
}
uint8_t Pump::startDosing( void ){
analogWrite(this->_pin, (uint8_t)(this->_dc*1.2+135));
return (uint8_t)(this->_dc*1.2+135);
}
void Pump::startDosing(uint8_t val){
analogWrite(this->_pin, val);
}
void Pump::stopDosing( void ){
analogWrite(this->_pin, 0);
}
uint8_t Pump::getDC( void ){
return this->_dc;
}
void Pump::setDC( uint8_t dc ){
this->_dc = dc;
}
void Pump::save(){
EEPROM_writeAnything(this->_ee, this->_mlm);
EEPROM_writeAnything(this->_ee+5, this->_dose);
EEPROM_writeAnything(this->_ee+10, this->_dc);
EEPROM_writeAnything(this->_ee+15, this->_desc);
}
void Pump::load(){
EEPROM_readAnything(this->_ee, this->_mlm);
EEPROM_readAnything(this->_ee+5, this->_dose);
EEPROM_readAnything(this->_ee+10, this->_dc);
EEPROM_readAnything(this->_ee+15, this->_desc);
}