| 78 | } |
| 79 | |
| 80 | void SerialCommunicationApp::update() |
| 81 | { |
| 82 | // console() << "Bytes available: " << mSerial->getNumBytesAvailable() << std::endl; |
| 83 | |
| 84 | double now = getElapsedSeconds(); |
| 85 | double deltaTime = now - mLastUpdate; |
| 86 | mLastUpdate = now; |
| 87 | mLastRead += deltaTime; |
| 88 | |
| 89 | if( mLastRead > READ_INTERVAL ) { |
| 90 | mSendSerialMessage = true; |
| 91 | mLastRead = 0.0; |
| 92 | } |
| 93 | |
| 94 | if( mSendSerialMessage ) { |
| 95 | // request next chunk |
| 96 | mSerial->writeByte( mCounter ); |
| 97 | |
| 98 | try{ |
| 99 | // read until newline, to a maximum of BUFSIZE bytes |
| 100 | mLastString = mSerial->readStringUntil( '\n', BUFSIZE ); |
| 101 | |
| 102 | } |
| 103 | catch( SerialTimeoutExc &exc ) { |
| 104 | CI_LOG_EXCEPTION( "timeout", exc ); |
| 105 | } |
| 106 | |
| 107 | mSendSerialMessage = false; |
| 108 | mCounter += 8; |
| 109 | |
| 110 | console() << "last string: " << mLastString << endl; |
| 111 | |
| 112 | TextLayout simple; |
| 113 | simple.setFont( Font( "Arial Black", 24 ) ); |
| 114 | simple.setColor( Color( .7, .7, .2 ) ); |
| 115 | simple.addLine( mLastString ); |
| 116 | simple.setLeadingOffset( 0 ); |
| 117 | mTexture = gl::Texture::create( simple.render( true, false ) ); |
| 118 | |
| 119 | mSerial->flush(); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | void SerialCommunicationApp::draw() |
| 124 | { |
nothing calls this directly
no test coverage detected