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