1 /*
2  * Copyright (C) 2021-2023 Alibaba Group Holding Limited
3  */
4 
5 #include <stdint.h>
6 #include <stdio.h>
7 #include "wifi_camera.h"
8 #include "ucamera_service.h"
9 #include "ulog/ulog.h"
10 
11 #if AOS_COMP_CLI
12 #include "aos/cli.h"
13 #endif
14 #define TAG "ucamera_example"
15 #define LOG printf
16 
17 #define CAPTURED_IMAGE "/data/capture.jpg"
18 
ucamera_comp_example(int argc,char ** argv)19 static void ucamera_comp_example(int argc, char **argv)
20 {
21     int ret;
22     frame_buffer_t *frame = NULL;
23 
24     if (argc < 3)
25         LOG("wrong parameter number\n");
26 
27     if (!strncmp(argv[1], "init", 4)) {
28         /*init network*/
29         event_service_init(NULL);
30         netmgr_service_init(NULL);
31         LOG("ucamera comp init successfully!\n");
32     } else if (!strncmp(argv[1], "-t", 2)) {
33         if (!strcmp(argv[2], "wifi")) {
34             /*init ucamera service*/
35             ret = ucamera_service_init("wifi_camera");
36             if (ret < 0) {
37                 LOGE(TAG, "ucamera service init fail\n");
38                 return;
39             }
40 
41             /*get one camera frame*/
42             frame = ucamera_service_get_frame();
43             if (!frame) {
44                 LOGE(TAG, "ucamera get frame fail\n");
45                 return;
46             } else {
47                 LOG("ucamera get frame OK!\n");
48             }
49 
50             /*save frame to jpeg file*/
51             ret = ucamera_service_save_frame(frame, CAPTURED_IMAGE);
52             if (ret < 0) {
53                 LOGE(TAG, "save image fail\n");
54                 return;
55             } else {
56                 LOG("save image to %s successfully!\n", CAPTURED_IMAGE);
57             }
58 
59             /*uninit ucamera service*/
60             ucamera_service_uninit();
61         } else {
62             LOG("unknown camera device type!\n");
63         }
64     }
65     return;
66 }
67 
68 #if AOS_COMP_CLI
69 /* reg args: fun, cmd, description*/
70 ALIOS_CLI_CMD_REGISTER(ucamera_comp_example, ucamera, ucamera component base example)
71 #endif
72