var i2c,i2c_buf=new Buffer(32),mcu_poll_timer=0,mcu_poll_last=0;function mcu_poll(){try{for(;;){fs.readSync(i2c,i2c_buf,0,1);var c=i2c_buf[0];if(!(0<c))break;fs.readSync(i2c,i2c_buf,1,c);for(var i=[],r=0;r<c;r++)i.push(i2c_buf[r+1]);mcu_process_message(i)}}catch(c){}clearTimeout(mcu_poll_timer),mcu_poll_timer=setTimeout(mcu_poll,500)}function mcu_connect(){log("Connecting to MCU at /dev/i2c-0");try{i2c=fs.openSync("/dev/i2c-0","r+"),mcu_write([100])}catch(c){return void log("Error opening i2c port: ",c)}setTimeout(mcu_poll,100)}function mcu_write(c){try{for(var i=0;i<c.length;i++)i2c_buf[i]=c[i];fs.writeSync(i2c,i2c_buf,0,c.length)}catch(c){log("Error writing to MCU: ",c)}}function mcu_reconnect(){mcu_write([100])}