Louis-Philippe Gauthier
/
EZO_I2C_hello
Library for the EZO ph probe communicating with the I2C protocol.
EZOPH/EZOPH.cpp@0:1e392c8ebfcd, 2017-03-06 (annotated)
- Committer:
- gaul2411
- Date:
- Mon Mar 06 19:03:29 2017 +0000
- Revision:
- 0:1e392c8ebfcd
Library for the EZO ph probe communication with the I2C protocol
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gaul2411 | 0:1e392c8ebfcd | 1 | /** |
gaul2411 | 0:1e392c8ebfcd | 2 | * Ezo ph sensor library |
gaul2411 | 0:1e392c8ebfcd | 3 | * |
gaul2411 | 0:1e392c8ebfcd | 4 | * @author Louis-Philippe Gauthier |
gaul2411 | 0:1e392c8ebfcd | 5 | * @version 1.0 |
gaul2411 | 0:1e392c8ebfcd | 6 | * @date 03-March-2017 |
gaul2411 | 0:1e392c8ebfcd | 7 | * |
gaul2411 | 0:1e392c8ebfcd | 8 | * Library for "EZO PH sensor module" from Atlas Scientific |
gaul2411 | 0:1e392c8ebfcd | 9 | * http://www.atlas-scientific.com/product_pages/circuits/ezo_ph.html |
gaul2411 | 0:1e392c8ebfcd | 10 | * |
gaul2411 | 0:1e392c8ebfcd | 11 | * For more information about the EZO: |
gaul2411 | 0:1e392c8ebfcd | 12 | * http://www.atlas-scientific.com/_files/_datasheets/_circuit/pH_EZO_datasheet.pdf? |
gaul2411 | 0:1e392c8ebfcd | 13 | */ |
gaul2411 | 0:1e392c8ebfcd | 14 | |
gaul2411 | 0:1e392c8ebfcd | 15 | #include "mbed.h" |
gaul2411 | 0:1e392c8ebfcd | 16 | #include "EZOPH.h" |
gaul2411 | 0:1e392c8ebfcd | 17 | |
gaul2411 | 0:1e392c8ebfcd | 18 | EZOPH::EZOPH(PinName sda, PinName scl, char slave_adr) |
gaul2411 | 0:1e392c8ebfcd | 19 | : |
gaul2411 | 0:1e392c8ebfcd | 20 | i2c_p(new I2C(sda, scl)), |
gaul2411 | 0:1e392c8ebfcd | 21 | i2c(*i2c_p), |
gaul2411 | 0:1e392c8ebfcd | 22 | address(slave_adr) |
gaul2411 | 0:1e392c8ebfcd | 23 | { |
gaul2411 | 0:1e392c8ebfcd | 24 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 25 | i2c.frequency(100000); |
gaul2411 | 0:1e392c8ebfcd | 26 | error255 = "No Data"; |
gaul2411 | 0:1e392c8ebfcd | 27 | error254 = "Pending"; |
gaul2411 | 0:1e392c8ebfcd | 28 | failedStr = "Failed"; |
gaul2411 | 0:1e392c8ebfcd | 29 | succesStr = "Success"; |
gaul2411 | 0:1e392c8ebfcd | 30 | failed = 2; |
gaul2411 | 0:1e392c8ebfcd | 31 | success = 1; |
gaul2411 | 0:1e392c8ebfcd | 32 | } |
gaul2411 | 0:1e392c8ebfcd | 33 | |
gaul2411 | 0:1e392c8ebfcd | 34 | EZOPH::~EZOPH() |
gaul2411 | 0:1e392c8ebfcd | 35 | { |
gaul2411 | 0:1e392c8ebfcd | 36 | if (NULL != i2c_p) |
gaul2411 | 0:1e392c8ebfcd | 37 | delete i2c_p; |
gaul2411 | 0:1e392c8ebfcd | 38 | } |
gaul2411 | 0:1e392c8ebfcd | 39 | |
gaul2411 | 0:1e392c8ebfcd | 40 | void EZOPH::clear(void) |
gaul2411 | 0:1e392c8ebfcd | 41 | { |
gaul2411 | 0:1e392c8ebfcd | 42 | for (int i=0; i<sizeof(ezodata); i++) { |
gaul2411 | 0:1e392c8ebfcd | 43 | ezodata[i] = '0'; |
gaul2411 | 0:1e392c8ebfcd | 44 | } |
gaul2411 | 0:1e392c8ebfcd | 45 | for (int i=0; i<sizeof(cmdData); i++) { |
gaul2411 | 0:1e392c8ebfcd | 46 | cmdData[i] = '0'; |
gaul2411 | 0:1e392c8ebfcd | 47 | } |
gaul2411 | 0:1e392c8ebfcd | 48 | for (int i=0; i<sizeof(receivedValue); i++) { |
gaul2411 | 0:1e392c8ebfcd | 49 | receivedValue[i] = '0'; |
gaul2411 | 0:1e392c8ebfcd | 50 | } |
gaul2411 | 0:1e392c8ebfcd | 51 | ezovalue = "0"; |
gaul2411 | 0:1e392c8ebfcd | 52 | } |
gaul2411 | 0:1e392c8ebfcd | 53 | |
gaul2411 | 0:1e392c8ebfcd | 54 | int EZOPH::Tcompensation (float tmp) |
gaul2411 | 0:1e392c8ebfcd | 55 | { |
gaul2411 | 0:1e392c8ebfcd | 56 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 57 | int value = static_cast<int>(tmp); |
gaul2411 | 0:1e392c8ebfcd | 58 | char dig[3] = { NULL, NULL, NULL}; |
gaul2411 | 0:1e392c8ebfcd | 59 | int x = 0; |
gaul2411 | 0:1e392c8ebfcd | 60 | while (value > 0 && x < 3) { |
gaul2411 | 0:1e392c8ebfcd | 61 | dig[x] = value % 10; |
gaul2411 | 0:1e392c8ebfcd | 62 | value /= 10; |
gaul2411 | 0:1e392c8ebfcd | 63 | x++; |
gaul2411 | 0:1e392c8ebfcd | 64 | } |
gaul2411 | 0:1e392c8ebfcd | 65 | |
gaul2411 | 0:1e392c8ebfcd | 66 | cmdData[0] = 'T'; |
gaul2411 | 0:1e392c8ebfcd | 67 | cmdData[1] = ','; |
gaul2411 | 0:1e392c8ebfcd | 68 | cmdData[2] = dig[0]; |
gaul2411 | 0:1e392c8ebfcd | 69 | cmdData[3] = '.'; |
gaul2411 | 0:1e392c8ebfcd | 70 | cmdData[4] = dig[1]; |
gaul2411 | 0:1e392c8ebfcd | 71 | cmdData[5] = dig[2]; |
gaul2411 | 0:1e392c8ebfcd | 72 | |
gaul2411 | 0:1e392c8ebfcd | 73 | i2c.write(address, cmdData, 6, false); |
gaul2411 | 0:1e392c8ebfcd | 74 | wait(0.3); |
gaul2411 | 0:1e392c8ebfcd | 75 | |
gaul2411 | 0:1e392c8ebfcd | 76 | i2c.read(address, ezodata, 1, false); |
gaul2411 | 0:1e392c8ebfcd | 77 | |
gaul2411 | 0:1e392c8ebfcd | 78 | if( ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 79 | return success; |
gaul2411 | 0:1e392c8ebfcd | 80 | } else { |
gaul2411 | 0:1e392c8ebfcd | 81 | return failed; |
gaul2411 | 0:1e392c8ebfcd | 82 | } |
gaul2411 | 0:1e392c8ebfcd | 83 | } |
gaul2411 | 0:1e392c8ebfcd | 84 | |
gaul2411 | 0:1e392c8ebfcd | 85 | float EZOPH::QTcompensation (void) |
gaul2411 | 0:1e392c8ebfcd | 86 | { |
gaul2411 | 0:1e392c8ebfcd | 87 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 88 | cmdData[0] = 'T'; |
gaul2411 | 0:1e392c8ebfcd | 89 | cmdData[1] = ','; |
gaul2411 | 0:1e392c8ebfcd | 90 | cmdData[3] = '?'; |
gaul2411 | 0:1e392c8ebfcd | 91 | |
gaul2411 | 0:1e392c8ebfcd | 92 | i2c.write(address, cmdData, 3, false); |
gaul2411 | 0:1e392c8ebfcd | 93 | wait(0.3); |
gaul2411 | 0:1e392c8ebfcd | 94 | |
gaul2411 | 0:1e392c8ebfcd | 95 | i2c.read(address, ezodata, 10, false); |
gaul2411 | 0:1e392c8ebfcd | 96 | |
gaul2411 | 0:1e392c8ebfcd | 97 | if(ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 98 | receivedValue[0] = ezodata[4]; |
gaul2411 | 0:1e392c8ebfcd | 99 | receivedValue[1] = ezodata[5]; |
gaul2411 | 0:1e392c8ebfcd | 100 | receivedValue[2] = ezodata[6]; |
gaul2411 | 0:1e392c8ebfcd | 101 | receivedValue[3] = ezodata[7]; |
gaul2411 | 0:1e392c8ebfcd | 102 | float tmp = atof(receivedValue); |
gaul2411 | 0:1e392c8ebfcd | 103 | return tmp; |
gaul2411 | 0:1e392c8ebfcd | 104 | } else { |
gaul2411 | 0:1e392c8ebfcd | 105 | return 0.0; |
gaul2411 | 0:1e392c8ebfcd | 106 | } |
gaul2411 | 0:1e392c8ebfcd | 107 | } |
gaul2411 | 0:1e392c8ebfcd | 108 | |
gaul2411 | 0:1e392c8ebfcd | 109 | string EZOPH::getSensorInfo(void) |
gaul2411 | 0:1e392c8ebfcd | 110 | { |
gaul2411 | 0:1e392c8ebfcd | 111 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 112 | cmdData[0] = 'I'; |
gaul2411 | 0:1e392c8ebfcd | 113 | |
gaul2411 | 0:1e392c8ebfcd | 114 | i2c.write(address, cmdData, 1, false); |
gaul2411 | 0:1e392c8ebfcd | 115 | wait(0.3); |
gaul2411 | 0:1e392c8ebfcd | 116 | |
gaul2411 | 0:1e392c8ebfcd | 117 | i2c.read(address, ezodata, 21, false); |
gaul2411 | 0:1e392c8ebfcd | 118 | |
gaul2411 | 0:1e392c8ebfcd | 119 | if(ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 120 | receivedValue[0] = ezodata[1]; |
gaul2411 | 0:1e392c8ebfcd | 121 | receivedValue[1] = ezodata[2]; |
gaul2411 | 0:1e392c8ebfcd | 122 | receivedValue[2] = ezodata[3]; |
gaul2411 | 0:1e392c8ebfcd | 123 | receivedValue[3] = ezodata[4]; |
gaul2411 | 0:1e392c8ebfcd | 124 | receivedValue[4] = ezodata[5]; |
gaul2411 | 0:1e392c8ebfcd | 125 | receivedValue[5] = ezodata[6]; |
gaul2411 | 0:1e392c8ebfcd | 126 | receivedValue[6] = ezodata[7]; |
gaul2411 | 0:1e392c8ebfcd | 127 | receivedValue[7] = ezodata[8]; |
gaul2411 | 0:1e392c8ebfcd | 128 | receivedValue[8] = ezodata[9]; |
gaul2411 | 0:1e392c8ebfcd | 129 | receivedValue[9] = ezodata[10]; |
gaul2411 | 0:1e392c8ebfcd | 130 | receivedValue[10] = ezodata[11]; |
gaul2411 | 0:1e392c8ebfcd | 131 | receivedValue[11] = ezodata[12]; |
gaul2411 | 0:1e392c8ebfcd | 132 | receivedValue[12] = ezodata[13]; |
gaul2411 | 0:1e392c8ebfcd | 133 | receivedValue[13] = ezodata[14]; |
gaul2411 | 0:1e392c8ebfcd | 134 | receivedValue[14] = ezodata[15]; |
gaul2411 | 0:1e392c8ebfcd | 135 | receivedValue[15] = ezodata[16]; |
gaul2411 | 0:1e392c8ebfcd | 136 | receivedValue[16] = ezodata[17]; |
gaul2411 | 0:1e392c8ebfcd | 137 | receivedValue[17] = ezodata[18]; |
gaul2411 | 0:1e392c8ebfcd | 138 | receivedValue[18] = ezodata[19]; |
gaul2411 | 0:1e392c8ebfcd | 139 | receivedValue[19] = ezodata[20]; |
gaul2411 | 0:1e392c8ebfcd | 140 | return receivedValue; |
gaul2411 | 0:1e392c8ebfcd | 141 | } else if(ezodata[0] == 254) { |
gaul2411 | 0:1e392c8ebfcd | 142 | return error254; |
gaul2411 | 0:1e392c8ebfcd | 143 | } else if(ezodata[0] == 255) { |
gaul2411 | 0:1e392c8ebfcd | 144 | return error255; |
gaul2411 | 0:1e392c8ebfcd | 145 | } else { |
gaul2411 | 0:1e392c8ebfcd | 146 | return failedStr; |
gaul2411 | 0:1e392c8ebfcd | 147 | } |
gaul2411 | 0:1e392c8ebfcd | 148 | } |
gaul2411 | 0:1e392c8ebfcd | 149 | |
gaul2411 | 0:1e392c8ebfcd | 150 | string EZOPH::getSensorStatus(void) |
gaul2411 | 0:1e392c8ebfcd | 151 | { |
gaul2411 | 0:1e392c8ebfcd | 152 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 153 | cmdData[0] = 'S'; |
gaul2411 | 0:1e392c8ebfcd | 154 | cmdData[1] = 'T'; |
gaul2411 | 0:1e392c8ebfcd | 155 | cmdData[2] = 'A'; |
gaul2411 | 0:1e392c8ebfcd | 156 | cmdData[3] = 'T'; |
gaul2411 | 0:1e392c8ebfcd | 157 | cmdData[4] = 'U'; |
gaul2411 | 0:1e392c8ebfcd | 158 | cmdData[5] = 'S'; |
gaul2411 | 0:1e392c8ebfcd | 159 | |
gaul2411 | 0:1e392c8ebfcd | 160 | i2c.write(address, cmdData, 6, false); |
gaul2411 | 0:1e392c8ebfcd | 161 | wait(0.3); |
gaul2411 | 0:1e392c8ebfcd | 162 | |
gaul2411 | 0:1e392c8ebfcd | 163 | i2c.read(address, ezodata, 21, false); |
gaul2411 | 0:1e392c8ebfcd | 164 | |
gaul2411 | 0:1e392c8ebfcd | 165 | if(ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 166 | receivedValue[0] = ezodata[1]; |
gaul2411 | 0:1e392c8ebfcd | 167 | receivedValue[1] = ezodata[2]; |
gaul2411 | 0:1e392c8ebfcd | 168 | receivedValue[2] = ezodata[3]; |
gaul2411 | 0:1e392c8ebfcd | 169 | receivedValue[3] = ezodata[4]; |
gaul2411 | 0:1e392c8ebfcd | 170 | receivedValue[4] = ezodata[5]; |
gaul2411 | 0:1e392c8ebfcd | 171 | receivedValue[5] = ezodata[6]; |
gaul2411 | 0:1e392c8ebfcd | 172 | receivedValue[6] = ezodata[7]; |
gaul2411 | 0:1e392c8ebfcd | 173 | receivedValue[7] = ezodata[8]; |
gaul2411 | 0:1e392c8ebfcd | 174 | receivedValue[8] = ezodata[9]; |
gaul2411 | 0:1e392c8ebfcd | 175 | receivedValue[9] = ezodata[10]; |
gaul2411 | 0:1e392c8ebfcd | 176 | receivedValue[10] = ezodata[11]; |
gaul2411 | 0:1e392c8ebfcd | 177 | receivedValue[11] = ezodata[12]; |
gaul2411 | 0:1e392c8ebfcd | 178 | receivedValue[12] = ezodata[13]; |
gaul2411 | 0:1e392c8ebfcd | 179 | receivedValue[13] = ezodata[14]; |
gaul2411 | 0:1e392c8ebfcd | 180 | receivedValue[14] = ezodata[15]; |
gaul2411 | 0:1e392c8ebfcd | 181 | receivedValue[15] = ezodata[16]; |
gaul2411 | 0:1e392c8ebfcd | 182 | receivedValue[16] = ezodata[17]; |
gaul2411 | 0:1e392c8ebfcd | 183 | receivedValue[17] = ezodata[18]; |
gaul2411 | 0:1e392c8ebfcd | 184 | receivedValue[18] = ezodata[19]; |
gaul2411 | 0:1e392c8ebfcd | 185 | receivedValue[19] = ezodata[20]; |
gaul2411 | 0:1e392c8ebfcd | 186 | return receivedValue; |
gaul2411 | 0:1e392c8ebfcd | 187 | } else if(ezodata[0] == 254) { |
gaul2411 | 0:1e392c8ebfcd | 188 | return error254; |
gaul2411 | 0:1e392c8ebfcd | 189 | } else if(ezodata[0] == 255) { |
gaul2411 | 0:1e392c8ebfcd | 190 | return error255; |
gaul2411 | 0:1e392c8ebfcd | 191 | } else { |
gaul2411 | 0:1e392c8ebfcd | 192 | return failedStr; |
gaul2411 | 0:1e392c8ebfcd | 193 | } |
gaul2411 | 0:1e392c8ebfcd | 194 | } |
gaul2411 | 0:1e392c8ebfcd | 195 | |
gaul2411 | 0:1e392c8ebfcd | 196 | float EZOPH::read(void) |
gaul2411 | 0:1e392c8ebfcd | 197 | { |
gaul2411 | 0:1e392c8ebfcd | 198 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 199 | cmdData[0] = 'R'; |
gaul2411 | 0:1e392c8ebfcd | 200 | |
gaul2411 | 0:1e392c8ebfcd | 201 | i2c.write(address, cmdData, 1, false); |
gaul2411 | 0:1e392c8ebfcd | 202 | wait(1); |
gaul2411 | 0:1e392c8ebfcd | 203 | |
gaul2411 | 0:1e392c8ebfcd | 204 | i2c.read(address, ezodata, 21, false); |
gaul2411 | 0:1e392c8ebfcd | 205 | |
gaul2411 | 0:1e392c8ebfcd | 206 | if(ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 207 | receivedValue[0] = ezodata[1]; |
gaul2411 | 0:1e392c8ebfcd | 208 | receivedValue[1] = ezodata[2]; |
gaul2411 | 0:1e392c8ebfcd | 209 | receivedValue[2] = ezodata[3]; |
gaul2411 | 0:1e392c8ebfcd | 210 | receivedValue[3] = ezodata[4]; |
gaul2411 | 0:1e392c8ebfcd | 211 | receivedValue[4] = ezodata[5]; |
gaul2411 | 0:1e392c8ebfcd | 212 | receivedValue[5] = ezodata[6]; |
gaul2411 | 0:1e392c8ebfcd | 213 | receivedValue[6] = ezodata[7]; |
gaul2411 | 0:1e392c8ebfcd | 214 | receivedValue[7] = ezodata[8]; |
gaul2411 | 0:1e392c8ebfcd | 215 | receivedValue[8] = ezodata[9]; |
gaul2411 | 0:1e392c8ebfcd | 216 | receivedValue[9] = ezodata[10]; |
gaul2411 | 0:1e392c8ebfcd | 217 | receivedValue[10] = ezodata[11]; |
gaul2411 | 0:1e392c8ebfcd | 218 | receivedValue[11] = ezodata[12]; |
gaul2411 | 0:1e392c8ebfcd | 219 | receivedValue[12] = ezodata[13]; |
gaul2411 | 0:1e392c8ebfcd | 220 | receivedValue[13] = ezodata[14]; |
gaul2411 | 0:1e392c8ebfcd | 221 | receivedValue[14] = ezodata[15]; |
gaul2411 | 0:1e392c8ebfcd | 222 | receivedValue[15] = ezodata[16]; |
gaul2411 | 0:1e392c8ebfcd | 223 | receivedValue[16] = ezodata[17]; |
gaul2411 | 0:1e392c8ebfcd | 224 | receivedValue[17] = ezodata[18]; |
gaul2411 | 0:1e392c8ebfcd | 225 | receivedValue[18] = ezodata[19]; |
gaul2411 | 0:1e392c8ebfcd | 226 | receivedValue[19] = ezodata[20]; |
gaul2411 | 0:1e392c8ebfcd | 227 | float PhValue = atof(receivedValue); |
gaul2411 | 0:1e392c8ebfcd | 228 | return PhValue; |
gaul2411 | 0:1e392c8ebfcd | 229 | } else { |
gaul2411 | 0:1e392c8ebfcd | 230 | return 16.999; |
gaul2411 | 0:1e392c8ebfcd | 231 | } |
gaul2411 | 0:1e392c8ebfcd | 232 | } |
gaul2411 | 0:1e392c8ebfcd | 233 | |
gaul2411 | 0:1e392c8ebfcd | 234 | int EZOPH::sensorLED(bool on) |
gaul2411 | 0:1e392c8ebfcd | 235 | { |
gaul2411 | 0:1e392c8ebfcd | 236 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 237 | cmdData[0] = 'L'; |
gaul2411 | 0:1e392c8ebfcd | 238 | cmdData[1] = ','; |
gaul2411 | 0:1e392c8ebfcd | 239 | if(on) { |
gaul2411 | 0:1e392c8ebfcd | 240 | cmdData[2] = '1'; |
gaul2411 | 0:1e392c8ebfcd | 241 | } else { |
gaul2411 | 0:1e392c8ebfcd | 242 | cmdData[2] = '0'; |
gaul2411 | 0:1e392c8ebfcd | 243 | } |
gaul2411 | 0:1e392c8ebfcd | 244 | i2c.write(address, cmdData, 3, false); |
gaul2411 | 0:1e392c8ebfcd | 245 | wait(0.3); |
gaul2411 | 0:1e392c8ebfcd | 246 | |
gaul2411 | 0:1e392c8ebfcd | 247 | i2c.read(address, ezodata, 1, false); |
gaul2411 | 0:1e392c8ebfcd | 248 | if( ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 249 | return success; |
gaul2411 | 0:1e392c8ebfcd | 250 | } else { |
gaul2411 | 0:1e392c8ebfcd | 251 | return failed; |
gaul2411 | 0:1e392c8ebfcd | 252 | } |
gaul2411 | 0:1e392c8ebfcd | 253 | } |
gaul2411 | 0:1e392c8ebfcd | 254 | int EZOPH::QsensorLED(void) |
gaul2411 | 0:1e392c8ebfcd | 255 | { |
gaul2411 | 0:1e392c8ebfcd | 256 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 257 | cmdData[0] = 'L'; |
gaul2411 | 0:1e392c8ebfcd | 258 | cmdData[1] = ','; |
gaul2411 | 0:1e392c8ebfcd | 259 | cmdData[2] = '?'; |
gaul2411 | 0:1e392c8ebfcd | 260 | |
gaul2411 | 0:1e392c8ebfcd | 261 | i2c.write(address, cmdData, 3, false); |
gaul2411 | 0:1e392c8ebfcd | 262 | wait(0.3); |
gaul2411 | 0:1e392c8ebfcd | 263 | |
gaul2411 | 0:1e392c8ebfcd | 264 | i2c.read(address, ezodata, 6, false); |
gaul2411 | 0:1e392c8ebfcd | 265 | |
gaul2411 | 0:1e392c8ebfcd | 266 | if(ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 267 | if(ezodata[4] == '1') { |
gaul2411 | 0:1e392c8ebfcd | 268 | return 1; |
gaul2411 | 0:1e392c8ebfcd | 269 | } else if(ezodata[4] == '0') { |
gaul2411 | 0:1e392c8ebfcd | 270 | return 0; |
gaul2411 | 0:1e392c8ebfcd | 271 | } |
gaul2411 | 0:1e392c8ebfcd | 272 | } else { |
gaul2411 | 0:1e392c8ebfcd | 273 | return failed; |
gaul2411 | 0:1e392c8ebfcd | 274 | } |
gaul2411 | 0:1e392c8ebfcd | 275 | } |
gaul2411 | 0:1e392c8ebfcd | 276 | |
gaul2411 | 0:1e392c8ebfcd | 277 | int EZOPH::calibrationClear(void) |
gaul2411 | 0:1e392c8ebfcd | 278 | { |
gaul2411 | 0:1e392c8ebfcd | 279 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 280 | cmdData[0] = 'C'; |
gaul2411 | 0:1e392c8ebfcd | 281 | cmdData[1] = 'a'; |
gaul2411 | 0:1e392c8ebfcd | 282 | cmdData[2] = 'l'; |
gaul2411 | 0:1e392c8ebfcd | 283 | cmdData[3] = ','; |
gaul2411 | 0:1e392c8ebfcd | 284 | cmdData[4] = 'c'; |
gaul2411 | 0:1e392c8ebfcd | 285 | cmdData[5] = 'l'; |
gaul2411 | 0:1e392c8ebfcd | 286 | cmdData[6] = 'e'; |
gaul2411 | 0:1e392c8ebfcd | 287 | cmdData[7] = 'a'; |
gaul2411 | 0:1e392c8ebfcd | 288 | cmdData[8] = 'r'; |
gaul2411 | 0:1e392c8ebfcd | 289 | |
gaul2411 | 0:1e392c8ebfcd | 290 | i2c.write(address, cmdData, 9, false); |
gaul2411 | 0:1e392c8ebfcd | 291 | wait(0.3); |
gaul2411 | 0:1e392c8ebfcd | 292 | |
gaul2411 | 0:1e392c8ebfcd | 293 | i2c.read(address, ezodata, 1, false); |
gaul2411 | 0:1e392c8ebfcd | 294 | |
gaul2411 | 0:1e392c8ebfcd | 295 | if(ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 296 | return success; |
gaul2411 | 0:1e392c8ebfcd | 297 | } else { |
gaul2411 | 0:1e392c8ebfcd | 298 | return failed; |
gaul2411 | 0:1e392c8ebfcd | 299 | } |
gaul2411 | 0:1e392c8ebfcd | 300 | } |
gaul2411 | 0:1e392c8ebfcd | 301 | |
gaul2411 | 0:1e392c8ebfcd | 302 | string EZOPH::calibrationQuery(void) |
gaul2411 | 0:1e392c8ebfcd | 303 | { |
gaul2411 | 0:1e392c8ebfcd | 304 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 305 | cmdData[0] = 'C'; |
gaul2411 | 0:1e392c8ebfcd | 306 | cmdData[1] = 'a'; |
gaul2411 | 0:1e392c8ebfcd | 307 | cmdData[2] = 'l'; |
gaul2411 | 0:1e392c8ebfcd | 308 | cmdData[3] = ','; |
gaul2411 | 0:1e392c8ebfcd | 309 | cmdData[4] = '?'; |
gaul2411 | 0:1e392c8ebfcd | 310 | |
gaul2411 | 0:1e392c8ebfcd | 311 | i2c.write(address, cmdData, 5, false); |
gaul2411 | 0:1e392c8ebfcd | 312 | wait(0.3); |
gaul2411 | 0:1e392c8ebfcd | 313 | |
gaul2411 | 0:1e392c8ebfcd | 314 | i2c.read(address, ezodata, 21, false); |
gaul2411 | 0:1e392c8ebfcd | 315 | |
gaul2411 | 0:1e392c8ebfcd | 316 | if(ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 317 | receivedValue[0] = ezodata[1]; |
gaul2411 | 0:1e392c8ebfcd | 318 | receivedValue[1] = ezodata[2]; |
gaul2411 | 0:1e392c8ebfcd | 319 | receivedValue[2] = ezodata[3]; |
gaul2411 | 0:1e392c8ebfcd | 320 | receivedValue[3] = ezodata[4]; |
gaul2411 | 0:1e392c8ebfcd | 321 | receivedValue[4] = ezodata[5]; |
gaul2411 | 0:1e392c8ebfcd | 322 | receivedValue[5] = ezodata[6]; |
gaul2411 | 0:1e392c8ebfcd | 323 | receivedValue[6] = ezodata[7]; |
gaul2411 | 0:1e392c8ebfcd | 324 | receivedValue[7] = ezodata[8]; |
gaul2411 | 0:1e392c8ebfcd | 325 | receivedValue[8] = ezodata[9]; |
gaul2411 | 0:1e392c8ebfcd | 326 | receivedValue[9] = ezodata[10]; |
gaul2411 | 0:1e392c8ebfcd | 327 | receivedValue[10] = ezodata[11]; |
gaul2411 | 0:1e392c8ebfcd | 328 | receivedValue[11] = ezodata[12]; |
gaul2411 | 0:1e392c8ebfcd | 329 | receivedValue[12] = ezodata[13]; |
gaul2411 | 0:1e392c8ebfcd | 330 | receivedValue[13] = ezodata[14]; |
gaul2411 | 0:1e392c8ebfcd | 331 | receivedValue[14] = ezodata[15]; |
gaul2411 | 0:1e392c8ebfcd | 332 | receivedValue[15] = ezodata[16]; |
gaul2411 | 0:1e392c8ebfcd | 333 | receivedValue[16] = ezodata[17]; |
gaul2411 | 0:1e392c8ebfcd | 334 | receivedValue[17] = ezodata[18]; |
gaul2411 | 0:1e392c8ebfcd | 335 | receivedValue[18] = ezodata[19]; |
gaul2411 | 0:1e392c8ebfcd | 336 | receivedValue[19] = ezodata[20]; |
gaul2411 | 0:1e392c8ebfcd | 337 | return receivedValue; |
gaul2411 | 0:1e392c8ebfcd | 338 | } else if(ezodata[0] == 254) { |
gaul2411 | 0:1e392c8ebfcd | 339 | return error254; |
gaul2411 | 0:1e392c8ebfcd | 340 | } else if(ezodata[0] == 255) { |
gaul2411 | 0:1e392c8ebfcd | 341 | return error255; |
gaul2411 | 0:1e392c8ebfcd | 342 | } else { |
gaul2411 | 0:1e392c8ebfcd | 343 | return failedStr; |
gaul2411 | 0:1e392c8ebfcd | 344 | } |
gaul2411 | 0:1e392c8ebfcd | 345 | } |
gaul2411 | 0:1e392c8ebfcd | 346 | |
gaul2411 | 0:1e392c8ebfcd | 347 | int EZOPH::calibratingMid(void) |
gaul2411 | 0:1e392c8ebfcd | 348 | { |
gaul2411 | 0:1e392c8ebfcd | 349 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 350 | cmdData[0] = 'C'; |
gaul2411 | 0:1e392c8ebfcd | 351 | cmdData[1] = 'a'; |
gaul2411 | 0:1e392c8ebfcd | 352 | cmdData[2] = 'l'; |
gaul2411 | 0:1e392c8ebfcd | 353 | cmdData[3] = ','; |
gaul2411 | 0:1e392c8ebfcd | 354 | cmdData[4] = 'm'; |
gaul2411 | 0:1e392c8ebfcd | 355 | cmdData[5] = 'i'; |
gaul2411 | 0:1e392c8ebfcd | 356 | cmdData[6] = 'd'; |
gaul2411 | 0:1e392c8ebfcd | 357 | cmdData[7] = ','; |
gaul2411 | 0:1e392c8ebfcd | 358 | cmdData[8] = '7'; |
gaul2411 | 0:1e392c8ebfcd | 359 | cmdData[9] = '.'; |
gaul2411 | 0:1e392c8ebfcd | 360 | cmdData[10] = '0'; |
gaul2411 | 0:1e392c8ebfcd | 361 | cmdData[11] = '0'; |
gaul2411 | 0:1e392c8ebfcd | 362 | |
gaul2411 | 0:1e392c8ebfcd | 363 | i2c.write(address, cmdData, 12, false); |
gaul2411 | 0:1e392c8ebfcd | 364 | wait(1.6); |
gaul2411 | 0:1e392c8ebfcd | 365 | |
gaul2411 | 0:1e392c8ebfcd | 366 | i2c.read(address, ezodata, 21, false); |
gaul2411 | 0:1e392c8ebfcd | 367 | |
gaul2411 | 0:1e392c8ebfcd | 368 | if(ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 369 | return success; |
gaul2411 | 0:1e392c8ebfcd | 370 | } else { |
gaul2411 | 0:1e392c8ebfcd | 371 | return failed; |
gaul2411 | 0:1e392c8ebfcd | 372 | } |
gaul2411 | 0:1e392c8ebfcd | 373 | } |
gaul2411 | 0:1e392c8ebfcd | 374 | |
gaul2411 | 0:1e392c8ebfcd | 375 | int EZOPH::calibratingLow(void) |
gaul2411 | 0:1e392c8ebfcd | 376 | { |
gaul2411 | 0:1e392c8ebfcd | 377 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 378 | cmdData[0] = 'C'; |
gaul2411 | 0:1e392c8ebfcd | 379 | cmdData[1] = 'a'; |
gaul2411 | 0:1e392c8ebfcd | 380 | cmdData[2] = 'l'; |
gaul2411 | 0:1e392c8ebfcd | 381 | cmdData[3] = ','; |
gaul2411 | 0:1e392c8ebfcd | 382 | cmdData[4] = 'l'; |
gaul2411 | 0:1e392c8ebfcd | 383 | cmdData[5] = 'o'; |
gaul2411 | 0:1e392c8ebfcd | 384 | cmdData[6] = 'w'; |
gaul2411 | 0:1e392c8ebfcd | 385 | cmdData[7] = ','; |
gaul2411 | 0:1e392c8ebfcd | 386 | cmdData[8] = '4'; |
gaul2411 | 0:1e392c8ebfcd | 387 | cmdData[9] = '.'; |
gaul2411 | 0:1e392c8ebfcd | 388 | cmdData[10] = '0'; |
gaul2411 | 0:1e392c8ebfcd | 389 | cmdData[11] = '0'; |
gaul2411 | 0:1e392c8ebfcd | 390 | |
gaul2411 | 0:1e392c8ebfcd | 391 | i2c.write(address, cmdData, 12, false); |
gaul2411 | 0:1e392c8ebfcd | 392 | wait(1.6); |
gaul2411 | 0:1e392c8ebfcd | 393 | |
gaul2411 | 0:1e392c8ebfcd | 394 | i2c.read(address, ezodata, 1, false); |
gaul2411 | 0:1e392c8ebfcd | 395 | |
gaul2411 | 0:1e392c8ebfcd | 396 | if(ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 397 | return success; |
gaul2411 | 0:1e392c8ebfcd | 398 | } else { |
gaul2411 | 0:1e392c8ebfcd | 399 | return failed; |
gaul2411 | 0:1e392c8ebfcd | 400 | } |
gaul2411 | 0:1e392c8ebfcd | 401 | } |
gaul2411 | 0:1e392c8ebfcd | 402 | |
gaul2411 | 0:1e392c8ebfcd | 403 | int EZOPH::calibratingHigh(void) |
gaul2411 | 0:1e392c8ebfcd | 404 | { |
gaul2411 | 0:1e392c8ebfcd | 405 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 406 | cmdData[0] = 'C'; |
gaul2411 | 0:1e392c8ebfcd | 407 | cmdData[1] = 'a'; |
gaul2411 | 0:1e392c8ebfcd | 408 | cmdData[2] = 'l'; |
gaul2411 | 0:1e392c8ebfcd | 409 | cmdData[3] = ','; |
gaul2411 | 0:1e392c8ebfcd | 410 | cmdData[4] = 'h'; |
gaul2411 | 0:1e392c8ebfcd | 411 | cmdData[5] = 'i'; |
gaul2411 | 0:1e392c8ebfcd | 412 | cmdData[6] = 'g'; |
gaul2411 | 0:1e392c8ebfcd | 413 | cmdData[7] = 'h'; |
gaul2411 | 0:1e392c8ebfcd | 414 | cmdData[8] = ','; |
gaul2411 | 0:1e392c8ebfcd | 415 | cmdData[9] = '1'; |
gaul2411 | 0:1e392c8ebfcd | 416 | cmdData[10] = '0'; |
gaul2411 | 0:1e392c8ebfcd | 417 | cmdData[11] = '.'; |
gaul2411 | 0:1e392c8ebfcd | 418 | cmdData[12] = '0'; |
gaul2411 | 0:1e392c8ebfcd | 419 | cmdData[13] = '0'; |
gaul2411 | 0:1e392c8ebfcd | 420 | |
gaul2411 | 0:1e392c8ebfcd | 421 | i2c.write(address, cmdData, 14, false); |
gaul2411 | 0:1e392c8ebfcd | 422 | wait(1.6); |
gaul2411 | 0:1e392c8ebfcd | 423 | |
gaul2411 | 0:1e392c8ebfcd | 424 | i2c.read(address, ezodata, 21, false); |
gaul2411 | 0:1e392c8ebfcd | 425 | |
gaul2411 | 0:1e392c8ebfcd | 426 | if(ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 427 | return success; |
gaul2411 | 0:1e392c8ebfcd | 428 | } else { |
gaul2411 | 0:1e392c8ebfcd | 429 | return failed; |
gaul2411 | 0:1e392c8ebfcd | 430 | } |
gaul2411 | 0:1e392c8ebfcd | 431 | } |
gaul2411 | 0:1e392c8ebfcd | 432 | |
gaul2411 | 0:1e392c8ebfcd | 433 | string EZOPH::slope(void) |
gaul2411 | 0:1e392c8ebfcd | 434 | { |
gaul2411 | 0:1e392c8ebfcd | 435 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 436 | cmdData[0] = 'S'; |
gaul2411 | 0:1e392c8ebfcd | 437 | cmdData[1] = 'l'; |
gaul2411 | 0:1e392c8ebfcd | 438 | cmdData[2] = 'o'; |
gaul2411 | 0:1e392c8ebfcd | 439 | cmdData[3] = 'p'; |
gaul2411 | 0:1e392c8ebfcd | 440 | cmdData[4] = 'e'; |
gaul2411 | 0:1e392c8ebfcd | 441 | cmdData[5] = ','; |
gaul2411 | 0:1e392c8ebfcd | 442 | cmdData[6] = '?'; |
gaul2411 | 0:1e392c8ebfcd | 443 | |
gaul2411 | 0:1e392c8ebfcd | 444 | i2c.write(address, cmdData, 7, false); |
gaul2411 | 0:1e392c8ebfcd | 445 | wait(0.3); |
gaul2411 | 0:1e392c8ebfcd | 446 | |
gaul2411 | 0:1e392c8ebfcd | 447 | i2c.read(address, ezodata, 21, false); |
gaul2411 | 0:1e392c8ebfcd | 448 | |
gaul2411 | 0:1e392c8ebfcd | 449 | if(ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 450 | receivedValue[0] = ezodata[1]; |
gaul2411 | 0:1e392c8ebfcd | 451 | receivedValue[1] = ezodata[2]; |
gaul2411 | 0:1e392c8ebfcd | 452 | receivedValue[2] = ezodata[3]; |
gaul2411 | 0:1e392c8ebfcd | 453 | receivedValue[3] = ezodata[4]; |
gaul2411 | 0:1e392c8ebfcd | 454 | receivedValue[4] = ezodata[5]; |
gaul2411 | 0:1e392c8ebfcd | 455 | receivedValue[5] = ezodata[6]; |
gaul2411 | 0:1e392c8ebfcd | 456 | receivedValue[6] = ezodata[7]; |
gaul2411 | 0:1e392c8ebfcd | 457 | receivedValue[7] = ezodata[8]; |
gaul2411 | 0:1e392c8ebfcd | 458 | receivedValue[8] = ezodata[9]; |
gaul2411 | 0:1e392c8ebfcd | 459 | receivedValue[9] = ezodata[10]; |
gaul2411 | 0:1e392c8ebfcd | 460 | receivedValue[10] = ezodata[11]; |
gaul2411 | 0:1e392c8ebfcd | 461 | receivedValue[11] = ezodata[12]; |
gaul2411 | 0:1e392c8ebfcd | 462 | receivedValue[12] = ezodata[13]; |
gaul2411 | 0:1e392c8ebfcd | 463 | receivedValue[13] = ezodata[14]; |
gaul2411 | 0:1e392c8ebfcd | 464 | receivedValue[14] = ezodata[15]; |
gaul2411 | 0:1e392c8ebfcd | 465 | receivedValue[15] = ezodata[16]; |
gaul2411 | 0:1e392c8ebfcd | 466 | receivedValue[16] = ezodata[17]; |
gaul2411 | 0:1e392c8ebfcd | 467 | receivedValue[17] = ezodata[18]; |
gaul2411 | 0:1e392c8ebfcd | 468 | receivedValue[18] = ezodata[19]; |
gaul2411 | 0:1e392c8ebfcd | 469 | receivedValue[19] = ezodata[20]; |
gaul2411 | 0:1e392c8ebfcd | 470 | return receivedValue; |
gaul2411 | 0:1e392c8ebfcd | 471 | } else if(ezodata[0] == 254) { |
gaul2411 | 0:1e392c8ebfcd | 472 | return error254; |
gaul2411 | 0:1e392c8ebfcd | 473 | } else if(ezodata[0] == 255) { |
gaul2411 | 0:1e392c8ebfcd | 474 | return error255; |
gaul2411 | 0:1e392c8ebfcd | 475 | } else { |
gaul2411 | 0:1e392c8ebfcd | 476 | return failedStr; |
gaul2411 | 0:1e392c8ebfcd | 477 | } |
gaul2411 | 0:1e392c8ebfcd | 478 | } |
gaul2411 | 0:1e392c8ebfcd | 479 | |
gaul2411 | 0:1e392c8ebfcd | 480 | string EZOPH::factoryReset(void) |
gaul2411 | 0:1e392c8ebfcd | 481 | { |
gaul2411 | 0:1e392c8ebfcd | 482 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 483 | cmdData[0] = 'F'; |
gaul2411 | 0:1e392c8ebfcd | 484 | cmdData[1] = 'a'; |
gaul2411 | 0:1e392c8ebfcd | 485 | cmdData[2] = 'c'; |
gaul2411 | 0:1e392c8ebfcd | 486 | cmdData[3] = 't'; |
gaul2411 | 0:1e392c8ebfcd | 487 | cmdData[4] = 'o'; |
gaul2411 | 0:1e392c8ebfcd | 488 | cmdData[5] = 'r'; |
gaul2411 | 0:1e392c8ebfcd | 489 | cmdData[6] = 'y'; |
gaul2411 | 0:1e392c8ebfcd | 490 | |
gaul2411 | 0:1e392c8ebfcd | 491 | i2c.write(address, cmdData, 7, false); |
gaul2411 | 0:1e392c8ebfcd | 492 | wait(0.3); |
gaul2411 | 0:1e392c8ebfcd | 493 | |
gaul2411 | 0:1e392c8ebfcd | 494 | i2c.read(address, ezodata, 21, false); |
gaul2411 | 0:1e392c8ebfcd | 495 | |
gaul2411 | 0:1e392c8ebfcd | 496 | if(ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 497 | receivedValue[0] = ezodata[1]; |
gaul2411 | 0:1e392c8ebfcd | 498 | receivedValue[1] = ezodata[2]; |
gaul2411 | 0:1e392c8ebfcd | 499 | receivedValue[2] = ezodata[3]; |
gaul2411 | 0:1e392c8ebfcd | 500 | receivedValue[3] = ezodata[4]; |
gaul2411 | 0:1e392c8ebfcd | 501 | receivedValue[4] = ezodata[5]; |
gaul2411 | 0:1e392c8ebfcd | 502 | receivedValue[5] = ezodata[6]; |
gaul2411 | 0:1e392c8ebfcd | 503 | receivedValue[6] = ezodata[7]; |
gaul2411 | 0:1e392c8ebfcd | 504 | receivedValue[7] = ezodata[8]; |
gaul2411 | 0:1e392c8ebfcd | 505 | receivedValue[8] = ezodata[9]; |
gaul2411 | 0:1e392c8ebfcd | 506 | receivedValue[9] = ezodata[10]; |
gaul2411 | 0:1e392c8ebfcd | 507 | receivedValue[10] = ezodata[11]; |
gaul2411 | 0:1e392c8ebfcd | 508 | receivedValue[11] = ezodata[12]; |
gaul2411 | 0:1e392c8ebfcd | 509 | receivedValue[12] = ezodata[13]; |
gaul2411 | 0:1e392c8ebfcd | 510 | receivedValue[13] = ezodata[14]; |
gaul2411 | 0:1e392c8ebfcd | 511 | receivedValue[14] = ezodata[15]; |
gaul2411 | 0:1e392c8ebfcd | 512 | receivedValue[15] = ezodata[16]; |
gaul2411 | 0:1e392c8ebfcd | 513 | receivedValue[16] = ezodata[17]; |
gaul2411 | 0:1e392c8ebfcd | 514 | receivedValue[17] = ezodata[18]; |
gaul2411 | 0:1e392c8ebfcd | 515 | receivedValue[18] = ezodata[19]; |
gaul2411 | 0:1e392c8ebfcd | 516 | receivedValue[19] = ezodata[20]; |
gaul2411 | 0:1e392c8ebfcd | 517 | return receivedValue; |
gaul2411 | 0:1e392c8ebfcd | 518 | } else if(ezodata[0] == 254) { |
gaul2411 | 0:1e392c8ebfcd | 519 | return error254; |
gaul2411 | 0:1e392c8ebfcd | 520 | } else if(ezodata[0] == 255) { |
gaul2411 | 0:1e392c8ebfcd | 521 | return error255; |
gaul2411 | 0:1e392c8ebfcd | 522 | } else { |
gaul2411 | 0:1e392c8ebfcd | 523 | return failedStr; |
gaul2411 | 0:1e392c8ebfcd | 524 | } |
gaul2411 | 0:1e392c8ebfcd | 525 | } |
gaul2411 | 0:1e392c8ebfcd | 526 | |
gaul2411 | 0:1e392c8ebfcd | 527 | void EZOPH::sleep(void) |
gaul2411 | 0:1e392c8ebfcd | 528 | { |
gaul2411 | 0:1e392c8ebfcd | 529 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 530 | |
gaul2411 | 0:1e392c8ebfcd | 531 | cmdData[0] = 'S'; |
gaul2411 | 0:1e392c8ebfcd | 532 | cmdData[1] = 'l'; |
gaul2411 | 0:1e392c8ebfcd | 533 | cmdData[2] = 'e'; |
gaul2411 | 0:1e392c8ebfcd | 534 | cmdData[3] = 'e'; |
gaul2411 | 0:1e392c8ebfcd | 535 | cmdData[4] = 'p'; |
gaul2411 | 0:1e392c8ebfcd | 536 | |
gaul2411 | 0:1e392c8ebfcd | 537 | i2c.write(address, cmdData, 5, false); |
gaul2411 | 0:1e392c8ebfcd | 538 | wait(0.3); |
gaul2411 | 0:1e392c8ebfcd | 539 | |
gaul2411 | 0:1e392c8ebfcd | 540 | // no response code |
gaul2411 | 0:1e392c8ebfcd | 541 | } |
gaul2411 | 0:1e392c8ebfcd | 542 | |
gaul2411 | 0:1e392c8ebfcd | 543 | int EZOPH::EDProtocolLock(bool on) |
gaul2411 | 0:1e392c8ebfcd | 544 | { |
gaul2411 | 0:1e392c8ebfcd | 545 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 546 | cmdData[0] = 'P'; |
gaul2411 | 0:1e392c8ebfcd | 547 | cmdData[1] = 'L'; |
gaul2411 | 0:1e392c8ebfcd | 548 | cmdData[2] = 'O'; |
gaul2411 | 0:1e392c8ebfcd | 549 | cmdData[3] = 'C'; |
gaul2411 | 0:1e392c8ebfcd | 550 | cmdData[4] = 'K'; |
gaul2411 | 0:1e392c8ebfcd | 551 | cmdData[5] = ','; |
gaul2411 | 0:1e392c8ebfcd | 552 | if(on) { |
gaul2411 | 0:1e392c8ebfcd | 553 | cmdData[6] = '1'; |
gaul2411 | 0:1e392c8ebfcd | 554 | } else { |
gaul2411 | 0:1e392c8ebfcd | 555 | cmdData[6] = '0'; |
gaul2411 | 0:1e392c8ebfcd | 556 | } |
gaul2411 | 0:1e392c8ebfcd | 557 | |
gaul2411 | 0:1e392c8ebfcd | 558 | i2c.write(address, cmdData, 7, false); |
gaul2411 | 0:1e392c8ebfcd | 559 | wait(0.3); |
gaul2411 | 0:1e392c8ebfcd | 560 | |
gaul2411 | 0:1e392c8ebfcd | 561 | i2c.read(address, ezodata, 1, false); |
gaul2411 | 0:1e392c8ebfcd | 562 | |
gaul2411 | 0:1e392c8ebfcd | 563 | if(ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 564 | return success; |
gaul2411 | 0:1e392c8ebfcd | 565 | } else { |
gaul2411 | 0:1e392c8ebfcd | 566 | return failed; |
gaul2411 | 0:1e392c8ebfcd | 567 | } |
gaul2411 | 0:1e392c8ebfcd | 568 | } |
gaul2411 | 0:1e392c8ebfcd | 569 | |
gaul2411 | 0:1e392c8ebfcd | 570 | int EZOPH::QProtocolLock() |
gaul2411 | 0:1e392c8ebfcd | 571 | { |
gaul2411 | 0:1e392c8ebfcd | 572 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 573 | cmdData[0] = 'P'; |
gaul2411 | 0:1e392c8ebfcd | 574 | cmdData[1] = 'L'; |
gaul2411 | 0:1e392c8ebfcd | 575 | cmdData[2] = 'O'; |
gaul2411 | 0:1e392c8ebfcd | 576 | cmdData[3] = 'C'; |
gaul2411 | 0:1e392c8ebfcd | 577 | cmdData[4] = 'K'; |
gaul2411 | 0:1e392c8ebfcd | 578 | cmdData[5] = ','; |
gaul2411 | 0:1e392c8ebfcd | 579 | cmdData[6] = '?'; |
gaul2411 | 0:1e392c8ebfcd | 580 | |
gaul2411 | 0:1e392c8ebfcd | 581 | i2c.write(address, cmdData, 7, false); |
gaul2411 | 0:1e392c8ebfcd | 582 | wait(0.3); |
gaul2411 | 0:1e392c8ebfcd | 583 | |
gaul2411 | 0:1e392c8ebfcd | 584 | i2c.read(address, ezodata, 1, false); |
gaul2411 | 0:1e392c8ebfcd | 585 | |
gaul2411 | 0:1e392c8ebfcd | 586 | if(ezodata[0] == 1) { |
gaul2411 | 0:1e392c8ebfcd | 587 | return ezodata[8]; |
gaul2411 | 0:1e392c8ebfcd | 588 | } else { |
gaul2411 | 0:1e392c8ebfcd | 589 | return failed; |
gaul2411 | 0:1e392c8ebfcd | 590 | } |
gaul2411 | 0:1e392c8ebfcd | 591 | } |
gaul2411 | 0:1e392c8ebfcd | 592 | |
gaul2411 | 0:1e392c8ebfcd | 593 | void EZOPH::changeUART(int baudRate) |
gaul2411 | 0:1e392c8ebfcd | 594 | { |
gaul2411 | 0:1e392c8ebfcd | 595 | clear(); |
gaul2411 | 0:1e392c8ebfcd | 596 | |
gaul2411 | 0:1e392c8ebfcd | 597 | char dig[6] = { NULL, NULL, NULL, NULL, NULL, NULL}; |
gaul2411 | 0:1e392c8ebfcd | 598 | int x = 0; |
gaul2411 | 0:1e392c8ebfcd | 599 | int value = baudRate; |
gaul2411 | 0:1e392c8ebfcd | 600 | int number = 10; |
gaul2411 | 0:1e392c8ebfcd | 601 | |
gaul2411 | 0:1e392c8ebfcd | 602 | while (value > 0 && x < 3) { |
gaul2411 | 0:1e392c8ebfcd | 603 | dig[x] = value % 10; |
gaul2411 | 0:1e392c8ebfcd | 604 | value /= 10; |
gaul2411 | 0:1e392c8ebfcd | 605 | x++; |
gaul2411 | 0:1e392c8ebfcd | 606 | } |
gaul2411 | 0:1e392c8ebfcd | 607 | cmdData[0] = 'S'; |
gaul2411 | 0:1e392c8ebfcd | 608 | cmdData[1] = 'E'; |
gaul2411 | 0:1e392c8ebfcd | 609 | cmdData[2] = 'R'; |
gaul2411 | 0:1e392c8ebfcd | 610 | cmdData[3] = 'I'; |
gaul2411 | 0:1e392c8ebfcd | 611 | cmdData[4] = 'A'; |
gaul2411 | 0:1e392c8ebfcd | 612 | cmdData[5] = 'L'; |
gaul2411 | 0:1e392c8ebfcd | 613 | cmdData[6] = ','; |
gaul2411 | 0:1e392c8ebfcd | 614 | cmdData[7] = dig[0]; |
gaul2411 | 0:1e392c8ebfcd | 615 | cmdData[8] = dig[1]; |
gaul2411 | 0:1e392c8ebfcd | 616 | cmdData[9] = dig[2]; |
gaul2411 | 0:1e392c8ebfcd | 617 | if (dig[3] != NULL) { |
gaul2411 | 0:1e392c8ebfcd | 618 | cmdData[10] = dig[3]; |
gaul2411 | 0:1e392c8ebfcd | 619 | number = 11; |
gaul2411 | 0:1e392c8ebfcd | 620 | } else if (dig[4] != NULL) { |
gaul2411 | 0:1e392c8ebfcd | 621 | cmdData[11] = dig[3]; |
gaul2411 | 0:1e392c8ebfcd | 622 | number = 12; |
gaul2411 | 0:1e392c8ebfcd | 623 | } else if (dig[5] != NULL) { |
gaul2411 | 0:1e392c8ebfcd | 624 | cmdData[12] = dig[3]; |
gaul2411 | 0:1e392c8ebfcd | 625 | number = 13; |
gaul2411 | 0:1e392c8ebfcd | 626 | } |
gaul2411 | 0:1e392c8ebfcd | 627 | |
gaul2411 | 0:1e392c8ebfcd | 628 | i2c.write(address, cmdData, number, false); |
gaul2411 | 0:1e392c8ebfcd | 629 | wait(0.3); |
gaul2411 | 0:1e392c8ebfcd | 630 | // No response code |
gaul2411 | 0:1e392c8ebfcd | 631 | } |