+
+ if (temp_state == 1) {
+ if (w1_reset()) {
+ temp_state = 2;
+ } else {
+ temp_state = 0;
+ }
+ } else if (temp_state == 2) {
+ w1_write(0xCC); /* SKIP ROM */
+ temp_state = 3;
+ } else if (temp_state == 3) {
+ w1_write(0x44); /* Convert T */
+ temp_state = 4;
+ } else if (temp_state == 4) {
+ if (w1_read_bit())
+ temp_state = 5;
+ } else if (temp_state == 5) {
+ if (w1_reset()) {
+ temp_state = 6;
+ } else {
+ temp_state = 0;
+ }
+ } else if (temp_state == 6) {
+ w1_write(0xCC); /* SKIP ROM */
+ temp_state = 7;
+ } else if (temp_state == 7) {
+ w1_write(0xBE); /* Read Scratchpad */
+ temp_state = 8;
+ } else if (temp_state > 7 && temp_state < 17) {
+ buf[temp_state - 8] = w1_read_byte();
+ temp_state++;
+ } else if (temp_state == 17) {
+ last_temp = buf[1] << 12 | buf[0] << 4;
+ temp_state = 0;
+ last_temp_time = millis();
+ }
+
+ if (temp_state == 0 &&
+ (millis() - last_temp_time) > TEMP_INTERVAL) {
+ temp_state = 1;
+ }