Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
sending_state.cpp
00001 #include "system_states.hpp" 00002 #include "system.hpp" 00003 #include "display_manager.hpp" 00004 #include "dtmf_generator.hpp" 00005 #include <iostream> 00006 00007 float SendingState::ToneTime = 1.0; 00008 float SendingState::PauseTime = 0.25; 00009 00010 namespace { 00011 DigitalOut toneLed(LED3); 00012 DigitalOut pauseLed(LED4); 00013 } 00014 00015 void SendingState::enterState() { 00016 system()->moveCursorTo(0); 00017 00018 DisplayManager *display = system()->display(); 00019 display->hideCursor(); 00020 display->writeStatus("Sending..."); 00021 00022 toneLed = 0; 00023 pauseLed = 0; 00024 00025 playSymbol(); 00026 } 00027 00028 void SendingState::handleKey(char key) { 00029 this->timer.detach(); 00030 pauseLed = 0; 00031 00032 system()->dtmf()->stop(); 00033 toneLed = 0; 00034 00035 system()->setState(System::Edit); 00036 } 00037 00038 void SendingState::playSymbol() { 00039 std::cout << "Sending: Play @" << system()->cursor() << "/" << system()->text_size() << "\r" << std::endl; 00040 DisplayManager *display = system()->display(); 00041 display->moveTo(system()->cursor()); 00042 display->showCursor(); 00043 00044 char symbol = system()->text().at(system()->cursor()); 00045 system()->dtmf()->play(symbol); 00046 00047 toneLed = 1; 00048 00049 this->timer.attach(this, &SendingState::endSymbol, ToneTime); 00050 } 00051 00052 void SendingState::endSymbol() { 00053 std::cout << "Sending: End @" << system()->cursor() << "/" << system()->text_size() << "\r" << std::endl; 00054 system()->dtmf()->stop(); 00055 00056 toneLed = 0; 00057 00058 if (system()->cursor() < system()->text_size()-1) { 00059 this->timer.attach(this, &SendingState::nextSymbol, PauseTime); 00060 pauseLed = 1; 00061 } 00062 else { 00063 DisplayManager *display = system()->display(); 00064 display->hideCursor(); 00065 00066 system()->moveCursorBy(1); 00067 00068 // 1234567890123456 00069 display->writeStatus("Done sending..."); 00070 } 00071 } 00072 00073 void SendingState::nextSymbol() { 00074 std::cout << "Sending: Next @" << system()->cursor() << "/" << system()->text_size() << "\r" << std::endl; 00075 00076 pauseLed = 0; 00077 00078 system()->moveCursorBy(1); 00079 playSymbol(); 00080 }
Generated on Wed Jul 13 2022 16:23:43 by
1.7.2