1 /*
2 * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3 */
4
5 #include "aos/init.h"
6 #include "board.h"
7 #include "k1_apps/menu.h"
8 #include <aos/errno.h>
9 #include <aos/kernel.h>
10 #include <k_api.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <uservice/eventid.h>
14 // #include "drivers/lcd/st7789v/st7789v_vfs.h"
15 // #include "drivers/lcd/st7789v/st7789v.h"
16 #include "netmgr.h"
17
18 extern int board_test(void);
19 extern void vendor_cli_register_init(void);
20 int g_haasboard_is_k1c = 0;
21
22 int bt_connected = 0;
23 int wifi_connected = 0;
24 int ip_got_finished = 0;
25 char eduk1_ip_addr[IPADDR_STR_LEN] = {0};
26
demo_main(int argc,char * argv[])27 int demo_main(int argc, char *argv[])
28 {
29 int ret = 0;
30
31 while (1)
32 {
33 if (wifi_connected && !ip_got_finished)
34 {
35 ret = netmgr_wifi_get_ip_addr(&eduk1_ip_addr);
36
37 if (ret ==0)
38 ip_got_finished = 1;
39 }
40 aos_msleep(1000);
41 }
42 }
43
entry_func(void * data)44 static void entry_func(void *data)
45 {
46 demo_main(0 , NULL);
47 }
48
wifi_event_cb(uint32_t event_id,const void * param,void * context)49 static void wifi_event_cb(uint32_t event_id, const void *param, void *context)
50 {
51 switch (event_id)
52 {
53 case EVENT_NETMGR_DHCP_SUCCESS:
54 wifi_connected = 1;
55 aos_task_new("link_dmeo", entry_func, NULL, 6*1024);
56 break;
57
58 case EVENT_NETMGR_WIFI_DISCONNECTED:
59 wifi_connected = 0;
60 break;
61
62 default:
63 break;
64 }
65 return;
66 }
67 extern int haasedu_is_k1c();
68
application_start(int argc,char ** argv)69 int application_start(int argc, char **argv)
70 {
71 int ret;
72
73 aos_set_log_level(AOS_LL_INFO);
74 event_service_init(NULL);
75
76 netmgr_service_init(NULL);
77
78 /*enable network auto reconnect*/
79 netmgr_set_auto_reconnect(NULL, true);
80
81 /*enable auto save wifi config*/
82 netmgr_wifi_set_auto_save_ap(true);
83
84 event_subscribe(EVENT_NETMGR_DHCP_SUCCESS, wifi_event_cb, NULL);
85
86 g_haasboard_is_k1c = haasedu_is_k1c();
87 sh1106_init();
88 menu_init();
89
90 ret = BleCfg_run();
91 if (ret) {
92 return ret;
93 }
94
95 aos_msleep(100);
96
97 (void)BleCfg_recovery_wifi();
98 (void)BleCfg_recovery_devinfo();
99
100 return 0;
101 }
102