void MorpheusSlave::receiveEthernet(EthernetClient& incoming) { if ( incoming.available() ) { char b; while ( incoming.available() > 0 ) { _lastRX = millis(); b = incoming.read(); #if DBG Serial.print("B: "); Serial.println(b); #endif if ( b == '\n' ) { endComm(); break; } else if ( command == NULL ) { command = b; data = ""; } else { data += b; } } } if ( _lastRX != -1 && millis() - _lastRX > RX_TIMEOUT ) { endComm(); } }
/** handle nested comments and simple minded attributes */ void lqGvSynCol::highlightBlock(const QString &text) { QString begComm("/\\*"); QString number("\\d+(?:\\.\\d+)?"); QString symbol("\\w+"); QString quoted("\"[^\"]*\""); QString edges("--|->"); QRegExp tokens(QString("(%1)|(%2)|(%3)|(%4)|(%5)|#").arg(begComm, number, symbol, quoted, edges)); QRegExp endComm("\\*/"); // simple state machine if (currentBlock().blockNumber() > 0) setCurrentBlockState(previousBlockState()); else setCurrentBlockState(0); for (int i = 0, j, l; ; i = j + l) if (currentBlockState()) { // in multiline comment if ((j = endComm.indexIn(text, i)) == -1) { setFormat(i, text.length() - i, fmt[Comm]); break; } setFormat(i, j - i + (l = 2), fmt[Comm]); setCurrentBlockState(0); } else { if ((j = tokens.indexIn(text, i)) == -1) break; QStringList ml = tokens.capturedTexts(); Q_ASSERT(ml.length() == 5+1); if ((l = ml[1].length())) { // begin multiline comment setFormat(j, l, fmt[Comm]); setCurrentBlockState(1); } else if ((l = ml[2].length())) { // number setFormat(j, l, fmt[Number]); } else if ((l = ml[3].length())) { // symbol if (keyws.contains(ml[3])) setFormat(j, l, fmt[Keyw]); else if (attrs.contains(ml[3])) setFormat(j, l, fmt[Attr]); else setFormat(j, l, fmt[Unknown]); } else if ((l = ml[4].length())) { // quoted setFormat(j, l, fmt[Quoted]); } else if ((l = ml[5].length())) { // edge setFormat(j, l, fmt[Edge]); } else { // single line comment setFormat(j, text.length() - i, fmt[Comm]); break; } } // rather useless - anyway textChanged will fire after completion if (currentBlock().blockNumber() == document()->blockCount() - 1) emit completed(); }
void MorpheusSlave::receiveI2C(int n) { int i = 0; char b; while ( Wire.available() > 0 ){ b = Wire.read(); #if DBG Serial.print("B: "); Serial.println(b); #endif switch ( i++ ) { case 0: command = b; data = ""; break; default: data += b; break; } } endComm(); }