2023-12-11 21:45:06 +08:00
|
|
|
|
/*********************************************************************************************************************
|
2024-01-04 22:07:13 +08:00
|
|
|
|
* CH32V307VCT6 Opensourec Library 即(CH32V307VCT6 开源库)是一个基于官方 SDK 接口的第三方开源库
|
|
|
|
|
|
* Copyright (c) 2022 SEEKFREE 逐飞科技
|
|
|
|
|
|
*
|
|
|
|
|
|
* 本文件是 CH32V307VCT6 开源库的一部分
|
|
|
|
|
|
*
|
|
|
|
|
|
* CH32V307VCT6 开源库 是免费软件
|
|
|
|
|
|
* 您可以根据自由软件基金会发布的 GPL(GNU General Public License,即 GNU 通用公共许可证)的条款
|
|
|
|
|
|
* 即 GPL 的第 3 版(即 GPL3.0)或(您选择的)任何后来的版本,重新发布和/或修改它
|
|
|
|
|
|
*
|
|
|
|
|
|
* 本开源库的发布是希望它能发挥作用,但并未对其作任何的保证
|
|
|
|
|
|
* 甚至没有隐含的适销性或适合特定用途的保证
|
|
|
|
|
|
* 更多细节请参见 GPL
|
|
|
|
|
|
*
|
|
|
|
|
|
* 您应该在收到本开源库的同时收到一份 GPL 的副本
|
|
|
|
|
|
* 如果没有,请参阅<https://www.gnu.org/licenses/>
|
|
|
|
|
|
*
|
|
|
|
|
|
* 额外注明:
|
|
|
|
|
|
* 本开源库使用 GPL3.0 开源许可证协议 以上许可申明为译文版本
|
|
|
|
|
|
* 许可申明英文版在 libraries/doc 文件夹下的 GPL3_permission_statement.txt 文件中
|
|
|
|
|
|
* 许可证副本在 libraries 文件夹下 即该文件夹下的 LICENSE 文件
|
|
|
|
|
|
* 欢迎各位使用并传播本程序 但修改内容时必须保留逐飞科技的版权声明(即本声明)
|
|
|
|
|
|
********************************************************************************************************************/
|
2024-02-15 22:50:20 +08:00
|
|
|
|
#include "zf_common_headfile.h"
|
2023-12-17 16:11:35 +08:00
|
|
|
|
#include "gl_headfile.h"
|
2024-02-15 22:50:20 +08:00
|
|
|
|
#include "page.h"
|
|
|
|
|
|
#include "by_tiny_frame.h"
|
2024-01-08 22:08:43 +08:00
|
|
|
|
#include "by_buzzer.h"
|
2024-01-31 17:43:48 +08:00
|
|
|
|
#include "by_led.h"
|
2024-01-31 17:55:16 +08:00
|
|
|
|
#include "jj_param.h"
|
|
|
|
|
|
#include "jj_blueteeth.h"
|
|
|
|
|
|
|
2024-02-23 18:56:53 +08:00
|
|
|
|
/** 测试完成后移除 **/
|
2024-02-15 22:50:20 +08:00
|
|
|
|
#include "by_tiny_frame_parse.h"
|
2024-02-23 18:56:53 +08:00
|
|
|
|
#include "by_tiny_frame_pack.h"
|
|
|
|
|
|
/** 测试完成后移除 **/
|
2024-02-15 22:50:20 +08:00
|
|
|
|
|
2024-02-23 21:13:31 +08:00
|
|
|
|
void test(by_tf_parse_frame_t frame_s, uint8_t status)
|
2024-02-23 20:13:34 +08:00
|
|
|
|
{
|
2024-02-23 21:13:31 +08:00
|
|
|
|
printf("parse done\r\n");
|
|
|
|
|
|
printf("--cmd: %0.2X\n--reg_addr: %0.4X\n--data: %0.8X\r\n", frame_s.cmd, frame_s.reg_addr, frame_s.data);
|
2024-02-23 20:41:40 +08:00
|
|
|
|
if (status) {
|
|
|
|
|
|
printf("noooooooo!\r\n");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
printf("hhhhhhok\r\n");
|
|
|
|
|
|
}
|
2024-02-23 20:13:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-16 11:31:25 +08:00
|
|
|
|
int main(void)
|
2023-12-11 21:45:06 +08:00
|
|
|
|
{
|
2024-01-07 17:20:10 +08:00
|
|
|
|
|
2024-01-31 17:20:09 +08:00
|
|
|
|
clock_init(SYSTEM_CLOCK_144M);
|
2024-01-05 09:13:10 +08:00
|
|
|
|
system_delay_init();
|
2023-12-24 22:21:15 +08:00
|
|
|
|
debug_init();
|
2024-01-31 17:20:09 +08:00
|
|
|
|
// mt9v03x_init();
|
2023-12-21 22:33:36 +08:00
|
|
|
|
ips200_init(IPS200_TYPE_SPI);
|
2024-01-31 17:43:48 +08:00
|
|
|
|
|
|
|
|
|
|
by_led_init();
|
2024-01-08 22:08:43 +08:00
|
|
|
|
by_buzzer_init();
|
2024-01-31 17:20:09 +08:00
|
|
|
|
by_button_init();
|
2024-01-31 17:43:48 +08:00
|
|
|
|
|
2024-02-10 16:19:51 +08:00
|
|
|
|
// jj_bt_init();
|
2024-01-31 17:20:09 +08:00
|
|
|
|
// jj_param_eeprom_init();
|
2024-01-31 17:55:16 +08:00
|
|
|
|
|
2023-12-21 22:33:36 +08:00
|
|
|
|
Page_Init();
|
2024-01-31 17:55:16 +08:00
|
|
|
|
|
2024-02-10 16:19:51 +08:00
|
|
|
|
// pit_ms_init(TIM6_PIT, 2);
|
|
|
|
|
|
// pit_ms_init(TIM1_PIT, 2);
|
2024-01-31 17:55:16 +08:00
|
|
|
|
|
2024-02-15 22:50:20 +08:00
|
|
|
|
by_tiny_frame_init();
|
|
|
|
|
|
printf("start running\r\n");
|
|
|
|
|
|
|
2024-02-23 18:56:53 +08:00
|
|
|
|
/** 测试完成后移除 **/
|
2024-02-23 20:13:34 +08:00
|
|
|
|
by_tiny_frame_parse_handle_register(test);
|
|
|
|
|
|
by_tiny_frame_parse_start_listern();
|
|
|
|
|
|
|
2024-02-23 18:56:53 +08:00
|
|
|
|
by_tf_pack_frame_t frame_now;
|
|
|
|
|
|
|
|
|
|
|
|
frame_now.cmd = 0x06;
|
|
|
|
|
|
frame_now.data = 0x19260817;
|
|
|
|
|
|
frame_now.reg_addr = 0x4059;
|
|
|
|
|
|
frame_now.slave_id = 0x0D;
|
|
|
|
|
|
/** 测试完成后移除 **/
|
|
|
|
|
|
|
2023-12-21 22:33:36 +08:00
|
|
|
|
while (1) {
|
|
|
|
|
|
Page_Run();
|
2024-02-10 16:19:51 +08:00
|
|
|
|
by_buzzer_run();
|
2024-02-23 18:56:53 +08:00
|
|
|
|
|
|
|
|
|
|
/** 测试完成后移除 **/
|
2024-02-15 22:50:20 +08:00
|
|
|
|
by_tiny_frame_parse_run();
|
2024-02-23 18:56:53 +08:00
|
|
|
|
// by_tiny_frame_pack_send(&frame_now);
|
2024-02-23 20:13:34 +08:00
|
|
|
|
system_delay_ms(10);
|
|
|
|
|
|
by_tiny_frame_parse_timer_handle();
|
2024-02-23 18:56:53 +08:00
|
|
|
|
/** 测试完成后移除 **/
|
|
|
|
|
|
|
2024-02-15 22:50:20 +08:00
|
|
|
|
// if (mt9v03x_finish_flag) {
|
|
|
|
|
|
// // 该操作消耗大概 1970 个 tick,折合约 110us
|
|
|
|
|
|
// memcpy(mt9v03x_image_copy[0], mt9v03x_image[0], (sizeof(mt9v03x_image_copy) / sizeof(uint8_t)));
|
|
|
|
|
|
// // adaptiveThreshold((uint8_t*)mt9v03x_image_copy, (uint8_t*)mt9v03x_image_copy, 188, 120, 7, 17);
|
|
|
|
|
|
// // ips200_show_gray_image(0, 0, mt9v03x_image_copy[0], MT9V03X_W, MT9V03X_H, MT9V03X_W, MT9V03X_H, 0);
|
|
|
|
|
|
// mt9v03x_finish_flag = 0;
|
|
|
|
|
|
// by_led_info_blink();
|
|
|
|
|
|
// state_type = COMMON_STATE;
|
|
|
|
|
|
// img_processing();
|
|
|
|
|
|
// get_corners();
|
|
|
|
|
|
// aim_distance = COMMON_AIM;
|
|
|
|
|
|
// tracking();
|
|
|
|
|
|
// ElementJudge();
|
|
|
|
|
|
// ElementRun();
|
|
|
|
|
|
// MidLineTrack();
|
|
|
|
|
|
// }
|
2023-12-11 21:45:06 +08:00
|
|
|
|
}
|
2024-01-16 20:03:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-31 17:20:09 +08:00
|
|
|
|
void adaptiveThreshold(uint8_t *img_data, uint8_t *output_data, int width, int height, int block, uint8_t clip_value)
|
|
|
|
|
|
{
|
|
|
|
|
|
int half_block = block / 2;
|
|
|
|
|
|
for (int y = half_block; y < height - half_block; y++) {
|
|
|
|
|
|
for (int x = half_block; x < width - half_block; x++) {
|
|
|
|
|
|
// 计算局部阈值
|
|
|
|
|
|
int thres = 0;
|
|
|
|
|
|
for (int dy = -half_block; dy <= half_block; dy++) {
|
|
|
|
|
|
for (int dx = -half_block; dx <= half_block; dx++) {
|
|
|
|
|
|
thres += img_data[(x + dx) + (y + dy) * width];
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
thres = thres / (block * block) - clip_value;
|
|
|
|
|
|
// 进行二值化
|
|
|
|
|
|
output_data[x + y * width] = img_data[x + y * width] > thres ? 255 : 0;
|
2023-12-11 21:45:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-01-16 20:09:12 +08:00
|
|
|
|
}
|