-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathEVShieldUART.cpp
196 lines (161 loc) · 4.38 KB
/
EVShieldUART.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
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
Modification history:
Date Author reason
12/24/14 Deepak Initial development
*/
#include "EVShieldUART.h"
EVShieldUART::EVShieldUART()
{
mp_shield = NULL;
}
EVShieldUART::EVShieldUART(EVShield * shield, SH_BankPort bp)
{
mp_shield = shield;
m_bp = bp;
switch(m_bp) {
case SH_BAS1:
case SH_BBS1:
m_offset = 0;
break;
case SH_BAS2:
case SH_BBS2:
m_offset = 52;
break;
}
}
bool EVShieldUART::setType(uint8_t type)
{
if ( mp_shield == NULL) return false;
switch (m_bp) {
case SH_BAS1:
return mp_shield->bank_a.sensorSetType(SH_S1, type);
case SH_BAS2:
return mp_shield->bank_a.sensorSetType(SH_S2, type);
case SH_BBS1:
return mp_shield->bank_b.sensorSetType(SH_S1, type);
case SH_BBS2:
return mp_shield->bank_b.sensorSetType(SH_S2, type);
}
return 0;
}
bool EVShieldUART::writeLocation(uint8_t loc, uint8_t data)
{
if ( mp_shield == NULL) return false;
switch (m_bp) {
case SH_BAS1:
case SH_BAS2:
return mp_shield->bank_a.writeByte(loc, data);
case SH_BBS1:
case SH_BBS2:
return mp_shield->bank_b.writeByte(loc, data);
}
return true;
}
int16_t EVShieldUART::readLocationInt(uint8_t loc)
{
if ( mp_shield == NULL) return -1;
switch (m_bp) {
case SH_BAS1:
case SH_BAS2:
return mp_shield->bank_a.readInteger(loc);
case SH_BBS1:
case SH_BBS2:
return mp_shield->bank_b.readInteger(loc);
}
return 0;
}
uint8_t EVShieldUART::readLocationByte(uint8_t loc)
{
if ( mp_shield == NULL) return -1;
switch (m_bp) {
case SH_BAS1:
case SH_BAS2:
return mp_shield->bank_a.readByte(loc);
case SH_BBS1:
case SH_BBS2:
return mp_shield->bank_b.readByte(loc);
}
return 0;
}
bool EVShieldUART::init(EVShield * shield, SH_BankPort bp)
{
mp_shield = shield;
m_bp = bp;
switch(m_bp) {
case SH_BAS1:
case SH_BBS1:
m_offset = 0;
break;
case SH_BAS2:
case SH_BBS2:
m_offset = 52;
break;
}
return true;
}
uint8_t EVShieldUART::getMode( )
{
if ( mp_shield == NULL) return -1;
switch (m_bp) {
case SH_BAS1:
case SH_BAS2:
return mp_shield->bank_a.readByte(0x81+m_offset);
case SH_BBS1:
case SH_BBS2:
return mp_shield->bank_b.readByte(0x81+m_offset);
}
return 0;
}
uint8_t EVShieldUART::setMode(char newMode)
{
if ( mp_shield == NULL) return -1;
switch (m_bp) {
case SH_BAS1:
case SH_BAS2:
return mp_shield->bank_a.writeByte(0x81+m_offset, (uint8_t) newMode);
case SH_BBS1:
case SH_BBS2:
return mp_shield->bank_b.writeByte(0x81+m_offset, (uint8_t) newMode);
}
return 0;
}
bool EVShieldUART::isDeviceReady()
{
if ( mp_shield == NULL) return false;
switch (m_bp) {
case SH_BAS1:
case SH_BAS2:
return (mp_shield->bank_a.readByte(0x70+m_offset) == 1);
case SH_BBS1:
case SH_BBS2:
return (mp_shield->bank_b.readByte(0x70+m_offset) == 1);
}
return 0;
}
bool EVShieldUART::readAndPrint(uint8_t loc, uint8_t len)
{
uint8_t result;
Serial.print(" ");
for (int i=loc; i<loc+len; i++) {
Serial.print (readLocationByte(i), DEC); Serial.print(" ");
}
//Serial.println("");
return true;
}
uint16_t EVShieldUART::readValue()
{
uint16_t result;
result = readLocationInt(0x83+m_offset);
return (result);
}