guowenxue
2021-08-29 77ddd4a0943e2f9935bec2e00fffacec370cc1aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**********************************************************************
*   Copyright: (C)2021 LingYun IoT System Studio <www.weike-iot.com>
*      Author: GuoWenxue<guowenxue@gmail.com> QQ: 281143292
* Description: BearKE1 NB-IoT Board OLED display test source code
*
*      Notice: Must implement delay_us() by timer in tim.h first.
*
*   ChangeLog:
*        Version    Date       Author            Description
*        V1.0.0  2021.08.10  GuoWenxue      Release initial version
***********************************************************************/
#include <stdio.h>
#include "oled.h"
#include "hal_oled.h"
#include "font_bmp.h"
#include "font_hzk.h"
 
/*
 *+-------------------------------------------------+
 *|            OLED Board display API               |
 *+-------------------------------------------------+
 */ 
 
void OLED_ShowBanner(int showtime)
{
    uint8_t          i;
    uint8_t          pos_x = 25;
    uint8_t          pos_y = 0;    
    
    OLED_Clear();
    OLED_DrawBMP(0,0,128,7, &LOGO_BMP[0][0]);
    HAL_Delay(showtime);
 
    OLED_Clear();
 
    for(i=0; i<HZK_LEN_LINGYUN; i++)
        OLED_ShowChinese(Hzk_LingYun, pos_x+i*16, pos_y, i);
 
    pos_x = 5;
    pos_y = 2;
    OLED_ShowString(pos_x, pos_y, "Hello, LingYun!", OLED_FONT16);
 
    HAL_Delay(showtime);
}
 
 
void OLED_ShowTempHumdity(uint32_t temp, uint32_t humd, int showtime)
{
    uint8_t          i;
    char             temp_str[10] = {0}; /* Tempearute  : 28.32'C */
    char             humd_str[16] = {0}; /* Humidity    : 58.39%  */
    uint8_t          pos_x = 5;
    uint8_t          pos_y = 0;
    
    snprintf(temp_str, sizeof(temp_str), ": %02d.%02d\'C", (int)temp/100, (int)temp%100);
    snprintf(humd_str, sizeof(humd_str), ": %02d.%02d%%",  (int)humd/100, (int)humd%100);
    
    OLED_Clear();
    
    for(i=0; i<2*HZK_LEN_TEMP; i++)
        OLED_ShowChinese(Hzk_Temp, pos_x+i*16, pos_y, i);
    
    pos_x += 16*HZK_LEN_TEMP;
    OLED_ShowString(pos_x, pos_y, temp_str, OLED_FONT16);
    
    pos_x = 5;
    pos_y = 2;
    
    for(i=0; i<HZK_LEN_HUMD; i++)
        OLED_ShowChinese(Hzk_Humd, pos_x+i*16, pos_y, i);    
    
    pos_x += 16*HZK_LEN_HUMD;
    OLED_ShowString(pos_x, pos_y, humd_str, OLED_FONT16);    
    
    HAL_Delay(showtime);    
}
 
void OLED_ShowLightNoisy(uint32_t light, uint32_t noisy, int showtime)
{
    uint8_t          i;
    char             light_str[10] = {0}; 
    char             noisy_str[16] = {0}; 
    uint8_t          pos_x = 5;
    uint8_t          pos_y = 0;
    
    snprintf(light_str, sizeof(light_str), ": %04d", (int)light);
    snprintf(noisy_str, sizeof(noisy_str), ": %04d", (int)noisy);
    
    OLED_Clear();
    
    for(i=0; i<2*HZK_LEN_LIGHT; i++)
        OLED_ShowChinese(Hzk_Light, pos_x+i*16, pos_y, i);
    
    pos_x += 16*HZK_LEN_LIGHT;
    OLED_ShowString(pos_x, pos_y, light_str, OLED_FONT16);
    
    pos_x = 5;
    pos_y = 2;
    
    for(i=0; i<HZK_LEN_NOISY; i++)
        OLED_ShowChinese(Hzk_Noisy, pos_x+i*16, pos_y, i);    
    
    pos_x += 16*HZK_LEN_NOISY;
    OLED_ShowString(pos_x, pos_y, noisy_str, OLED_FONT16);    
    
    HAL_Delay(showtime);    
}