Xbee CountUp

Dependencies:   mbed

Fork of HeptaXbee_CountUp by 智也 大野

Committer:
tomoya123
Date:
Tue Dec 13 07:55:03 2016 +0000
Revision:
1:715b80d2a02b
Parent:
0:0a7fa0911e6c
Xbee CountUp

Who changed what in which revision?

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