Battery hex

Dependencies:   mbed PowerControl SDFileSystem

Fork of HeptaBattery_hex by 智也 大野

Committer:
tomoya123
Date:
Fri Dec 09 04:19:51 2016 +0000
Revision:
0:30e193b92735
Battery_hex

Who changed what in which revision?

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