Charge control
Dependencies: mbed PowerControl SDFileSystem
hepta_sat/HeptaVoice.cpp@0:0842f00470eb, 2016-12-09 (annotated)
- Committer:
- tomoya123
- Date:
- Fri Dec 09 05:04:37 2016 +0000
- Revision:
- 0:0842f00470eb
Charge control
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tomoya123 | 0:0842f00470eb | 1 | #include "HeptaVoice.h" |
tomoya123 | 0:0842f00470eb | 2 | |
tomoya123 | 0:0842f00470eb | 3 | HeptaVoice::HeptaVoice(PinName sda, PinName scl, int addr):_i2c(sda, scl),_addr(addr) |
tomoya123 | 0:0842f00470eb | 4 | { |
tomoya123 | 0:0842f00470eb | 5 | _addr = addr; |
tomoya123 | 0:0842f00470eb | 6 | _poll_wait.reset(); |
tomoya123 | 0:0842f00470eb | 7 | _poll_wait.start(); |
tomoya123 | 0:0842f00470eb | 8 | } |
tomoya123 | 0:0842f00470eb | 9 | |
tomoya123 | 0:0842f00470eb | 10 | bool HeptaVoice::IsActive(int timeout_ms) |
tomoya123 | 0:0842f00470eb | 11 | { |
tomoya123 | 0:0842f00470eb | 12 | wait_ms(AQTK_STARTUP_WAIT_MS); |
tomoya123 | 0:0842f00470eb | 13 | Timer t; |
tomoya123 | 0:0842f00470eb | 14 | t.reset(); |
tomoya123 | 0:0842f00470eb | 15 | t.start(); |
tomoya123 | 0:0842f00470eb | 16 | while(t.read_ms() < timeout_ms) { |
tomoya123 | 0:0842f00470eb | 17 | _poll_wait.reset(); |
tomoya123 | 0:0842f00470eb | 18 | if (_i2c.write(_addr, NULL, 0) == 0) { |
tomoya123 | 0:0842f00470eb | 19 | return true; |
tomoya123 | 0:0842f00470eb | 20 | } |
tomoya123 | 0:0842f00470eb | 21 | wait_ms(AQTK_POLL_WAIT_MS); |
tomoya123 | 0:0842f00470eb | 22 | } |
tomoya123 | 0:0842f00470eb | 23 | return false; |
tomoya123 | 0:0842f00470eb | 24 | } |
tomoya123 | 0:0842f00470eb | 25 | |
tomoya123 | 0:0842f00470eb | 26 | void HeptaVoice::Synthe(const char* msg) |
tomoya123 | 0:0842f00470eb | 27 | { |
tomoya123 | 0:0842f00470eb | 28 | while(IsBusy()) { |
tomoya123 | 0:0842f00470eb | 29 | ; |
tomoya123 | 0:0842f00470eb | 30 | } |
tomoya123 | 0:0842f00470eb | 31 | Write(msg); |
tomoya123 | 0:0842f00470eb | 32 | Write("\r"); |
tomoya123 | 0:0842f00470eb | 33 | } |
tomoya123 | 0:0842f00470eb | 34 | |
tomoya123 | 0:0842f00470eb | 35 | void HeptaVoice::Write(const char *msg) |
tomoya123 | 0:0842f00470eb | 36 | { |
tomoya123 | 0:0842f00470eb | 37 | _i2c.write(_addr, msg, strlen(msg)); |
tomoya123 | 0:0842f00470eb | 38 | _poll_wait.reset(); |
tomoya123 | 0:0842f00470eb | 39 | } |
tomoya123 | 0:0842f00470eb | 40 | |
tomoya123 | 0:0842f00470eb | 41 | bool HeptaVoice::IsBusy() |
tomoya123 | 0:0842f00470eb | 42 | { |
tomoya123 | 0:0842f00470eb | 43 | if (AQTK_POLL_WAIT_MS > _poll_wait.read_ms()) { |
tomoya123 | 0:0842f00470eb | 44 | return true; |
tomoya123 | 0:0842f00470eb | 45 | } |
tomoya123 | 0:0842f00470eb | 46 | _poll_wait.reset(); |
tomoya123 | 0:0842f00470eb | 47 | char c = 0x00; |
tomoya123 | 0:0842f00470eb | 48 | if (_i2c.read(_addr, &c, 1) != 0) { |
tomoya123 | 0:0842f00470eb | 49 | return false; |
tomoya123 | 0:0842f00470eb | 50 | } |
tomoya123 | 0:0842f00470eb | 51 | return c == '*' || c == 0xff; |
tomoya123 | 0:0842f00470eb | 52 | } |