Battery

Dependencies:   mbed PowerControl SDFileSystem

Fork of HeptaBattery by 智也 大野

Committer:
tomoya123
Date:
Tue Dec 13 06:37:27 2016 +0000
Revision:
1:166ddf929155
Parent:
0:d53e9c6fc771
HeptaBattery

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tomoya123 0:d53e9c6fc771 1 #include "HeptaVoice.h"
tomoya123 0:d53e9c6fc771 2
tomoya123 0:d53e9c6fc771 3 HeptaVoice::HeptaVoice(PinName sda, PinName scl, int addr):_i2c(sda, scl),_addr(addr)
tomoya123 0:d53e9c6fc771 4 {
tomoya123 0:d53e9c6fc771 5 _addr = addr;
tomoya123 0:d53e9c6fc771 6 _poll_wait.reset();
tomoya123 0:d53e9c6fc771 7 _poll_wait.start();
tomoya123 0:d53e9c6fc771 8 }
tomoya123 0:d53e9c6fc771 9
tomoya123 0:d53e9c6fc771 10 bool HeptaVoice::IsActive(int timeout_ms)
tomoya123 0:d53e9c6fc771 11 {
tomoya123 0:d53e9c6fc771 12 wait_ms(AQTK_STARTUP_WAIT_MS);
tomoya123 0:d53e9c6fc771 13 Timer t;
tomoya123 0:d53e9c6fc771 14 t.reset();
tomoya123 0:d53e9c6fc771 15 t.start();
tomoya123 0:d53e9c6fc771 16 while(t.read_ms() < timeout_ms) {
tomoya123 0:d53e9c6fc771 17 _poll_wait.reset();
tomoya123 0:d53e9c6fc771 18 if (_i2c.write(_addr, NULL, 0) == 0) {
tomoya123 0:d53e9c6fc771 19 return true;
tomoya123 0:d53e9c6fc771 20 }
tomoya123 0:d53e9c6fc771 21 wait_ms(AQTK_POLL_WAIT_MS);
tomoya123 0:d53e9c6fc771 22 }
tomoya123 0:d53e9c6fc771 23 return false;
tomoya123 0:d53e9c6fc771 24 }
tomoya123 0:d53e9c6fc771 25
tomoya123 0:d53e9c6fc771 26 void HeptaVoice::Synthe(const char* msg)
tomoya123 0:d53e9c6fc771 27 {
tomoya123 0:d53e9c6fc771 28 while(IsBusy()) {
tomoya123 0:d53e9c6fc771 29 ;
tomoya123 0:d53e9c6fc771 30 }
tomoya123 0:d53e9c6fc771 31 Write(msg);
tomoya123 0:d53e9c6fc771 32 Write("\r");
tomoya123 0:d53e9c6fc771 33 }
tomoya123 0:d53e9c6fc771 34
tomoya123 0:d53e9c6fc771 35 void HeptaVoice::Write(const char *msg)
tomoya123 0:d53e9c6fc771 36 {
tomoya123 0:d53e9c6fc771 37 _i2c.write(_addr, msg, strlen(msg));
tomoya123 0:d53e9c6fc771 38 _poll_wait.reset();
tomoya123 0:d53e9c6fc771 39 }
tomoya123 0:d53e9c6fc771 40
tomoya123 0:d53e9c6fc771 41 bool HeptaVoice::IsBusy()
tomoya123 0:d53e9c6fc771 42 {
tomoya123 0:d53e9c6fc771 43 if (AQTK_POLL_WAIT_MS > _poll_wait.read_ms()) {
tomoya123 0:d53e9c6fc771 44 return true;
tomoya123 0:d53e9c6fc771 45 }
tomoya123 0:d53e9c6fc771 46 _poll_wait.reset();
tomoya123 0:d53e9c6fc771 47 char c = 0x00;
tomoya123 0:d53e9c6fc771 48 if (_i2c.read(_addr, &c, 1) != 0) {
tomoya123 0:d53e9c6fc771 49 return false;
tomoya123 0:d53e9c6fc771 50 }
tomoya123 0:d53e9c6fc771 51 return c == '*' || c == 0xff;
tomoya123 0:d53e9c6fc771 52 }