]> the.earth.li Git - temper-clone.git/commitdiff
Switch state machine transitions to increment
authorJonathan McDowell <noodles@earth.li>
Thu, 12 Jul 2018 12:27:53 +0000 (13:27 +0100)
committerJonathan McDowell <noodles@earth.li>
Thu, 12 Jul 2018 12:27:53 +0000 (13:27 +0100)
Rather than explicitly setting the next state just increment
the current state - makes it easier to add extra states.

main.c

diff --git a/main.c b/main.c
index ee6b1a17b7e60d4a90236151df4b11fa9e6b04ac..de54471813640c91a8b5cb4d476ecd4c614e1789 100644 (file)
--- a/main.c
+++ b/main.c
@@ -418,31 +418,31 @@ int main(void)
 
                if (temp_state == 1) {
                        if (w1_reset()) {
-                               temp_state = 2;
+                               temp_state++;
                        } else {
                                temp_state = 0;
                        }
                } else if (temp_state == 2) {
                        w1_write(0xCC);         /* SKIP ROM */
-                       temp_state = 3;
+                       temp_state++;
                } else if (temp_state == 3) {
                        w1_write(0x44);         /* Convert T */
-                       temp_state = 4;
+                       temp_state++;
                } else if (temp_state == 4) {
                        if (w1_read_bit())
-                               temp_state = 5;
+                               temp_state++;
                } else if (temp_state == 5) {
                        if (w1_reset()) {
-                               temp_state = 6;
+                               temp_state++;
                        } else {
                                temp_state = 0;
                        }
                } else if (temp_state == 6) {
                        w1_write(0xCC);         /* SKIP ROM */
-                       temp_state = 7;
+                       temp_state++;
                } else if (temp_state == 7) {
                        w1_write(0xBE);         /* Read Scratchpad */
-                       temp_state = 8;
+                       temp_state++;
                } else if (temp_state > 7 && temp_state < 17) {
                        buf[temp_state - 8] = w1_read_byte();
                        temp_state++;