• Hm, how do I work around this without making it into a total mess?

    On Arduino it's easy, because Serial.read() always returns one character. But here, I could be getting anything...

    Is there anything more graceful than

    
    AzzyRF.prototype.onData = function(data) {
    for (var x=0; x < data.length; x++) {
    	if (data.charAt(x)=="#" && this.datastring) {
    		if (this.datastring) {
    			this.Serial.print(this.datastring);
    			this.datastring="";
    		}
    	} else if (data.charAt(x)==">" && this.datastring) {
    		//TODO
    	} else if (data.charAt(x)=="\n" || data.charAt(x)=="\r"){
    		if (this.inString!="") {
    			this.outputFormat(this.inString);
    			this.inString="";
    		}
    	} else {
    		this.inString+=data.charAt(x);
        if (this.timeout > 0) {
          clearTimeout(this.timeout);
    		}
      }
    }
        this.timeout=setTimeout(function() {this.outputFormat(this.inString);this.i­nString='';this.timeout=0;}.bind(this),1­000);
    };
    
    
About

Avatar for DrAzzy @DrAzzy started