1 /* 2 * Copyright (C) 2022 HiHope Open Source Organization . 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * 14 * limitations under the License. 15 */ 16 17 #include <stdio.h> 18 #include <stdlib.h> 19 #include <memory.h> 20 21 #include "ohos_init.h" 22 #include "cmsis_os2.h" 23 #include "iot_gpio.h" 24 #include "hi_io.h" 25 #include "hi_time.h" 26 27 28 #define GPIO11 11 29 #define GPIO12 12 30 #define TASK_STAK_SIZE (1024*10) get_tcrt5000_value(void)31void get_tcrt5000_value (void) 32 { 33 IotGpioValue id_status; 34 IoTGpioGetInputVal(GPIO11, &id_status); 35 if (id_status == IOT_GPIO_VALUE0) { 36 printf("left black\r\n"); 37 } else { 38 printf("left white\r\n"); 39 } 40 IoTGpioGetInputVal(GPIO12, &id_status); 41 if (id_status == IOT_GPIO_VALUE0) { 42 printf("right black\r\n"); 43 } else { 44 printf("right white\r\n"); 45 } 46 } 47 RobotTask(void * parame)48void RobotTask(void* parame) 49 { 50 (void)parame; 51 printf("start test tcrt5000\r\n"); 52 unsigned int time = 2000; 53 while (1) { 54 hi_sleep(time); 55 get_tcrt5000_value(); 56 } 57 } 58 59 RobotDemo(void)60static void RobotDemo(void) 61 { 62 osThreadAttr_t attr; 63 64 attr.name = "RobotTask"; 65 attr.attr_bits = 0U; 66 attr.cb_mem = NULL; 67 attr.cb_size = 0U; 68 attr.stack_mem = NULL; 69 attr.stack_size = TASK_STAK_SIZE; 70 attr.priority = osPriorityNormal; 71 72 if (osThreadNew(RobotTask, NULL, &attr) == NULL) { 73 printf("[RobotDemo] Failed to create RobotTask!\n"); 74 } 75 } 76 77 APP_FEATURE_INIT(RobotDemo); 78