]> mj.ucw.cz Git - home-hw.git/commitdiff
Test: Experimental air temperature readings
authorMartin Mares <mj@ucw.cz>
Thu, 4 Jul 2019 12:45:47 +0000 (14:45 +0200)
committerMartin Mares <mj@ucw.cz>
Thu, 4 Jul 2019 12:45:47 +0000 (14:45 +0200)
test-opencm3/ds18b20.c
test-opencm3/test.c

index 53df2a674609dde16017e3a65067fb253a5c396d..434af43f9ac8ce7965b6e3cd7b65dbedc694e6bf 100644 (file)
@@ -18,7 +18,7 @@ static volatile u32 ds_dma_buffer;
 #define DS_DMA DMA1
 #define DS_DMA_CH 6
 
-#define DS_DEBUG
+#undef DS_DEBUG
 #undef DS_DEBUG2
 
 #ifdef DS_DEBUG
@@ -379,8 +379,9 @@ void ds_step(void)
                        if (!maxn--)
                                return;
                        ds_current_id++;
-                       if (ds_current_id >= DS_NUM_SENSORS)
+                       if (ds_current_id >= DS_NUM_SENSORS) {
                                ds_current_id = 0;
+                       }
                } while (!ds_sensors[ds_current_id].address[0]);
 #endif
                if (!ds_activate()) {
index 309fc759e6043945ced5d0ac03681f3bc8bf16fb..b765805a6fff1c5cb3817b2f5f17165c6ce94df3 100644 (file)
@@ -58,6 +58,20 @@ static void usart_setup(void)
        usart_enable(USART1);
 }
 
+static void show_temperature(void)
+{
+       debug_putc('#');
+       for (uint i=0; ds_sensors[i].address[0]; i++) {
+               debug_putc(' ');
+               int t = ds_sensors[i].current_temp;
+               if (t == DS_TEMP_UNKNOWN)
+                       debug_puts("---.---");
+               else
+                       debug_printf("%3d.%03d", t / 1000, t % 1000);
+       }
+       debug_puts("\r\n");
+}
+
 int main(void)
 {
        clock_setup();
@@ -66,10 +80,16 @@ int main(void)
        usart_setup();
 
        ds_init();
+
+       byte cycles = 0;
        for (;;) {
                gpio_toggle(GPIOC, GPIO13);
                delay_ms(100);
                ds_step();
+               if (cycles++ >= 50) {
+                       cycles = 0;
+                       show_temperature();
+               }
        }
 
        return 0;