Commit 85f391b7 authored by 957dd's avatar 957dd

限位使用线程池进行打开和关闭线程,pwm和pin控制使用了结构体

parent 193b8804
......@@ -38,7 +38,8 @@ int main(){
my_zlog_warn("此版本电压没有使用INA226");
}
int thread_rc=thread_start_init( thread_exit_time,thread_mqtt_beat,thread_open_browser,thread_mqtt_reconnect,thread_time_calculation,thread_play_mp3);
int thread_rc=thread_start_init( thread_exit_time,thread_mqtt_beat,
thread_open_browser,thread_mqtt_reconnect,thread_time_calculation,thread_play_mp3);
if(thread_rc != 0){
my_zlog_warn("多线程初始化失败");
return -7;
......
......@@ -10,14 +10,17 @@
#include "browser_open.h"
#include "device_init.h"
#include "audioplay.h"
#include "gpio_init.h"
pthread_t g_thread[6]; // 全局线程句柄数组(或传参)
#define PTHREAD_MAX 6
int g_webrtc_index=0;
pthread_t g_thread[PTHREAD_MAX]; // 全局线程句柄数组(或传参)
int g_webrtc_index=0;//判断游览器是否打开
int g_mqtt_grc=0;
void* g_args[6] = { NULL, NULL, NULL, NULL, NULL, NULL };
void* g_args[PTHREAD_MAX] = { NULL};
int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat,
ThreadFunc thread_open_browser, ThreadFunc thread_mqtt_reconnect,
......@@ -32,7 +35,7 @@ int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat,
thread_play_mp3
};
for (int i = 0; i < 6; i++) {
for (int i = 0; i < PTHREAD_MAX; i++) {
if (pthread_create(&g_thread[i], NULL, thread_funcs[i], g_args[i]) != 0) {
my_zlog_error("创建线程 %d 失败", i);
return i + 1;
......@@ -168,7 +171,7 @@ void *thread_play_mp3(void* arg) {
// 等待线程结束
void thread_end_close() {
for (int i = 0; i < 6; i++) {
for (int i = 0; i < PTHREAD_MAX; i++) {
if (g_thread[i]) pthread_join(g_thread[i], NULL);
}
}
......
#ifndef PTHREAD_OPEN_H__
#define PTHREAD_OPEN_H__
typedef void *(*ThreadFunc)(void *);
int thread_start_init(ThreadFunc thread_exit_time, ThreadFunc thread_mqtt_beat,
......@@ -12,6 +13,7 @@ void *thread_open_browser(void *arg) ;//启动游览器线程
void *thread_mqtt_reconnect(void *arg) ;//mqtt自带重连线程
void *thread_time_calculation(void *arg) ;//延时计算延迟
void *thread_play_mp3(void* arg);//等待播放音频线程
void thread_end_close() ;
#endif
\ No newline at end of file
......@@ -774,6 +774,30 @@ drivers/gpio/device_init.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/gpio/device_init.c.s
.PHONY : drivers/gpio/device_init.c.s
drivers/gpio/gpio_control.o: drivers/gpio/gpio_control.c.o
.PHONY : drivers/gpio/gpio_control.o
# target to build an object file
drivers/gpio/gpio_control.c.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/gpio/gpio_control.c.o
.PHONY : drivers/gpio/gpio_control.c.o
drivers/gpio/gpio_control.i: drivers/gpio/gpio_control.c.i
.PHONY : drivers/gpio/gpio_control.i
# target to preprocess a source file
drivers/gpio/gpio_control.c.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/gpio/gpio_control.c.i
.PHONY : drivers/gpio/gpio_control.c.i
drivers/gpio/gpio_control.s: drivers/gpio/gpio_control.c.s
.PHONY : drivers/gpio/gpio_control.s
# target to generate assembly for a file
drivers/gpio/gpio_control.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/gpio/gpio_control.c.s
.PHONY : drivers/gpio/gpio_control.c.s
drivers/gpio/gpio_init.o: drivers/gpio/gpio_init.c.o
.PHONY : drivers/gpio/gpio_init.o
......@@ -1062,30 +1086,6 @@ modules/delay/delay.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/delay/delay.c.s
.PHONY : modules/delay/delay.c.s
modules/delay/device_time.o: modules/delay/device_time.c.o
.PHONY : modules/delay/device_time.o
# target to build an object file
modules/delay/device_time.c.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/delay/device_time.c.o
.PHONY : modules/delay/device_time.c.o
modules/delay/device_time.i: modules/delay/device_time.c.i
.PHONY : modules/delay/device_time.i
# target to preprocess a source file
modules/delay/device_time.c.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/delay/device_time.c.i
.PHONY : modules/delay/device_time.c.i
modules/delay/device_time.s: modules/delay/device_time.c.s
.PHONY : modules/delay/device_time.s
# target to generate assembly for a file
modules/delay/device_time.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/delay/device_time.c.s
.PHONY : modules/delay/device_time.c.s
modules/http/http_request.o: modules/http/http_request.c.o
.PHONY : modules/http/http_request.o
......@@ -1110,30 +1110,6 @@ modules/http/http_request.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/http/http_request.c.s
.PHONY : modules/http/http_request.c.s
modules/http/ota.o: modules/http/ota.c.o
.PHONY : modules/http/ota.o
# target to build an object file
modules/http/ota.c.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/http/ota.c.o
.PHONY : modules/http/ota.c.o
modules/http/ota.i: modules/http/ota.c.i
.PHONY : modules/http/ota.i
# target to preprocess a source file
modules/http/ota.c.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/http/ota.c.i
.PHONY : modules/http/ota.c.i
modules/http/ota.s: modules/http/ota.c.s
.PHONY : modules/http/ota.s
# target to generate assembly for a file
modules/http/ota.c.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/modules/http/ota.c.s
.PHONY : modules/http/ota.c.s
modules/logger/mylog.o: modules/logger/mylog.c.o
.PHONY : modules/logger/mylog.o
......@@ -1861,6 +1837,9 @@ help:
@echo "... drivers/gpio/device_init.o"
@echo "... drivers/gpio/device_init.i"
@echo "... drivers/gpio/device_init.s"
@echo "... drivers/gpio/gpio_control.o"
@echo "... drivers/gpio/gpio_control.i"
@echo "... drivers/gpio/gpio_control.s"
@echo "... drivers/gpio/gpio_init.o"
@echo "... drivers/gpio/gpio_init.i"
@echo "... drivers/gpio/gpio_init.s"
......@@ -1897,15 +1876,9 @@ help:
@echo "... modules/delay/delay.o"
@echo "... modules/delay/delay.i"
@echo "... modules/delay/delay.s"
@echo "... modules/delay/device_time.o"
@echo "... modules/delay/device_time.i"
@echo "... modules/delay/device_time.s"
@echo "... modules/http/http_request.o"
@echo "... modules/http/http_request.i"
@echo "... modules/http/http_request.s"
@echo "... modules/http/ota.o"
@echo "... modules/http/ota.i"
@echo "... modules/http/ota.s"
@echo "... modules/logger/mylog.o"
@echo "... modules/logger/mylog.i"
@echo "... modules/logger/mylog.s"
......
No preview for this file type
CMAKE_PROGRESS_1 =
CMAKE_PROGRESS_1 = 80
CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_3 = 81
CMAKE_PROGRESS_4 =
......
CMAKE_PROGRESS_1 = 90
CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_1 =
CMAKE_PROGRESS_2 = 90
CMAKE_PROGRESS_3 =
CMAKE_PROGRESS_4 = 91
CMAKE_PROGRESS_5 =
......
CMAKE_PROGRESS_1 = 95
CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_1 =
CMAKE_PROGRESS_2 = 95
CMAKE_PROGRESS_3 =
CMAKE_PROGRESS_4 = 96
CMAKE_PROGRESS_5 =
......
......@@ -18,8 +18,8 @@ CMAKE_PROGRESS_17 =
CMAKE_PROGRESS_18 =
CMAKE_PROGRESS_19 = 23
CMAKE_PROGRESS_20 =
CMAKE_PROGRESS_21 =
CMAKE_PROGRESS_22 = 24
CMAKE_PROGRESS_21 = 24
CMAKE_PROGRESS_22 =
CMAKE_PROGRESS_23 =
CMAKE_PROGRESS_24 = 25
CMAKE_PROGRESS_25 =
......@@ -32,8 +32,8 @@ CMAKE_PROGRESS_31 =
CMAKE_PROGRESS_32 =
CMAKE_PROGRESS_33 = 28
CMAKE_PROGRESS_34 =
CMAKE_PROGRESS_35 =
CMAKE_PROGRESS_36 = 29
CMAKE_PROGRESS_35 = 29
CMAKE_PROGRESS_36 =
CMAKE_PROGRESS_37 =
CMAKE_PROGRESS_38 = 30
CMAKE_PROGRESS_39 =
......
CMAKE_PROGRESS_1 = 85
CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_1 =
CMAKE_PROGRESS_2 = 85
CMAKE_PROGRESS_3 =
CMAKE_PROGRESS_4 = 86
CMAKE_PROGRESS_5 =
......
......@@ -2,25 +2,25 @@ CMAKE_PROGRESS_1 =
CMAKE_PROGRESS_2 =
CMAKE_PROGRESS_3 = 54
CMAKE_PROGRESS_4 =
CMAKE_PROGRESS_5 = 55
CMAKE_PROGRESS_6 =
CMAKE_PROGRESS_5 =
CMAKE_PROGRESS_6 = 55
CMAKE_PROGRESS_7 =
CMAKE_PROGRESS_8 = 56
CMAKE_PROGRESS_9 =
CMAKE_PROGRESS_8 =
CMAKE_PROGRESS_9 = 56
CMAKE_PROGRESS_10 =
CMAKE_PROGRESS_11 = 57
CMAKE_PROGRESS_12 =
CMAKE_PROGRESS_11 =
CMAKE_PROGRESS_12 = 57
CMAKE_PROGRESS_13 =
CMAKE_PROGRESS_14 = 58
CMAKE_PROGRESS_15 =
CMAKE_PROGRESS_16 =
CMAKE_PROGRESS_17 = 59
CMAKE_PROGRESS_18 =
CMAKE_PROGRESS_19 = 60
CMAKE_PROGRESS_20 =
CMAKE_PROGRESS_19 =
CMAKE_PROGRESS_20 = 60
CMAKE_PROGRESS_21 =
CMAKE_PROGRESS_22 = 61
CMAKE_PROGRESS_23 =
CMAKE_PROGRESS_22 =
CMAKE_PROGRESS_23 = 61
CMAKE_PROGRESS_24 =
CMAKE_PROGRESS_25 = 62
CMAKE_PROGRESS_26 =
......@@ -30,11 +30,11 @@ CMAKE_PROGRESS_29 =
CMAKE_PROGRESS_30 =
CMAKE_PROGRESS_31 = 64
CMAKE_PROGRESS_32 =
CMAKE_PROGRESS_33 = 65
CMAKE_PROGRESS_34 =
CMAKE_PROGRESS_33 =
CMAKE_PROGRESS_34 = 65
CMAKE_PROGRESS_35 =
CMAKE_PROGRESS_36 = 66
CMAKE_PROGRESS_37 =
CMAKE_PROGRESS_36 =
CMAKE_PROGRESS_37 = 66
CMAKE_PROGRESS_38 =
CMAKE_PROGRESS_39 = 67
CMAKE_PROGRESS_40 =
......@@ -44,11 +44,11 @@ CMAKE_PROGRESS_43 =
CMAKE_PROGRESS_44 =
CMAKE_PROGRESS_45 = 69
CMAKE_PROGRESS_46 =
CMAKE_PROGRESS_47 = 70
CMAKE_PROGRESS_48 =
CMAKE_PROGRESS_47 =
CMAKE_PROGRESS_48 = 70
CMAKE_PROGRESS_49 =
CMAKE_PROGRESS_50 = 71
CMAKE_PROGRESS_51 =
CMAKE_PROGRESS_50 =
CMAKE_PROGRESS_51 = 71
CMAKE_PROGRESS_52 =
CMAKE_PROGRESS_53 = 72
CMAKE_PROGRESS_54 =
......@@ -58,11 +58,11 @@ CMAKE_PROGRESS_57 =
CMAKE_PROGRESS_58 =
CMAKE_PROGRESS_59 = 74
CMAKE_PROGRESS_60 =
CMAKE_PROGRESS_61 = 75
CMAKE_PROGRESS_62 =
CMAKE_PROGRESS_61 =
CMAKE_PROGRESS_62 = 75
CMAKE_PROGRESS_63 =
CMAKE_PROGRESS_64 = 76
CMAKE_PROGRESS_65 =
CMAKE_PROGRESS_64 =
CMAKE_PROGRESS_65 = 76
CMAKE_PROGRESS_66 =
CMAKE_PROGRESS_67 = 77
CMAKE_PROGRESS_68 =
......@@ -72,5 +72,5 @@ CMAKE_PROGRESS_71 =
CMAKE_PROGRESS_72 =
CMAKE_PROGRESS_73 = 79
CMAKE_PROGRESS_74 =
CMAKE_PROGRESS_75 = 80
CMAKE_PROGRESS_75 =
#include "car0102_control.h"
#include "common.h"
#include "gpio_init.h"
#include "device_init.h"
#include "gpio_control.h"
void car0102_calculate_L_R(int angle) {//将角度转化为对应的舵机pwm值
......@@ -16,15 +18,15 @@ void car0102_calculate_L_R(int angle) {//将角度转化为对应的舵机pwm值
pwmWrite(PWM_PIN_CHANGE,val);
}
void car0102_speed_stop() {
//pin_value(26,0);
//device_gpio_control(g_device_type,26,0);
pwmWrite(PWM_PIN_SPEED,0);
car0102_calculate_L_R(90);
}
void car0102_mode_1_flont(unsigned char gval) {
pin_value(26,1);
device_gpio_control(g_device_type,26,1);
if(gval == 0) {
pin_value(26,0);
device_gpio_control(g_device_type,26,0);
pwmWrite(PWM_PIN_SPEED, 0);
}else if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 1000);
......@@ -68,7 +70,7 @@ void car0102_mode_1_flont(unsigned char gval) {
void car0102_mode_2_back(unsigned char gval) {
int k = 5;
int b = 100;
pin_value(26,0);
device_gpio_control(g_device_type,26,0);
if (gval < 50) {
pwmWrite(PWM_PIN_SPEED, 0);
} else if (gval <= 55) {
......
......@@ -110,8 +110,8 @@ void tank0203_change(unsigned char *buf) {
tank0203_mode_lift_back(0);
//tank0203_mode_lift_back(s_val_2-20);
}else {
tank0203_mode_lift_back(val+20);
tank0203_mode_right_flont(val+20);
tank0203_mode_lift_back(val+30);
tank0203_mode_right_flont(val+30);
}
}
......@@ -123,8 +123,8 @@ void tank0203_change(unsigned char *buf) {
tank0203_mode_right_back(0);
}
else {
tank0203_mode_lift_flont(val+20);
tank0203_mode_right_back(val+20);
tank0203_mode_lift_flont(val+30);
tank0203_mode_right_back(val+30);
}
}
......@@ -134,8 +134,8 @@ void tank0203_change(unsigned char *buf) {
tank0203_mode_right_flont(0);
}
else {
tank0203_mode_lift_flont(val+20);
tank0203_mode_right_back(val+20);
tank0203_mode_lift_flont(val+30);
tank0203_mode_right_back(val+30);
}
}
......
......@@ -3,6 +3,7 @@
#include "gpio_init.h"
#include "pthrpoll.h"
#include "tank_angle.h"
#include "gpio_control.h"
int tank_shot_back_stop(unsigned char pin,unsigned char val);
......@@ -30,45 +31,9 @@ void tank_shot_back(unsigned char gval) {
pwmWrite(PWM_PIN_CHANGE, change_1);
}
// if (gval < 50) {
// pwmWrite(PWM_PIN_CHANGE, 75);
// } else if (gval <= 55) {
// pwmWrite(PWM_PIN_CHANGE, 71);
// } else if (gval <= 60) {
// pwmWrite(PWM_PIN_CHANGE, 70);
// } else if (gval <= 65) {
// pwmWrite(PWM_PIN_CHANGE, 70);
// } else if (gval <= 70) {
// pwmWrite(PWM_PIN_CHANGE, 70);
// } else if (gval <= 75) {
// pwmWrite(PWM_PIN_CHANGE, 69);
// } else if (gval <= 90) {
// pwmWrite(PWM_PIN_CHANGE, 68);
// } else if (gval <= 100) {
// pwmWrite(PWM_PIN_CHANGE, 68);
// } else if (gval <= 110) {
// pwmWrite(PWM_PIN_CHANGE, 66);
// } else if (gval <= 120) {
// pwmWrite(PWM_PIN_CHANGE, 65);
// } else if (gval <= 130) {
// pwmWrite(PWM_PIN_CHANGE, 64);
// } else if (gval <= 140) {
// pwmWrite(PWM_PIN_CHANGE, 62);
// } else if (gval <= 150) {
// pwmWrite(PWM_PIN_CHANGE, 60);
// } else if (gval <= 160) {
// pwmWrite(PWM_PIN_CHANGE, 59);
// } else if (gval <= 170) {
// pwmWrite(PWM_PIN_CHANGE, 58);
// } else if (gval <= 180) {
// pwmWrite(PWM_PIN_CHANGE, 57);
// } else if (gval <= 190) {
// pwmWrite(PWM_PIN_CHANGE, 56);
// } else if (gval <= 200) {
// pwmWrite(PWM_PIN_CHANGE, 55);
// }
}
const tank_common_back tank_common_config_t[]={
{
.device_id = DEVICE_TANK0202,
......@@ -143,9 +108,15 @@ int tank_shot_back_stop(unsigned char pin,unsigned char val){
shot_device_time_end=get_current_time_millis();
}
/*销毁坦克使用的线程池,让其正常销毁,只有在tank0202设备号下才有用*/
/*销毁坦克使用的线程池,让其正常销毁,只有在tank相关设备号下才有用,最后销毁都会到device——common.h中*/
void tank_thread_close(){
thread_pool_destroy(pool_tank_t);
if(pool_tank_t!=NULL){
thread_pool_destroy(pool_tank_t);
}
if(g_pool_device_gpio_control_t!=NULL){
thread_pool_destroy(g_pool_device_gpio_control_t);
}
}
void tank_shot_stop_control(int device_id,unsigned char pin,unsigned char val) {
......
......@@ -3,9 +3,11 @@
#include "common.h"
#include "gpio_init.h"
int g_device_delay_count =0;
int abnormal_pin_pwm_stop=0;
int g_device_type =0;
int g_device_type =0; //设备类型,比如tank0202、car0101
const deviceconfig_t device_configs[] = {
// car0101配置
......
#ifndef DEVICE_INIT_H__
#define DEVICE_INIT_H__
extern int g_device_type;
extern int g_device_type;//设备类型,比如tank0202、car0101
extern int g_device_delay_count ;
extern int g_device_delay_count ; //设备延时函数
typedef struct {
int device_id; // 设备ID (101, 102等)
......
#include "common.h"
#include "gpio_control.h"
#include "tank_angle.h"
#include "gpio_init.h"
#include "device_init.h"
#include "devcontrol_common.h"
#include "http_request.h"
#include "delay.h"
const gpiocontrol_t *gpio_control_config_t = NULL ;
ThreadPool_t *g_pool_device_gpio_control_t = NULL;
void tank_angle_limit_function(void *arg);
static bool s_poll_tank_index =0;
void public_pin_value(int pin,int value);
void public_pwm_value(int pin ,int value);
void tank0202_pwm_value(int pin,int value);
void tank0203_pwm_value(int pin,int value);
void tank0206_pwm_value(int pin,int value);
void device_gpio_control_threadpoll_init(){
int *arg = malloc(sizeof(int));
*arg = 1;
g_pool_device_gpio_control_t= thread_pool_init(1,1);
thread_pool_add_task(g_pool_device_gpio_control_t, tank_angle_limit_function, &arg);
}
const gpiocontrol_t gpio_configs[] = {
{
.device_id = DEVICE_CAR0101,
.device_pin_value =public_pin_value,
.device_pwm_value =public_pwm_value
},
{
.device_id = DEVICE_CAR0102,
.device_pin_value =public_pin_value,
.device_pwm_value =public_pwm_value
},
{
.device_id = DEVICE_CAR0103,
.device_pin_value =public_pin_value,
.device_pwm_value =public_pwm_value
},
{
.device_id = DEVICE_CAR0104,
.device_pin_value =public_pin_value,
.device_pwm_value =public_pwm_value
},
{
.device_id = DEVICE_TANK0202,
.device_pin_value =public_pin_value,
.device_pwm_value =tank0202_pwm_value,
.device_gpio_pthread_create=device_gpio_control_threadpoll_init
},
{
.device_id = DEVICE_TANK0203,
.device_pin_value =public_pin_value,
.device_pwm_value =tank0203_pwm_value,
.device_gpio_pthread_create=device_gpio_control_threadpoll_init
},
{
.device_id = DEVICE_TANK0206,
.device_pin_value =public_pin_value,
.device_pwm_value =tank0203_pwm_value
},
{
.device_id = DEVICE_PAO_PTZ0401,
.device_pin_value =public_pin_value,
.device_pwm_value =public_pwm_value
},
};
/*
设备控制代码
*/
void device_gpio_control(int device_id,int pin,int val) {
if (!gpio_control_config_t || gpio_control_config_t->device_id != device_id) {
// 查找设备配置
for(int i = 0; gpio_configs[i].device_id != -1; i++) {
if(gpio_configs[i].device_id == device_id) {
gpio_control_config_t = &gpio_configs[i];
break;
}
}
if(gpio_control_config_t&&
(gpio_control_config_t->device_id ==DEVICE_TANK0202||gpio_control_config_t->device_id ==DEVICE_TANK0203))
{
gpio_control_config_t->device_gpio_pthread_create; //创建线程,线程关闭在tank.common.h中何tank需要的其他线程关闭
}
}
if(!gpio_control_config_t) {
my_zlog_error("Error: Device gpio stop ID %d not found!", device_id);
return;
}
gpio_control_config_t->device_pin_value(pin,val);
gpio_control_config_t->device_pwm_value(pin,val);
}
void public_pin_value(int pin,int value) { //引脚控制
for(int i = 0 ; i <= g_gpiocount ; i++) {
if(pin == g_gpiowpi[i]) {
break;
}if(i == g_gpiocount) {
return ;
}
}
if(value==1) {
digitalWrite(pin, HIGH);
my_zlog_debug("pin:%d,%d",pin,HIGH);
}else if(value==0) {
digitalWrite(pin, LOW);
my_zlog_debug("pin:%d,%d",pin,LOW);
}
}
void public_pwm_value(int pin ,int value){
for(int i = 0 ; i <= g_gpio_softpwmcount ; i++) {
if(pin == g_gpioPwm[i]) {
break;
}
if(i == g_gpio_softpwmcount) {
return ;
}
}
int shot_speed = (int)(g_shot_speed_value*100);
if(value==1) {
if(pin == 27){
softPwmWrite(pin, shot_speed);
my_zlog_debug("pwm:%d,%d",pin,shot_speed);
} else {
softPwmWrite(pin, shot_speed);
my_zlog_debug("pwm:%d,%d",pin,shot_speed);
}
}else if(value==0) {
softPwmWrite(pin, 0);
my_zlog_debug("pwm:%d,0",pin);
}
my_zlog_debug("public pwm");
}
void tank0202_pwm_value(int pin,int value) { //软件陪我们控制调速
for(int i = 0 ; i <= g_gpio_softpwmcount ; i++) {
if(pin == g_gpioPwm[i]) {
break;
}
if(i == g_gpio_softpwmcount) {
return ;
}
}
if(value==1) {
if(pin == 27){
softPwmWrite(pin, 50);
} else {
if(angle_limit()==0 && (pin==7 ||pin ==5)) softPwmWrite(pin, 30);
if(pin!=7 &&pin !=5)softPwmWrite(pin, 30);
my_zlog_debug("pwm:%d",pin);
}
}else if(value==0) {
softPwmWrite(pin, 0);
my_zlog_debug("pwm:%d,0",pin);
}
my_zlog_debug("tank0202 pwm");
}
void tank0203_pwm_value(int pin,int value) { //软件陪我们控制调速
for(int i = 0 ; i <= g_gpio_softpwmcount ; i++) {
if(pin == g_gpioPwm[i]) {
break;
}
if(i == g_gpio_softpwmcount) {
return ;
}
}
if(value==1) {
if(pin == 27){
softPwmWrite(pin, 45);
} else {
if(angle_limit()==0 && (pin==7 ||pin ==5))softPwmWrite(pin, 30);
if(pin!=7 &&pin !=5) softPwmWrite(pin, 30);
my_zlog_debug("pwm:%d",pin);
}
}else if(value==0) {
softPwmWrite(pin, 0);
my_zlog_debug("pwm:%d,0",pin);
}
my_zlog_debug("tank0203 pwm");
}
void tank0206_pwm_value(int pin,int value) { //软件陪我们控制调速
for(int i = 0 ; i <= g_gpio_softpwmcount ; i++) {
if(pin == g_gpioPwm[i]) {
break;
}
if(i == g_gpio_softpwmcount) {
return ;
}
}
if(value==1) {
if(pin == 27){
softPwmWrite(pin, 45);
} else {
softPwmWrite(pin, 35);
my_zlog_debug("pwm:%d",pin);
}
}else if(value==0) {
softPwmWrite(pin, 0);
my_zlog_debug("pwm:%d,0",pin);
}
my_zlog_debug("tank0206 pwm");
}
void tank_angle_limit_function(void *arg){
while(1){
if(angle_limit()==1) device_gpio_control(g_device_type,5,0);
else if(angle_limit()==2) device_gpio_control(g_device_type,7,0);
else if(angle_limit()==0) delay_ms(5);
}
}
\ No newline at end of file
#ifndef GPIO_CONTROL_H__
#define GPIO_CONTROL_H__
#include "pthrpoll.h"
typedef struct {
int device_id; // 设备ID (101, 102等)备名称
void (*device_pwm_value)(int pin,int val); // PWM初始化函数指针
void (*device_pin_value)(int pin,int value);// 速度控制函数指针
void (*device_gpio_pthread_create)(void);
} gpiocontrol_t;
void device_gpio_control(int device_id,int pin,int val);
extern ThreadPool_t *g_pool_device_gpio_control_t;
#endif
\ No newline at end of file
......@@ -4,6 +4,7 @@
#include "device_init.h"
#include "devcontrol_common.h"
#define MIN_DUTY 0 // 最小占空比
#define MAX_DUTY 100 // 最大占空比
......@@ -52,70 +53,8 @@ void pwm_all_default() {//全部至低电平,车和坦克共用
}
}
void pwm_value(int pin,int value) { //软件陪我们控制调速
for(int i = 0 ; i <= g_gpio_softpwmcount ; i++) {
if(pin == g_gpioPwm[i]) {
break;
}
if(i == g_gpio_softpwmcount) {
return ;
}
}
int shot_speed = (int)(g_shot_speed_value*100);
if(value==1) {
if(pin == 27){
if(g_device_type == DEVICE_TANK0202) softPwmWrite(pin, 50);
else if(g_device_type == DEVICE_TANK0203) softPwmWrite(pin, 50);
else if(g_device_type == DEVICE_TANK0206) softPwmWrite(pin, 45);
else {
softPwmWrite(pin, shot_speed);
my_zlog_debug("pwm:%d,%d",pin,shot_speed);
}
} else {
if(g_device_type == DEVICE_TANK0202) {
softPwmWrite(pin, 35);
if(angele_limit() == 1) softPwmWrite(5, 0);
if(angele_limit() == 2) softPwmWrite(7, 0);
}
else if(g_device_type == DEVICE_TANK0203) {
softPwmWrite(pin, 30);
if(angele_limit() == 1) softPwmWrite(5, 0);
if(angele_limit() == 2) softPwmWrite(7, 0);
}
else if(g_device_type == DEVICE_TANK0206) softPwmWrite(pin, 35);
else{
softPwmWrite(pin, shot_speed);
my_zlog_debug("pwm:%d,%d",pin,shot_speed);
}
my_zlog_debug("pwm:%d",pin);
}
}else if(value==0) {
softPwmWrite(pin, 0);
my_zlog_debug("pwm:%d,0",pin);
}
}
void pin_value(int pin,int value) { //引脚控制
for(int i = 0 ; i <= g_gpiocount ; i++) {
if(pin == g_gpiowpi[i]) {
break;
}if(i == g_gpiocount) {
return ;
}
}
if(value==1) {
digitalWrite(pin, HIGH);
my_zlog_debug("pin:%d,%d",pin,HIGH);
}else if(value==0) {
digitalWrite(pin, LOW);
my_zlog_debug("pin:%d,%d",pin,LOW);
}
}
/*物理pwm初始化*/
void physics_pwm_init() {
......
......@@ -9,6 +9,12 @@
#define PWM_PIN_SPEED 21
#define PWM_PIN_CHANGE 2
extern int g_gpioPwm[30];//软件控制
extern int g_gpiowpi[40]; //能使用高低引脚和其他引脚
extern int g_gpiocount;
extern int g_gpio_softpwmcount;
void init_gpiowpi(const int *values_pin);//gpio引脚初始化
void init_gpiopwm(const int *values_pwm);
......
......@@ -19,7 +19,7 @@ double tank_angle(){
int angele_limit(){
int angle_limit(){
int tank_limit_angele = tank_angle();
if(tank_limit_angele >=LIFT_LIMIT && tank_limit_angele<=MIDDLE_LIMIT) return 1;
else if(tank_limit_angele >=MIDDLE_LIMIT && tank_limit_angele<=RIGHT_LIMIT) return 2;
......
......@@ -3,6 +3,6 @@
double tank_angle();
int angele_limit();
int angle_limit();
#endif
\ No newline at end of file
......@@ -2,19 +2,20 @@
#include "warn.h"
#include "http_request.h"
#include "mylog.h"
#include "gpio_init.h"
#include "gpio_control.h"
#include "device_init.h"
#include "devcontrol_common.h"
//最高警报,最低电压报警
int alarm_highest(int index) {
if(index == 1) {
pin_value(20,1);//紫灯
device_gpio_control(g_device_type,20,1);//紫灯
if(g_enable_buzzer_value) {
pin_value(22,1);//蜂鸣器
device_gpio_control(g_device_type,22,1);//蜂鸣器
}
}else if(index == 0) {
pin_value(20,0);//紫灯
pin_value(22,0);//蜂鸣器
device_gpio_control(g_device_type,20,0);//紫灯
device_gpio_control(g_device_type,22,0);//蜂鸣器
}
return index ;
......@@ -23,9 +24,9 @@ int alarm_highest(int index) {
//比较小警报
int alarm_low(int index) {
if(index == 1) {
pin_value(16,1);//黄灯
device_gpio_control(g_device_type,16,1);//黄灯
} else if(index == 0) {
pin_value(16,0);//黄灯
device_gpio_control(g_device_type,16,0);//黄灯
}
return index ;
......
......@@ -37,7 +37,6 @@
#include "delay.h"
#include "mylog.h"
#include "device_time.h"
// ========== 香橙派优化宏 ==========
......
......@@ -13,15 +13,15 @@
#include "tank_common.h"
#include "common.h"
#define DEVICE_CAR0101 101
#define DEVICE_CAR0102 102
#define DEVICE_CAR0103 103
#define DEVICE_CAR0104 104
#define DEVICE_TANK0201 201
#define DEVICE_TANK0202 202
#define DEVICE_TANK0203 203
#define DEVICE_TANK0206 206
#define DEVICE_PAO_PTZ0401 401
#define DEVICE_CAR0101 101 //莽牛大车
#define DEVICE_CAR0102 102 //莽牛小车
#define DEVICE_CAR0103 103 //推土机
#define DEVICE_CAR0104 104 //挖机
#define DEVICE_TANK0201 201 //废弃坦克
#define DEVICE_TANK0202 202 //
#define DEVICE_TANK0203 203 //M1A2美国坦克
#define DEVICE_TANK0206 206 //可以喷水坦克
#define DEVICE_PAO_PTZ0401 401 //云台
typedef struct {
int device_id; // 设备ID (101, 102等)
......
......@@ -20,32 +20,6 @@ int opencamsh_china(){
}
// int opencamsh_china() {
// const char* url = "https://jywy.yd-ss.com?dev=";
// char urls[50];
// sprintf(urls, "%s%s", url, mqtt_topic_pure_number());
// // 使用nice和taskset提高优先级并绑定CPU核心
// sprintf(gwebcam, "su - orangepi -c \"nice -n -10 taskset -c 1 chromium-browser --use-fake-ui-for-media-stream "
// "--use-gl=egl "
// "--enable-features=WebRTC-H264WithOpenH264FFmpeg "
// "--disable-features=WebRTC-IPv6OnWiFi "
// "--enable-gpu-rasterization "
// "--enable-zero-copy "
// "--disable-quic "
// "--disable-gpu-compositing "
// "--autoplay-policy=no-user-gesture-required "
// "--window-size=800,600 --start-maximized "
// "%s\"", urls);
// system(gwebcam);
// my_zlog_debug("%s", gwebcam);
// my_zlog_debug("open cam");
// return 0;
// }
int opencamsh_abroad(){
const char* url = "https://video.luckycar.top/?dev=";
char urls[50];
......
#include "device_time.h"
int g_device_delay_count =0 ;
\ No newline at end of file
#ifndef DEVICE_TIME_H
#define DEVICE_TIME_H
extern int g_device_delay_count ;
#endif
\ No newline at end of file
#include "ota.h"
#include "common.h"
int ota_init(){
}
\ No newline at end of file
#ifndef OTA_H
#define OTA_H
#endif
\ No newline at end of file
......@@ -18,6 +18,7 @@
#include "gpio_init.h"
#include "device_init.h"
#include "tank_angle.h"
#include "gpio_control.h"
int g_heartbeat_count=0;
......@@ -164,9 +165,8 @@ void message_4(cJSON *body){//message 为4时候
my_zlog_debug("pinTemp:%d",g_valt[1]);
my_zlog_debug("valTemp:%d",g_valt[2]);
pin_value(g_valt[1],g_valt[2]);
pwm_value(g_valt[1],g_valt[2]);
device_gpio_control(g_device_type,g_valt[1],g_valt[2]);
tank_shot_stop_control(g_device_type,g_valt[1],g_valt[2]);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment