Vladimir N. Shilov 3 лет назад
Родитель
Сommit
6b60f59ca9
5 измененных файлов с 79 добавлено и 117 удалено
  1. 26 26
      Dryer.layout
  2. 3 2
      inc/sensor.h
  3. 2 2
      lib/tinyavrlib/num2str.c
  4. 6 32
      src/main.c
  5. 42 55
      src/sensor.c

+ 26 - 26
Dryer.layout

@@ -2,29 +2,29 @@
 <CodeBlocks_layout_file>
 	<FileVersion major="1" minor="0" />
 	<ActiveTarget name="Debug" />
-	<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="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="4343" topLine="110" />
+			<Cursor1 position="951" topLine="0" />
 		</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\ssd1306xled\ssd1306xledtx.c" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="2252" topLine="56" />
+			<Cursor1 position="2451" topLine="66" />
 		</Cursor>
 	</File>
-	<File name="src\main.c" open="1" top="1" tabpos="1" 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="2436" topLine="54" />
+			<Cursor1 position="3534" topLine="60" />
 		</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">
+	<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="2451" topLine="66" />
+			<Cursor1 position="1062" topLine="33" />
 		</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="src\main.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="2098" topLine="0" />
+			<Cursor1 position="1393" topLine="41" />
 		</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">
@@ -32,44 +32,44 @@
 			<Cursor1 position="88" topLine="0" />
 		</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\rtos\rtos.h" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="951" topLine="0" />
+			<Cursor1 position="2098" 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="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="357" topLine="0" />
+			<Cursor1 position="1177" topLine="0" />
 		</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="inc\sensor.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="1062" topLine="33" />
+			<Cursor1 position="371" 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="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="2091" topLine="18" />
+			<Cursor1 position="1017" topLine="24" />
 		</Cursor>
 	</File>
-	<File name="src\sensor.c" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="src\sensor.c" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="1927" topLine="70" />
+			<Cursor1 position="2212" topLine="96" />
 		</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="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="1177" topLine="0" />
+			<Cursor1 position="5259" topLine="131" />
 		</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="inc\main.h" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="5259" topLine="131" />
+			<Cursor1 position="2252" topLine="56" />
 		</Cursor>
 	</File>
-	<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>
 </CodeBlocks_layout_file>

+ 3 - 2
inc/sensor.h

@@ -19,13 +19,14 @@ typedef enum {
 
 /* Data type */
 typedef struct {
-  uint16_t Humidity;
-  uint16_t Temperature;
+  uint8_t Humidity;
+   int8_t Temperature;
 } aht10_t;
 
 /* Function */
 aht10_st_t AHT10_Init(void);
 aht10_st_t AHT10_StartMeasure(void);
+aht10_st_t AHT10_SoftReset(void);
 aht10_st_t AHT10_GetData(aht10_t * data);
 
 #endif /* _SENSOR_H_ */

+ 2 - 2
lib/tinyavrlib/num2str.c

@@ -18,7 +18,7 @@
 #include "num2str.h"
 
 // ----------------------------------------------------------------------------
-//  NOTE: The resulting ASCII text should not be terminated with '\0' in the 
+//  NOTE: The resulting ASCII text should not be terminated with '\0' in the
 //        functions below because the buffer might be part of a larger text.
 // ----------------------------------------------------------------------------
 
@@ -83,7 +83,7 @@ uint8_t usint2binascii(uint16_t num, char *buffer) {
 		if (digits == USINT2BINASCII_MAX_DIGITS - 1) {
 			if (digit == 0) {
 				if (pos < USINT2BINASCII_MAX_DIGITS - 1) // Check position, so single "0" will be handled properly.
-					digit = 0; // Use: "-16" for space (' '), "-3" for dash/minus ('-'), "0" for zero ('0'), etc.
+					digit = -3; // Use: "-16" for space (' '), "-3" for dash/minus ('-'), "0" for zero ('0'), etc.
 			} else {
 				digits = pos;
 			}

+ 6 - 32
src/main.c

@@ -10,7 +10,7 @@
 #include "ssd1306xled/ssd1306xled.h"
 #include "ssd1306xled/ssd1306xledtx.h"
 #include "tinyavrlib/num2str.h"
-//#include "string.h"
+#include "string.h"
 
 /* Defines */
 
@@ -51,25 +51,18 @@ int main(void) {
   RTOS_SetTask(LedOn, 1, 1000);
   RTOS_SetTask(LedOff, 201, 1000);
 
-//  ssd1306_fill2(0xff, 0x00);
   ssd1306_clear();
 //  ssd1306tx_init(ssd1306xled_font6x8data, 0);
-  // ssd1306xled_font8x16data
   ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 0, 0, "Hello, World! :)");
 //  ssd1306_setpos(0, 3);
 //  ssd1306tx_string("SSD1306xLED Library");
-//  ssd1306_setpos(0, 3);
-//  ssd1306tx_string("!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[5]^_`");
-//  ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 0, 5, "TINUSAUR Project");
-//  ssd1306_setpos(0, 7);
-//  ssd1306tx_string("http://tinusaur.org");
   tdelay_ms(1000);
 
   ssd1306_clear();
   ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 1, 0, "Set:");
   ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 1, 3, "  T:");
   ssd1306tx_stringxy((uint8_t const *)ssd1306xled_font8x16data, 1, 5, "  H:");
-  char buffer[6] = {'\0'};
+  char buffer[9] = {0};
   uint8_t digits = 0;
 
   /* Infinity loop */
@@ -77,42 +70,23 @@ int main(void) {
 
   if (Flag.newTempSet != 0) {
     Flag.newTempSet = 0;
-    /*
-    ssd1306_setpos(25, 0);
-    ssd1306tx_numdec(TemperatureSetpoint);
-    ssd1306tx_string(" C");
-    */
     if (TemperatureSetpoint != 0) {
       digits = usint2decascii(TemperatureSetpoint, buffer);
+      strncpy(buffer+5, " C \0", 4);
       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");
     }
   }
 
-    //ssd1306_setpos(13, 3);
     if (Flag.AHT10state == 0) {
-        /*
-      ssd1306tx_numdec(Sensor.Temperature);
-      ssd1306tx_string(" C");
-      ssd1306_setpos(13, 5);
-      ssd1306tx_numdec(Sensor.Humidity);
-      ssd1306tx_string(" P");
-      */
-/*
-      digits = usint2decascii((int8_t)Sensor.Temperature, buffer);
+      digits = usint2decascii(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);
+      strncpy(buffer+5, " %\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");

+ 42 - 55
src/sensor.c

@@ -1,33 +1,6 @@
 #include "sensor.h"
 #include "i2c.h"
 
-/* Type def */
-typedef union {
-  uint32_t  u32;
-  struct {
-    #ifdef LITTLE_ENDIAN  // Byte-order is little endian
-    uint8_t u8ll;
-    uint8_t u8lh;
-    uint8_t u8hl;
-    uint8_t u8hh;
-    #else                 // Byte-order is big endian
-    uint8_t u8hh;
-    uint8_t u8hl;
-    uint8_t u8lh;
-    uint8_t u8ll;
-    #endif
-  } s8;
-  struct {
-    #ifdef LITTLE_ENDIAN  // Byte-order is little endian
-    uint8_t u16l;
-    uint8_t u16h;
-    #else                 // Byte-order is big endian
-    uint8_t u16h;
-    uint8_t u16l;
-    #endif
-  } s16;
-} nt32_t;
-
 /* Defines */
 #define I2C_ADDR    0x70
 
@@ -51,7 +24,28 @@ aht10_st_t AHT10_Init(void)
     return AHT10_St_Err;
   }
 
-  res = I2C_WriteByte(CMD_INIT);
+  res = I2C_WriteByte(CMD_SRESET);
+  if (res != I2C_Ret_OK) {
+    return AHT10_St_Err;
+  }
+
+  I2C_Stop();
+
+  return AHT10_St_OK;
+}
+
+aht10_st_t AHT10_SoftReset(void)
+{
+  i2c_status_t res;
+
+  I2C_Start();
+
+  res = I2C_WriteByte(I2C_ADDR);
+  if (res != I2C_Ret_OK) {
+    return AHT10_St_Err;
+  }
+
+  res = I2C_WriteByte(CMD_SRESET);
   if (res != I2C_Ret_OK) {
     return AHT10_St_Err;
   }
@@ -107,37 +101,30 @@ aht10_st_t AHT10_GetData(aht10_t * data)
     return AHT10_St_Bsy;
   }
   /* Calculate values */
-  nt32_t result = {0};
+  uint32_t result;
+  //nt32_t result = {0};
 
   /* Humidity = Srh * 100% / 2^20 */
-/*
-  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;
+  result = buf[1];
+  result <<= 8;
+  result |= buf[2];
+  result <<= 8;
+  result |= buf[3];
+  result >>= 4;
+  result *= 100;
+  result /= 1048576;
+  data->Humidity = (uint8_t)result;
 
   /* Temperature = St * 200 / 2^20 - 50 */
-/*
-  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;
+  result = buf[3] & 0xf;
+  result <<= 8;
+  result |= buf[4];
+  result <<= 8;
+  result |= buf[5];
+  result *= 200;
+  result /= 1048576;
+  result -= 50;
+  data->Temperature = (int8_t)result;
 
   return AHT10_St_OK;
 }