forked from mindsensors/EVShield
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EVs_NXTColor.cpp
115 lines (101 loc) · 2.84 KB
/
EVs_NXTColor.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
/*
Copyright (c) 2015 mindsensors.com
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
*/
#include "EVs_NXTColor.h"
EVs_NXTColor::EVs_NXTColor()
{
mp_shield = NULL;
}
EVs_NXTColor::EVs_NXTColor(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;
}
//setType(SH_Type_COLORFULL);
}
bool EVs_NXTColor::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;
}
//setType(SH_Type_COLORFULL);
return true;
}
bool EVs_NXTColor::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);
}
}
uint8_t EVs_NXTColor::readValue()
{
char str[100];
uint8_t val;
switch (m_bp) {
case SH_BAS1:
case SH_BAS2:
val = (mp_shield->bank_a.readByte((0x70 + m_offset)));
return (val*100)/255;
case SH_BBS1:
case SH_BBS2:
val = (mp_shield->bank_b.readByte((0x70 + m_offset)));
return (val*100)/255;
}
}
uint8_t EVs_NXTColor::readColor()
{
char str[100];
uint8_t val;
/*
Serial.println("NXTColor::readValue: ");
for (int i=0x70; i< 0x70+10;i++) {
Serial.print(" "); Serial.print(mp_shield->bank_a.readByte(i));
}
Serial.println("");
*/
switch (m_bp) {
case SH_BAS1:
case SH_BAS2:
return (mp_shield->bank_a.readByte((0x70 + m_offset)));
case SH_BBS1:
case SH_BBS2:
return (mp_shield->bank_b.readByte((0x70 + m_offset)));
}
}