1 #include "humiture.h"
2 #include "drv_temp_humi_si_si7006.h"
3 #include "drv_temp_humi_sensylink_cht8305.h"
4 #include "../menu.h"
5
6 MENU_COVER_TYP humiture_cover = {MENU_COVER_NONE};
7 MENU_TASK_TYP humiture_tasks = {humiture_init, humiture_uninit};
8 MENU_TYP humiture = {"humiture", &humiture_cover, &humiture_tasks, NULL, NULL};
9
10 static int running = 1;
11
12 static aos_task_t humiture_task_handle;
13
humiture_init(void)14 int humiture_init(void)
15 {
16 if (g_haasboard_is_k1c) {
17 cht8305_init();
18 LOGI(EDU_TAG, "cht8305_init done\n");
19 } else {
20 si7006_init();
21 LOGI(EDU_TAG, "si7006_init done\n");
22 }
23
24 OLED_Clear();
25 OLED_Refresh_GRAM();
26 running = 1;
27 aos_task_new_ext(&humiture_task_handle, "humiture_task", humiture_task, NULL, 1024, AOS_DEFAULT_APP_PRI);
28 LOGI(EDU_TAG, "aos_task_delete humiture_task\n");
29 return 0;
30 }
31
humiture_task(void)32 void humiture_task(void)
33 {
34 float temp, hump;
35 uint8_t temp_str[10];
36 uint8_t hump_str[10];
37 unsigned char c = 0;
38
39 while (running) {
40 if (g_haasboard_is_k1c) {
41 cht8305_getTempHumidity(&hump, &temp);
42 } else {
43 si7006_getTempHumidity(&hump, &temp);
44 }
45
46 sprintf(temp_str, "T:%5.1fC", temp);
47 sprintf(hump_str, "H:%5.1f%%", hump);
48 // LOGD(EDU_TAG, "%s %s", temp_str, hump_str);
49 OLED_Icon_Draw(14, 4, &icon_thermometer_24_24, 0);
50 OLED_Icon_Draw(14, 36, &icon_hygrometer_24_24, 0);
51
52 OLED_Icon_Draw(2, 24, &icon_skip_left, 0);
53 OLED_Icon_Draw(122, 24, &icon_skip_right, 0);
54
55 OLED_Show_String(42, 8, temp_str, 16, 1);
56 OLED_Show_String(42, 40, hump_str, 16, 1);
57
58 OLED_Refresh_GRAM();
59 aos_msleep(500);
60 }
61 running = 1;
62 }
63
humiture_uninit(void)64 int humiture_uninit(void)
65 {
66 running = 0;
67
68 while (!running) {
69 aos_msleep(50);
70 }
71 if (g_haasboard_is_k1c) {
72 cht8305_deinit();
73 LOGI(EDU_TAG, "cht8305_deinit done\n");
74 } else {
75 si7006_deinit();
76 LOGI(EDU_TAG, "si7006_deinit done\n");
77 }
78
79 aos_task_delete(&humiture_task_handle);
80 LOGI(EDU_TAG, "aos_task_delete humiture_task\n");
81 return 0;
82 }
83