#include <stdio.h>#include <string.h>#include <strings.h>#include <stdlib.h>#include <unistd.h>#include "ohos_init.h"#include "cmsis_os2.h"#include "genki_base.h"#include "genki_web_ohosdog.h"#include "genki_web.h"#include "genki_pin.h"#include "dog.h"#include "led.h"#include "beep.h"#include "lcd_st7735.h"static void init_service(void){genki_web_register(newDogService());}static void start(void){IoTIoSetFunc(IOT_IO_NAME_10, IOT_IO_FUNC_10_I2C0_SDA);IoTIoSetFunc(IOT_IO_NAME_9, IOT_IO_FUNC_9_I2C0_SCL);IoTI2cInit(0, 400000);init_led();init_beep();init_service();dog_init();genki_services_start();dog_install();// ST7735_LCD_Init();// LCD_ShowString(8, 8, "Hello Word", BLACK, BLUE, 16, 1);}APP_FEATURE_INIT(start);
void dog_install(void){dog_setLeftFrontAngle(45, 135);dog_setLeftBackAngle(45, 135);dog_setRightFrontAngle(45, 135);dog_setRightBackAngle(45, 135);}
void dog_execJson(char *buf, int len){cJSON *recv_json;recv_json = cJSON_ParseWithLength(buf, len);int type = cJSON_GetObjectItem(recv_json, "type")->valueint;if (type == 1){dog_install();}else if (type == 2){int index = cJSON_GetObjectItem(recv_json, "index")->valueint;// cJSON *data_json;// data_json = cJSON_GetObjectItem(recv_json, "data");// int alpha = cJSON_GetArrayItem(data_json, 0)->valueint;// int beta = cJSON_GetArrayItem(data_json, 1)->valueint;// if (index == 0) {// dog_setLeftFrontAngle(alpha, beta);// } else if (index == 1) {// dog_setLeftBackAngle(alpha, beta);// } else if (index == 2) {// dog_setRightFrontAngle(alpha, beta);// } else if (index == 3) {// dog_setRightBackAngle(alpha, beta);// }if (index == 0) // squat{dog_setLeftFrontAngle(15, 165);dog_setLeftBackAngle(15, 165);dog_setRightFrontAngle(15, 165);dog_setRightBackAngle(15, 165);}else if (index == 1) // stand up{dog_setLeftFrontAngle(85, 70);dog_setLeftBackAngle(85, 70);dog_setRightFrontAngle(85, 70);dog_setRightBackAngle(85, 70);}else if (index == 2) // Lie forward{dog_setLeftFrontAngle(-40, 45);dog_setRightFrontAngle(-40, 45);dog_setLeftBackAngle(45, 90);dog_setRightBackAngle(45, 90);}else if (index == 3) // Lie down{dog_setLeftFrontAngle(90, 135);dog_setRightFrontAngle(90, 135);dog_setLeftBackAngle(160, 180);dog_setRightBackAngle(160, 180);}}else if (type == 3){int execute_count = 1;if (cJSON_HasObjectItem(recv_json, "count")){execute_count = cJSON_GetObjectItem(recv_json, "count")->valueint;}dog_action_t *action = malloc(sizeof(dog_action_t));action->exec_count = execute_count;//Send multiple messagescJSON *list_json;list_json = cJSON_GetObjectItem(recv_json, "list");int count = cJSON_GetArraySize(list_json);action->len = count;action->cmds = malloc(sizeof(dog_cmd_t) * count);for (int i = 0; i < count; i++){cJSON *item_json;item_json = cJSON_GetArrayItem(list_json, i);dog_cmd_t cmd;cmd.angle[0] = cJSON_GetArrayItem(item_json, 0)->valueint;cmd.angle[1] = cJSON_GetArrayItem(item_json, 1)->valueint;cmd.angle[2] = cJSON_GetArrayItem(item_json, 2)->valueint;cmd.angle[3] = cJSON_GetArrayItem(item_json, 3)->valueint;cmd.angle[4] = cJSON_GetArrayItem(item_json, 4)->valueint;cmd.angle[5] = cJSON_GetArrayItem(item_json, 5)->valueint;cmd.angle[6] = cJSON_GetArrayItem(item_json, 6)->valueint;cmd.angle[7] = cJSON_GetArrayItem(item_json, 7)->valueint;cmd.duration = cJSON_GetArrayItem(item_json, 8)->valueint;action->cmds[i] = cmd;}dog_execAction(action);}cJSON_Delete(recv_json);}
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet