| 355 | |
| 356 | |
| 357 | uint32_t COZIR::_request(const char* str) |
| 358 | { |
| 359 | _command(str); |
| 360 | |
| 361 | // read the answer from serial. |
| 362 | // TODO: PROPER TIMEOUT CODE. |
| 363 | // - might be a big delay |
| 364 | // - what is longest answer possible? CZR_REQUEST_TIMEOUT? |
| 365 | uint8_t idx = 0; |
| 366 | uint32_t start = millis(); |
| 367 | while (millis() - start < CZR_REQUEST_TIMEOUT) |
| 368 | { |
| 369 | if (_ser->available()) |
| 370 | { |
| 371 | char c = _ser->read(); |
| 372 | if (c == '\n') break; |
| 373 | _buffer[idx++] = c; |
| 374 | _buffer[idx] = '\0'; |
| 375 | } |
| 376 | } |
| 377 | // Serial.print("buffer: "); |
| 378 | // Serial.println(_buffer); |
| 379 | uint32_t rv = 0; |
| 380 | // default for PPM is different. |
| 381 | if (str[0] == '.') rv = 1; |
| 382 | // do we got the requested field? |
| 383 | if (strchr(_buffer, str[0]) && (idx > 2)) |
| 384 | { |
| 385 | rv = atol(&_buffer[2]); |
| 386 | } |
| 387 | return rv; |
| 388 | } |
| 389 | |
| 390 | |
| 391 | void COZIR::_setEEPROM(uint8_t address, uint8_t value) |