108|0

6869

帖子

11

TA的资源

版主

楼主
 

【Follow me第二季第3期】进阶任务——示例程序中新增命令打印信息: [复制链接]

 

1、quickstart_ek工程中新建两个文件,分别为menu_dac.h/c:

 

2、menu_adc.c内容如下,主要是进入时,打印提示菜单,然后周期读取数据,如果是1-5打印出相应的字符,如果是0则退出此个菜单:

/*
 * menu_dac.c
 *
 *  Created on: 2024年12月14日
 *      Author: liujianhua
 */

#include <stdio.h>
#include <string.h>

#include "FreeRTOS.h"
#include "FreeRTOSConfig.h"
#include "semphr.h"
#include "queue.h"
#include "task.h"

#include "bsp_api.h"
#include "common_init.h"
#include "common_data.h"
#include "common_utils.h"
#include "menu_ext.h"



#define CONNECTION_ABORT_CRTL          (0x00)
#define MENU_EXIT_CRTL                 (0x20)
#define MENU_ENTER_RESPONSE_CRTL       (0x09)
#define INPUT_BUFFER                   (0x05)
#define CARRAGE_RETURN                 (0x0D)

#define BLOCK_LIMIT                    (0x40)

#define MODULE_NAME     "\r\n DAC TEST\r\n"

#define SUB_OPTIONS     ("Wave control:\r\n" \
		                "1: Triangle Wave\r\n" \
		                "2: Square Wave\r\n" \
						"3: Sine Wave\r\n" \
						"4: Read from flash \r\n" \
                        "5: Write to flash \r\n" \
                        "0: Exit\r\n")

/* Each thread must have a separate print buffer, to avoid clashes on task switching */
static char_t s_print_buffer[BUFFER_LINE_LENGTH] = {};
static char_t s_block_sz_str[INPUT_BUFFER] = {};



/**********************************************************************************************************************
 * Function Name: ext_display_menu
 * Description  : .
 * Return Value : .
 *********************************************************************************************************************/
test_fn dac_display_menu(void)
{
    int32_t c = -1;


    uint32_t value = 0;

    sprintf(s_print_buffer, "%s%s", gp_clear_screen, gp_cursor_home);

    /* ignoring -Wpointer-sign is OK when treating signed char_t array as as unsigned */
    print_to_console((void*)s_print_buffer);
    sprintf(s_print_buffer, MODULE_NAME, g_selected_menu);

    /* ignoring -Wpointer-sign is OK when treating signed char_t array as as unsigned */
    print_to_console((void*)s_print_buffer);
  //  sprintf(s_print_buffer, SUB_OPTIONS);

    /* ignoring -Wpointer-sign is OK when treating signed char_t array as as unsigned */
    print_to_console((void*)SUB_OPTIONS);

        /* Reset input state */
        c = -1;

        memset(&s_block_sz_str, 0, INPUT_BUFFER);

        while ((CONNECTION_ABORT_CRTL != c))
        {
            c = input_from_console();
            value = (uint32_t)(c-'0');
            switch (value)
            {
                case INVALID_CHARACTER:
                    sprintf(s_print_buffer,"\r\n> Invalid character in entry,please entry'0-5'");
                    print_to_console((void*)s_print_buffer);
                    break;
                case 1:
                    sprintf(s_print_buffer,"\r\n> begain Triangle Wave ");
                    print_to_console((void*)s_print_buffer);
                    break;
                case 2:
                    sprintf(s_print_buffer,"\r\n> begain Square Wave ");
                    print_to_console((void*)s_print_buffer);
                    break;
                case 3:
                    sprintf(s_print_buffer,"\r\n> begain Sine Wave ");
                    print_to_console((void*)s_print_buffer);
                    break;
                case 4:
                    sprintf(s_print_buffer,"\r\n> Read from flash ");
                    print_to_console((void*)s_print_buffer);
                    break;
                case 5:
                    sprintf(s_print_buffer,"\r\n> Write to flash ");
                    print_to_console((void*)s_print_buffer);
                    break;
                case 0:
                    sprintf(s_print_buffer,"\r\n> Exit ");
                    print_to_console((void*)s_print_buffer);
                    return 0;
                    break;
            }
        }

    while ((CONNECTION_ABORT_CRTL != c))
    {
        if ((MENU_EXIT_CRTL == c) || (0x00 == c))
        {
            break;
        }
        c = input_from_console();
    }

    return (0);
}
/**********************************************************************************************************************
 End of function ext_display_menu
 *********************************************************************************************************************/

3、头文件则是声明菜单的接口:

#ifndef __MENU_DAC_H__
#define __MENU_DAC_H__


test_fn dac_display_menu(void);


#endif __MENU_DAC_H__

4、将头文件添加到menu_main.h中:

 

5、在主菜单的列表里添加一条菜单,并把dac_display_menu子菜单函数添加进回调函数:

  【实现效果】

 

按6进入子菜单:

 

按下0又可以回到主菜单。

点赞 关注
 
 

回复
举报
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表