Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
car-controlserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenzhongjian
car-controlserver
Commits
4fe2e2b3
Commit
4fe2e2b3
authored
Aug 27, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入了推送控制台和wifi保存删除和优化挖机操作
parent
879c7269
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
109 additions
and
78 deletions
+109
-78
device_wifi_manager.c
app/device_change/device_wifi_manager.c
+7
-2
device_wifi_manager.h
app/device_change/device_wifi_manager.h
+4
-0
device_fileopen.h
app/device_identity/device_fileopen.h
+0
-3
pthread_open.c
app/main/pthread_open.c
+9
-10
main
build/main
+0
-0
car0102_control.c
drivers/devicecontrol/car0102_control.c
+5
-4
car0103_control.c
drivers/devicecontrol/car0103_control.c
+8
-7
car0103_control.h
drivers/devicecontrol/car0103_control.h
+4
-1
car0104_control.c
drivers/devicecontrol/car0104_control.c
+4
-0
tank0203_control.c
drivers/devicecontrol/tank0203_control.c
+14
-21
tank_common.c
drivers/devicecontrol/tank_common.c
+26
-6
tank_common.h
drivers/devicecontrol/tank_common.h
+2
-3
device_init.c
drivers/gpio/device_init.c
+5
-5
device_init.h
drivers/gpio/device_init.h
+1
-1
gpio_control.c
drivers/gpio/gpio_control.c
+13
-10
gpio_init.c
drivers/gpio/gpio_init.c
+5
-3
gpio_init.h
drivers/gpio/gpio_init.h
+2
-2
No files found.
app/device_change/device_wifi_manager.c
View file @
4fe2e2b3
...
...
@@ -7,7 +7,8 @@
#define MAX_WIFI_ENTRIES 50
#define SSID_MAX_LENGTH 64
void
device_wifi_public_sendmqtt
(
int
wifi_status
)
{
//成功发送3010
/*成功发送3010,保存wifi和删除WiFi都会发送,wifi_status未0为成功*/
void
device_wifi_public_sendmqtt
(
int
wifi_status
)
{
get_current_wifi
();
cJSON
*
root
=
cJSON_CreateObject
();
...
...
@@ -28,6 +29,8 @@ void device_wifi_public_sendmqtt(int wifi_status) { //成功发送3010
cJSON_Delete
(
root
);
// 释放 cJSON 对象
}
/*接收到删除的mqtt消息*/
void
device_wifi_rec_delete
(
cJSON
*
body
){
cJSON
*
wifi_ssid
=
cJSON_GetObjectItem
(
body
,
"wifi_ssid"
);
cJSON
*
wifi_password
=
cJSON_GetObjectItem
(
body
,
"wifi_password"
);
...
...
@@ -44,6 +47,7 @@ void device_wifi_rec_delete(cJSON *body){
}
}
/*进行保存wifi*/
int
orange_pi_save_wifi
(
const
char
*
ssid
,
const
char
*
password
)
{
// 参数检查
if
(
!
ssid
||
!
password
||
strlen
(
ssid
)
==
0
||
strlen
(
password
)
==
0
)
{
...
...
@@ -75,6 +79,7 @@ int orange_pi_save_wifi(const char* ssid, const char* password) {
}
/*保存WiFi接口,接收到mqtt消息进行保存*/
void
device_wifi_rec_sava
(
cJSON
*
body
){
cJSON
*
wifi_ssid
=
cJSON_GetObjectItem
(
body
,
"wifi_ssid"
);
cJSON
*
wifi_password
=
cJSON_GetObjectItem
(
body
,
"wifi_password"
);
...
...
@@ -131,10 +136,10 @@ int get_saved_wifi_list(char ssid_list[][SSID_MAX_LENGTH], int max_count) {
return
count
;
}
/**
* @brief 打印所有已保存的WiFi配置
*/
void
device_send_saved_wifi
(){
get_current_wifi
();
...
...
app/device_change/device_wifi_manager.h
View file @
4fe2e2b3
...
...
@@ -3,10 +3,13 @@
#include "common.h"
//发送已经保存的WiFi给上层
void
device_send_saved_wifi
();
//删除wifi
void
device_wifi_rec_delete
(
cJSON
*
body
);
//接收到保存wifi消息
void
device_wifi_rec_sava
(
cJSON
*
body
);
#endif
\ No newline at end of file
app/device_identity/device_fileopen.h
View file @
4fe2e2b3
...
...
@@ -8,7 +8,5 @@ int device_id_file_init();
/*打开版本文件,版本文件是go语言进行创建,只需要读取就行了*/
char
*
program_version
()
;
//extern char *g_device_id ;
char
*
device_id_function
();
#endif
\ No newline at end of file
app/main/pthread_open.c
View file @
4fe2e2b3
...
...
@@ -51,12 +51,11 @@ void *thread_exit_time(void *arg) {
delay_ms
(
100
);
pthread_mutex_lock
(
&
g_exit_count_mutex
);
g_devcontrol_exit_count
++
;
if
(
g_devcontrol_exit_count
>=
5
)
{
device_stop
(
g_device_type
);
g_devcontrol_exit_count
=
6
;
}
pthread_mutex_unlock
(
&
g_exit_count_mutex
);
...
...
@@ -64,6 +63,7 @@ void *thread_exit_time(void *arg) {
return
NULL
;
}
/*心跳线程处理函数,心跳发送前会像上层请求是否需要验证*/
void
*
thread_mqtt_beat
(
void
*
arg
)
{
my_zlog_info
(
"thread_mqtt_beat start"
);
g_webrtc_index
=
1
;
...
...
@@ -95,6 +95,7 @@ void *thread_mqtt_beat(void *arg) {
return
NULL
;
}
//打开游览器线程,让游览器一直在一个线程中打开并运行
void
*
thread_open_browser
(
void
*
arg
)
{
//如果为相关的不需要心跳或者游览器设备,提早结束线程
...
...
@@ -138,7 +139,7 @@ void *thread_mqtt_reconnect(void *arg) {
}
}
g_mqtt_grc
=
mqtt_create
(
mosq
);
g_mqtt_grc
=
mqtt_create
(
mosq
);
//创建mqtt
if
(
g_mqtt_grc
!=
0
)
{
my_zlog_warn
(
"mqtt fail ..."
);
mqtt_clean
(
mosq
);
...
...
@@ -161,21 +162,19 @@ void *thread_mqtt_reconnect(void *arg) {
//专门用于计时的线程
void
*
thread_time_calculation
(
void
*
arg
)
{
while
(
1
)
{
delay_ms
(
5
);
g_device_delay_
count
++
;
//设备计时,坦克打击倒退逻辑
delay_ms
(
5
);
g_device_delay_
back_count
++
;
//设备计时,坦克打击倒退逻辑
pthread_mutex_lock
(
&
g_verify_mutex
);
g_verify_count
++
;
//验证计时,每15s一次
pthread_mutex_unlock
(
&
g_verify_mutex
);
if
(
g_verify_count
>=
20000
)
{
if
(
g_verify_count
>=
20000
)
{
//防止溢出
pthread_mutex_lock
(
&
g_verify_mutex
);
g_verify_count
=
20000
;
pthread_mutex_unlock
(
&
g_verify_mutex
);
pthread_mutex_unlock
(
&
g_verify_mutex
);
}
if
(
g_device_delay_
count
>=
5000
)
g_device_delay_count
=
5000
;
if
(
g_device_delay_
back_count
>=
5000
)
g_device_delay_back_count
=
5000
;
//防止溢出
}
return
NULL
;
}
...
...
build/main
View file @
4fe2e2b3
No preview for this file type
drivers/devicecontrol/car0102_control.c
View file @
4fe2e2b3
...
...
@@ -4,8 +4,8 @@
#include "device_init.h"
#include "gpio_control.h"
void
car0102_calculate_L_R
(
int
angle
)
{
//将角度转化为对应的舵机pwm值
//将角度转化为对应的舵机pwm值
void
car0102_calculate_L_R
(
int
angle
)
{
if
(
angle
<
0
)
{
angle
=
0
;
}
else
if
(
angle
>
180
)
{
...
...
@@ -17,8 +17,8 @@ void car0102_calculate_L_R(int angle) {//将角度转化为对应的舵机pwm值
int
val
=
(
int
)((
pulse_width
/
period
)
*
1000
);
pwmWrite
(
PWM_PIN_CHANGE
,
val
);
}
void
car0102_speed_stop
()
{
//device_gpio_control(g_device_type,26,0);
pwmWrite
(
PWM_PIN_SPEED
,
0
);
car0102_calculate_L_R
(
90
);
}
...
...
@@ -166,7 +166,8 @@ void car0102_mode_4_right(unsigned char gval) {
}
}
void
car0102_speed_change
(
unsigned
char
*
buf
)
{
//车速度和转向引脚数值处理函数
//车速度和转向引脚数值处理函数
void
car0102_speed_change
(
unsigned
char
*
buf
)
{
unsigned
char
mode
=
buf
[
1
];
unsigned
char
val
=
buf
[
2
];
switch
(
mode
){
...
...
drivers/devicecontrol/car0103_control.c
View file @
4fe2e2b3
...
...
@@ -37,13 +37,13 @@ void mode_car0103_lift_back(unsigned char gval) {
}
void
mode_car0103_right_flont
(
unsigned
char
gval
)
{
int
b
=
0
;
int
b
=
1
;
if
(
gval
<
50
)
{
pwmWrite
(
PWM_PIN_CHANGE
,
75
);
}
else
if
(
gval
<=
60
)
{
pwmWrite
(
PWM_PIN_CHANGE
,
79
);
pwmWrite
(
PWM_PIN_CHANGE
,
79
+
b
);
}
else
if
(
gval
<=
70
)
{
pwmWrite
(
PWM_PIN_CHANGE
,
80
);
pwmWrite
(
PWM_PIN_CHANGE
,
80
+
b
);
}
else
if
(
gval
>
70
){
int
flont_speed
=
80
+
(
gval
-
70
)
/
10
+
b
;
pwmWrite
(
PWM_PIN_CHANGE
,
flont_speed
);
...
...
@@ -51,20 +51,21 @@ void mode_car0103_right_flont(unsigned char gval) {
}
void
mode_car0103_right_back
(
unsigned
char
gval
)
{
int
b
=
0
;
int
b
=
1
;
if
(
gval
<
50
)
{
pwmWrite
(
PWM_PIN_CHANGE
,
75
);
}
else
if
(
gval
<=
60
)
{
pwmWrite
(
PWM_PIN_CHANGE
,
71
);
pwmWrite
(
PWM_PIN_CHANGE
,
71
-
b
);
}
else
if
(
gval
<=
70
)
{
pwmWrite
(
PWM_PIN_CHANGE
,
70
);
pwmWrite
(
PWM_PIN_CHANGE
,
70
-
b
);
}
else
if
(
gval
>
70
){
int
back_speed
=
70
-
(
gval
-
70
)
/
10
-
b
;
pwmWrite
(
PWM_PIN_CHANGE
,
back_speed
);
}
}
void
car0103_change
(
unsigned
char
*
buf
)
{
/*挖机的速度处理接口*/
void
car0103_change
(
unsigned
char
*
buf
)
{
unsigned
char
mode
=
buf
[
1
];
unsigned
char
val
=
buf
[
2
];
static
int
modecount_car0103
=
0
;
...
...
drivers/devicecontrol/car0103_control.h
View file @
4fe2e2b3
#ifndef CAR0103_CONTROL_H__
#define CAR0103_CONTROL_H__
//停止接口
void
car0103_middle
();
void
car0103_change
(
unsigned
char
*
buf
);
/*挖机的速度处理接口*/
void
car0103_change
(
unsigned
char
*
buf
);
#endif
\ No newline at end of file
drivers/devicecontrol/car0104_control.c
View file @
4fe2e2b3
...
...
@@ -8,6 +8,7 @@ void car0104_stop() {
pwmWrite
(
PWM_PIN_CHANGE
,
75
);
}
//铲车后退
void
car0104_back
(
unsigned
char
gval
)
{
int
b
=
7
;
int
c
=
2
;
...
...
@@ -25,6 +26,7 @@ void car0104_back(unsigned char gval) {
}
}
//铲车前进
void
car0104_flont
(
unsigned
char
gval
)
{
int
b
=
7
;
int
c
=
2
;
...
...
@@ -41,6 +43,7 @@ void car0104_flont(unsigned char gval) {
}
}
//铲车右
void
car0104_right
(
unsigned
char
gval
)
{
int
b
=
5
;
if
(
gval
<
50
)
{
...
...
@@ -57,6 +60,7 @@ void car0104_right(unsigned char gval) {
}
}
//铲车左
void
car0104_lift
(
unsigned
char
gval
)
{
int
b
=
5
;
if
(
gval
<
50
)
{
...
...
drivers/devicecontrol/tank0203_control.c
View file @
4fe2e2b3
...
...
@@ -18,9 +18,9 @@ void tank0203_mode_lift_flont(unsigned char gval) {
pwmWrite
(
PWM_PIN_SPEED
,
75
);
}
else
if
(
gval
<=
60
)
{
pwmWrite
(
PWM_PIN_SPEED
,
79
);
pwmWrite
(
PWM_PIN_SPEED
,
79
+
b
);
}
else
if
(
gval
<=
70
)
{
pwmWrite
(
PWM_PIN_SPEED
,
80
);
pwmWrite
(
PWM_PIN_SPEED
,
80
+
b
);
}
else
if
(
gval
>
70
){
int
flont_speed
=
80
+
(
gval
-
70
)
/
10
+
b
;
if
(
flont_speed
>
95
)
flont_speed
=
95
;
...
...
@@ -33,9 +33,9 @@ void tank0203_mode_lift_back(unsigned char gval) {
if
(
gval
<
50
)
{
pwmWrite
(
PWM_PIN_SPEED
,
75
);
}
else
if
(
gval
<=
60
)
{
pwmWrite
(
PWM_PIN_SPEED
,
71
);
pwmWrite
(
PWM_PIN_SPEED
,
71
-
b
);
}
else
if
(
gval
<=
70
)
{
pwmWrite
(
PWM_PIN_SPEED
,
70
);
pwmWrite
(
PWM_PIN_SPEED
,
70
-
b
);
}
else
if
(
gval
>
70
){
int
back_speed
=
70
-
(
gval
-
70
)
/
10
-
b
;
if
(
back_speed
<
55
)
back_speed
=
55
;
...
...
@@ -48,9 +48,9 @@ void tank0203_mode_right_back(unsigned char gval) {
if
(
gval
<
50
)
{
pwmWrite
(
PWM_PIN_CHANGE
,
75
);
}
else
if
(
gval
<=
60
)
{
pwmWrite
(
PWM_PIN_CHANGE
,
79
);
pwmWrite
(
PWM_PIN_CHANGE
,
79
+
b
);
}
else
if
(
gval
<=
70
)
{
pwmWrite
(
PWM_PIN_CHANGE
,
80
);
pwmWrite
(
PWM_PIN_CHANGE
,
80
+
b
);
}
else
if
(
gval
>
70
){
int
flont_speed
=
80
+
(
gval
-
70
)
/
10
+
b
;
if
(
flont_speed
>
95
)
flont_speed
=
95
;
...
...
@@ -63,9 +63,9 @@ void tank0203_mode_right_flont(unsigned char gval) {
if
(
gval
<
50
)
{
pwmWrite
(
PWM_PIN_CHANGE
,
75
);
}
else
if
(
gval
<=
60
)
{
pwmWrite
(
PWM_PIN_CHANGE
,
71
);
pwmWrite
(
PWM_PIN_CHANGE
,
71
-
b
);
}
else
if
(
gval
<=
70
)
{
pwmWrite
(
PWM_PIN_CHANGE
,
70
);
pwmWrite
(
PWM_PIN_CHANGE
,
70
-
b
);
}
else
if
(
gval
>
70
){
int
back_speed
=
70
-
(
gval
-
70
)
/
10
-
b
;
if
(
back_speed
<
55
)
back_speed
=
55
;
...
...
@@ -73,36 +73,34 @@ void tank0203_mode_right_flont(unsigned char gval) {
}
}
void
tank0203_change
(
unsigned
char
*
buf
)
{
//tank0203控制函数
void
tank0203_change
(
unsigned
char
*
buf
)
{
unsigned
char
mode
=
buf
[
1
];
unsigned
char
val
=
buf
[
2
];
static
int
modecount_tank0203
=
0
;
static
int
tank0203_index
=
0
;
// static int s_val_1=0;
// static int s_val_2=0;
if
(
mode
==
1
)
{
tank0203_mode_lift_flont
(
val
);
tank0203_mode_right_flont
(
val
);
modecount_tank0203
=
0
;
//s_val_1 = val;
}
else
if
(
mode
==
2
)
{
tank0203_mode_lift_back
(
val
);
tank0203_mode_right_back
(
val
);
modecount_tank0203
=
1
;
//s_val_2 = val;
modecount_tank0203
=
1
;
}
if
((
mode
==
1
||
mode
==
2
)
&&
val
==
0
)
{
modecount_tank0203
=
0
;
tank0203_index
=
0
;
}
if
((
mode
==
1
||
mode
==
2
)
&&
val
!=
0
)
tank0203_index
=
1
;
if
(
mode
==
3
)
{
if
(
modecount_tank0203
==
0
){
if
(
tank0203_index
==
1
)
{
tank0203_mode_lift_flont
(
0
);
//tank0203_mode_right_flont(s_val_1-20);
}
else
{
tank0203_mode_lift_back
(
val
+
30
);
...
...
@@ -112,29 +110,24 @@ void tank0203_change(unsigned char *buf) {
if
(
modecount_tank0203
==
1
)
{
if
(
tank0203_index
==
1
)
{
tank0203_mode_lift_back
(
0
);
//tank0203_mode_lift_back(s_val_2-20);
}
else
{
tank0203_mode_lift_back
(
val
+
30
);
tank0203_mode_right_flont
(
val
+
30
);
}
}
}
else
if
(
mode
==
4
)
{
if
(
modecount_tank0203
==
1
){
if
(
tank0203_index
==
1
)
{
//tank0203_mode_right_back(s_val_1);
tank0203_mode_right_back
(
0
);
}
else
{
tank0203_mode_lift_flont
(
val
+
30
);
tank0203_mode_right_back
(
val
+
30
);
}
}
if
(
modecount_tank0203
==
0
)
{
if
(
tank0203_index
==
1
)
{
//tank0203_mode_lift_flont(s_val_1-20);
tank0203_mode_right_flont
(
0
);
}
else
{
...
...
drivers/devicecontrol/tank_common.c
View file @
4fe2e2b3
...
...
@@ -12,6 +12,7 @@ const tank_common_back *g_tank_common_config_t = NULL;
long
long
shot_device_time_start
=
0
;
long
long
shot_device_time_end
=
0
;
/*击打后退速度设置,混空模式下为单路,单独模式下为双路控制,后续需要优化*/
void
tank_shot_back
(
unsigned
char
gval
)
{
int
b
=
0
;
...
...
@@ -39,7 +40,6 @@ void tank_shot_back(unsigned char gval) {
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0204
)
pwmWrite
(
PWM_PIN_SPEED
,
speed_2
);
if
(
g_tank_common_config_t
->
device_id
==
DEVICE_TANK0204
)
pwmWrite
(
PWM_PIN_CHANGE
,
change_1
);
}
}
...
...
@@ -71,18 +71,35 @@ const tank_common_back tank_common_config_t[]={
{
.
device_id
=
-
1
}
};
void
tank_shot_back_stop_task_function
(
void
*
arg
)
{
//多线程处理坦克发射后退线程池
//多线程处理坦克发射后退线程池
void
tank_shot_back_stop_task_function
(
void
*
arg
)
{
if
(
arg
!=
NULL
){
free
(
arg
);
}
// 设置 GPIO 23 为输入模式,启用内部上拉电阻
// pinMode(23, INPUT);
// pullUpDnControl(23, PUD_UP);
// my_zlog_debug("开始监测 GPIO 23 状态...\n");
while
(
1
){
//下面一部分为检测射击后后退
// if(digitalRead(27)==LOW){
// if(g_device_delay_back_count <= g_tank_common_config_t->back_time) {
// tank_shot_back(g_tank_common_config_t->shot_back_speed);
// my_zlog_debug("操作耗时: %lld 毫秒", interval);
// }
// }else tank_shot_back(0);
//下面一部分为射击后按时间后退
long
long
interval
=
shot_device_time_start
-
shot_device_time_end
;
if
(
g_device_delay_
count
>
g_tank_common_config_t
->
back_time
&&
g_device_delay_count
<
(
g_tank_common_config_t
->
back_time
+
30
))
if
(
g_device_delay_
back_count
>
g_tank_common_config_t
->
back_time
&&
g_device_delay_back_count
<
(
g_tank_common_config_t
->
back_time
+
30
))
tank_shot_back
(
0
);
if
(
interval
>
g_tank_common_config_t
->
back_interval_back
){
if
(
g_device_delay_
count
<=
g_tank_common_config_t
->
back_time
)
{
if
(
g_device_delay_
back_count
<=
g_tank_common_config_t
->
back_time
)
{
tank_shot_back
(
g_tank_common_config_t
->
shot_back_speed
);
my_zlog_debug
(
"操作耗时: %lld 毫秒"
,
interval
);
}
...
...
@@ -92,8 +109,9 @@ void tank_shot_back_stop_task_function(void *arg) {//多线程处理坦克发射
}
ThreadPool_t
*
pool_tank_t
;
ThreadPool_t
*
pool_tank_t
;
//坦克后退线程函数
/*坦克后退线程池打开*/
void
tank_shot_pthrpoll_task_init
(){
int
*
arg
=
malloc
(
sizeof
(
int
));
*
arg
=
1
;
...
...
@@ -102,6 +120,7 @@ void tank_shot_pthrpoll_task_init(){
my_zlog_debug
(
"线程池打开"
);
}
/*坦克后退射击*/
int
tank_shot_back_stop
(
unsigned
char
pin
,
unsigned
char
val
){
static
int
shot_count
=
0
;
shot_device_time_start
=
get_current_time_millis
();
...
...
@@ -121,7 +140,7 @@ int tank_shot_back_stop(unsigned char pin,unsigned char val){
}
shot_count
=
1
;
if
(
shot_count
==
1
){
g_device_delay_
count
=
0
;
g_device_delay_
back_count
=
0
;
}
}
...
...
@@ -134,6 +153,7 @@ void tank_thread_close(){
thread_pool_destroy
(
g_pool_device_gpio_control_t
);
}
/*坦克射击接口,只有在特定设备号下使用*/
void
tank_shot_stop_control
(
int
device_id
,
unsigned
char
pin
,
unsigned
char
val
)
{
if
(
!
g_tank_common_config_t
||
g_tank_common_config_t
->
device_id
!=
device_id
)
{
...
...
drivers/devicecontrol/tank_common.h
View file @
4fe2e2b3
...
...
@@ -11,10 +11,10 @@ typedef struct {
int
(
*
shot_back
)(
unsigned
char
pin
,
unsigned
char
val
);
}
tank_common_back
;
/*坦克射击接口,只有在特定设备号下使用*/
void
tank_shot_stop_control
(
int
device_id
,
unsigned
char
pin
,
unsigned
char
val
);
/*关闭线程*/
void
tank_thread_close
();
int
angele_limit
();
#endif
\ No newline at end of file
drivers/gpio/device_init.c
View file @
4fe2e2b3
...
...
@@ -3,11 +3,11 @@
#include "common.h"
#include "gpio_init.h"
int
g_device_delay_
count
=
0
;
int
g_device_delay_
back_count
=
0
;
//设备计时,比如坦克打击倒退逻辑
int
abnormal_pin_pwm_stop
=
0
;
int
g_device_type
=
0
;
//设备类型,比如tank0202、car0101
int
g_device_type
=
0
;
//设备
详细
类型,比如tank0202、car0101
const
deviceconfig_t
device_configs
[]
=
{
// car0101配置
...
...
@@ -54,7 +54,7 @@ const deviceconfig_t device_configs[] = {
{
.
device_id
=
DEVICE_TANK0202
,
.
device_name
=
"tank0202"
,
.
gpio_pins
=
{
6
,
16
,
20
,
22
,
23
,
-
1
},
/* 补充GPIO引脚 */
.
gpio_pins
=
{
6
,
16
,
20
,
22
,
-
1
},
/* 补充GPIO引脚 */
.
gpio_pwms
=
{
5
,
7
,
24
,
26
,
27
,
-
1
},
.
device_pwm_init
=
physics_pwm_init
,
.
device_control_stop
=
tank0202_middle
,
/* 补充速度控制函数 */
...
...
@@ -63,7 +63,7 @@ const deviceconfig_t device_configs[] = {
{
.
device_id
=
DEVICE_TANK0203
,
.
device_name
=
"tank0203"
,
.
gpio_pins
=
{
6
,
16
,
20
,
22
,
23
,
-
1
},
/* 补充GPIO引脚 */
.
gpio_pins
=
{
6
,
16
,
20
,
22
,
-
1
},
/* 补充GPIO引脚 */
.
gpio_pwms
=
{
5
,
7
,
24
,
26
,
27
,
-
1
},
.
device_pwm_init
=
physics_pwm_init
,
.
device_control_stop
=
tank0203_middle
,
/* 补充速度控制函数 */
...
...
@@ -72,7 +72,7 @@ const deviceconfig_t device_configs[] = {
{
.
device_id
=
DEVICE_TANK0204
,
.
device_name
=
"tank0204"
,
.
gpio_pins
=
{
6
,
16
,
20
,
22
,
23
,
-
1
},
/* 补充GPIO引脚 */
.
gpio_pins
=
{
6
,
16
,
20
,
22
,
-
1
},
/* 补充GPIO引脚 */
.
gpio_pwms
=
{
5
,
7
,
24
,
26
,
27
,
-
1
},
.
device_pwm_init
=
physics_pwm_init
,
.
device_control_stop
=
tank0204_stop
,
/* 补充速度控制函数 */
...
...
drivers/gpio/device_init.h
View file @
4fe2e2b3
...
...
@@ -3,7 +3,7 @@
extern
int
g_device_type
;
//设备类型,比如tank0202、car0101
extern
int
g_device_delay_
count
;
//设备延时函数
extern
int
g_device_delay_
back_count
;
//设备延时函数,坦克倒退逻辑
typedef
struct
{
int
device_id
;
// 设备ID (101, 102等)
...
...
drivers/gpio/gpio_control.c
View file @
4fe2e2b3
...
...
@@ -9,14 +9,11 @@
#define GPIO_ID_THREAD_COUNT 3
int
gpio_device_id
[
GPIO_ID_THREAD_COUNT
]
=
{
DEVICE_TANK0202
,
DEVICE_TANK0203
,
DEVICE_TANK0204
};
int
gpio_device_id
[
GPIO_ID_THREAD_COUNT
]
=
{
DEVICE_TANK0202
,
DEVICE_TANK0203
,
DEVICE_TANK0204
};
//需要打开线程池设备号
const
gpiocontrol_t
*
gpio_control_config_t
=
NULL
;
ThreadPool_t
*
g_pool_device_gpio_control_t
;
static
bool
s_poll_tank_index
=
0
;
const
gpiocontrol_t
*
gpio_control_config_t
=
NULL
;
//gpio结构体标识
ThreadPool_t
*
g_pool_device_gpio_control_t
;
//gpio限位线程池标识,只在特地设备中打开
void
public_pin_value
(
int
pin
,
int
value
);
void
car0103_pin_value
(
int
pin
,
int
value
);
...
...
@@ -30,8 +27,9 @@ void tank0206_pwm_value(int pin,int value);
void
ship0301_pwm_value
(
int
pin
,
int
value
);
void
dog0501_pwm_value
(
int
pin
,
int
value
);
/*坦克限位线程函数*/
void
tank_angle_limit_function
(
void
*
arg_gpio
){
static
int
limit_log_count
=
0
;
if
(
arg_gpio
!=
NULL
)
{
free
(
arg_gpio
);
}
...
...
@@ -48,13 +46,18 @@ void tank_angle_limit_function(void *arg_gpio){
}
else
if
(
limit_status
==
0
)
{
delay_ms
(
5
);
my_zlog_debug
(
"limit stop"
);
limit_log_count
++
;
if
(
limit_log_count
>=
400
){
my_zlog_debug
(
"limit stop"
);
limit_log_count
=
0
;
}
}
}
free
(
arg_gpio
);
}
/*角度限位线程池初始化*/
void
device_gpio_control_threadpoll_init
(){
int
*
arg_gpio
=
malloc
(
sizeof
(
int
));
my_zlog_info
(
"device_gpio_control_threadpoll_init start
\n
"
);
...
...
@@ -64,7 +67,7 @@ void device_gpio_control_threadpoll_init(){
}
/*设备拉低引脚结构体数组*/
const
gpiocontrol_t
gpio_configs
[]
=
{
{
.
device_id
=
DEVICE_CAR0101
,
...
...
drivers/gpio/gpio_init.c
View file @
4fe2e2b3
...
...
@@ -8,12 +8,13 @@
#define MIN_DUTY 0 // 最小占空比
#define MAX_DUTY 100 // 最大占空比
int
g_gpioPwm
[
30
];
//软件控制
int
g_gpioPwm
[
30
];
//软件控制
pwm引脚
int
g_gpiowpi
[
40
];
//能使用高低引脚和其他引脚
int
g_gpiocount
=
0
;
int
g_gpio_softpwmcount
=
0
;
int
g_gpiocount
=
0
;
//gpio引脚数量
int
g_gpio_softpwmcount
=
0
;
//pwm引脚数量
/*初始化gpio*/
void
init_gpiowpi
(
const
int
*
values_pin
)
{
while
(
values_pin
[
g_gpiocount
]
!=
-
1
)
{
g_gpiocount
++
;
...
...
@@ -28,6 +29,7 @@ void init_gpiowpi(const int *values_pin) {
}
}
/*初始化gpio pwm*/
void
init_gpiopwm
(
const
int
*
values_pwm
)
{
while
(
values_pwm
[
g_gpio_softpwmcount
]
!=
-
1
)
{
g_gpio_softpwmcount
++
;
...
...
drivers/gpio/gpio_init.h
View file @
4fe2e2b3
...
...
@@ -12,8 +12,8 @@
extern
int
g_gpioPwm
[
30
];
//软件控制
extern
int
g_gpiowpi
[
40
];
//能使用高低引脚和其他引脚
extern
int
g_gpiocount
;
extern
int
g_gpio_softpwmcount
;
extern
int
g_gpiocount
;
//gpio引脚数量
extern
int
g_gpio_softpwmcount
;
//pwm引脚数量
void
init_gpiowpi
(
const
int
*
values_pin
);
//gpio引脚初始化
void
init_gpiopwm
(
const
int
*
values_pwm
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment