SDFileSystem

Dependencies:   mbed PowerControl SDFileSystem

Fork of SDFilesystem by 智也 大野

Committer:
tomoya123
Date:
Fri Dec 09 05:02:42 2016 +0000
Revision:
0:8d235efb1150
SDcard

Who changed what in which revision?

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