Vladimir N. Shilov 3 лет назад
Родитель
Сommit
d6a9cb8b2c
4 измененных файлов с 64 добавлено и 42 удалено
  1. 27 27
      Dryer.layout
  2. 2 2
      inc/sensor.h
  3. 11 1
      src/main.c
  4. 24 12
      src/sensor.c

+ 27 - 27
Dryer.layout

@@ -2,74 +2,74 @@
 <CodeBlocks_layout_file>
 	<FileVersion major="1" minor="0" />
 	<ActiveTarget name="Debug" />
-	<File name="lib\ssd1306xled\font8x16.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\rtos\rtos.c" open="0" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="1017" topLine="24" />
+			<Cursor1 position="4343" topLine="110" />
 		</Cursor>
 	</File>
-	<File name="lib\rtos\rtos.c" open="0" top="0" tabpos="11" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="inc\main.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="4343" topLine="110" />
+			<Cursor1 position="2252" topLine="56" />
 		</Cursor>
 	</File>
-	<File name="src\i2c.c" open="0" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="src\main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="1062" topLine="33" />
+			<Cursor1 position="2436" topLine="54" />
 		</Cursor>
 	</File>
 	<File name="lib\ssd1306xled\ssd1306xledtx.c" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="2451" topLine="68" />
+			<Cursor1 position="2451" topLine="66" />
 		</Cursor>
 	</File>
-	<File name="src\sensor.c" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\rtos\rtos.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="2150" topLine="95" />
+			<Cursor1 position="2098" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="lib\ssd1306xled\ssd1306xled.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="inc\i2c.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="1177" topLine="0" />
+			<Cursor1 position="88" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="lib\rtos\rtos.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\ssd1306xled\ssd1306xledtx.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="2098" topLine="0" />
+			<Cursor1 position="951" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="lib\tinyavrlib\num2str.c" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="inc\sensor.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="2700" topLine="6" />
+			<Cursor1 position="357" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="inc\sensor.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="src\i2c.c" open="0" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="350" topLine="0" />
+			<Cursor1 position="1062" topLine="33" />
 		</Cursor>
 	</File>
-	<File name="inc\main.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\tinyavrlib\num2str.c" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="2252" topLine="76" />
+			<Cursor1 position="2091" topLine="18" />
 		</Cursor>
 	</File>
-	<File name="lib\ssd1306xled\ssd1306xled.c" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="src\sensor.c" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="5259" topLine="131" />
+			<Cursor1 position="1927" topLine="70" />
 		</Cursor>
 	</File>
-	<File name="inc\i2c.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\ssd1306xled\ssd1306xled.h" open="1" top="0" tabpos="10" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="88" topLine="0" />
+			<Cursor1 position="1177" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="src\main.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\ssd1306xled\ssd1306xled.c" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="3104" topLine="78" />
+			<Cursor1 position="5259" topLine="131" />
 		</Cursor>
 	</File>
-	<File name="lib\ssd1306xled\ssd1306xledtx.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="lib\ssd1306xled\font8x16.h" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="951" topLine="0" />
+			<Cursor1 position="1017" topLine="24" />
 		</Cursor>
 	</File>
 </CodeBlocks_layout_file>

+ 2 - 2
inc/sensor.h

@@ -19,8 +19,8 @@ typedef enum {
 
 /* Data type */
 typedef struct {
-  uint8_t Humidity;
-  int8_t Temperature;
+  uint16_t Humidity;
+  uint16_t Temperature;
 } aht10_t;
 
 /* Function */

+ 11 - 1
src/main.c

@@ -10,6 +10,7 @@
 #include "ssd1306xled/ssd1306xled.h"
 #include "ssd1306xled/ssd1306xledtx.h"
 #include "tinyavrlib/num2str.h"
+//#include "string.h"
 
 /* Defines */
 
@@ -84,6 +85,7 @@ int main(void) {
     if (TemperatureSetpoint != 0) {
       digits = usint2decascii(TemperatureSetpoint, buffer);
       ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 0, buffer+digits);
+      //strncpy(buffer+5, " C \0", 4);
       ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 56, 0, " C ");
     } else {
       ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 0, " Off");
@@ -99,10 +101,18 @@ int main(void) {
       ssd1306tx_numdec(Sensor.Humidity);
       ssd1306tx_string(" P");
       */
+/*
       digits = usint2decascii((int8_t)Sensor.Temperature, buffer);
+      strncpy(buffer+5, " C\0", 3);
       ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 3, buffer+digits);
       digits = usint2decascii(Sensor.Humidity, buffer);
+      strncpy(buffer+5, " P\0", 3);
       ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 5, buffer+digits);
+*/
+      usint2hexascii(Sensor.Temperature, buffer);
+      ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 3, buffer);
+      digits = usint2hexascii(Sensor.Humidity, buffer);
+      ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 5, buffer);
     } else {
       //ssd1306tx_string("AHT10 error");
       ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 40, 3, "Error");
@@ -111,7 +121,7 @@ int main(void) {
 
     RTOS_DispatchTask();
 
-    // делать нечего -- спим, ждём прерывание
+    // nothing to do - sleep, wait for interrupt
 #if defined(__GNUC__)
     set_sleep_mode(SLEEP_MODE_IDLE);
     sleep_mode();

+ 24 - 12
src/sensor.c

@@ -107,25 +107,37 @@ aht10_st_t AHT10_GetData(aht10_t * data)
     return AHT10_St_Bsy;
   }
   /* Calculate values */
-  nt32_t tmp, result;
+  nt32_t result = {0};
 
   /* Humidity = Srh * 100% / 2^20 */
-  tmp.s8.u8hl = buf[1];
-  tmp.s8.u8lh = buf[2];
-  tmp.s8.u8ll = buf[3];
-  result.u32 = tmp.u32 >> 4;
+/*
+  result.s8.u8hl = buf[1];
+  result.s8.u8lh = buf[2];
+  result.s8.u8ll = buf[3];
+  result.u32 >>= 4;
   result.u32 *= 100;
   result.s16.u16h >>= 4;
+  data->Humidity = result.s16.u16l;
+*/
+  result.s8.u8hh = buf[1];
+  result.s8.u8hl = buf[2];
   data->Humidity = result.s16.u16h;
 
   /* Temperature = St * 200 / 2^20 - 50 */
-  tmp.s8.u8hl = buf[3] & 0xf;
-  tmp.s8.u8lh = buf[4];
-  tmp.s8.u8ll = buf[5];
-  tmp.u32 *= 200;
-  tmp.s16.u16h >>= 4;
-  //tmp.s16.u16h -= 50;
-  data->Temperature = tmp.s16.u16h;
+/*
+  result.s8.u8hl = buf[3] & 0xf;
+  result.s8.u8lh = buf[4];
+  result.s8.u8ll = buf[5];
+  result.u32 *= 200;
+  result.s16.u16h >>= 4;
+  result.s16.u16h -= 50;
+  data->Temperature = result.s16.u16h;
+*/
+  result.s8.u8hh = buf[3] & 0xf;
+  result.s8.u8hl = buf[4];
+  result.s8.u8lh = buf[5];
+  result.u32 <<= 4;
+  data->Temperature = result.s16.u16h;
 
   return AHT10_St_OK;
 }