123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- /******************************* (C) LiteMesh **********************************
- * @module Console
- * @file portConsole.c
- * @version 1.0.0
- * @date XX.XX.XXXX
- * $brief Port functions console lib
- *******************************************************************************
- * @history Version Author Comment
- * XX.XX.XXXX 1.0.0 Telenkov D.A. First release.
- *******************************************************************************
- */
- #include "stm32f4xx.h"
- #include "port_microrl.h"
- #include "microrl.h"
- #include "config.h"
- #include "stdio.h"
- #include "stdlib.h"
- #include "string.h"
- #include "dac.h"
- microrl_t rl;
- microrl_t *prl = &rl;
- /*
- AVR platform specific implementation routines (for Atmega8, rewrite for your MC)
- */
- #define _AVR_DEMO_VER "1.0"
- // definition commands word
- #define _CMD_HELP "help"
- #define _CMD_CLEAR "clear"
- #define _CMD_CLR "clear_port"
- #define _CMD_SET "set_port"
- #define _CMD_DAC_SEND_TEST_VAL "dac"
- // arguments for set/clear
- #define _SCMD_PB "port_b"
- #define _SCMD_PD "port_d"
- #define _NUM_OF_CMD 5
- #define _NUM_OF_SETCLEAR_SCMD 2
- //available commands
- char * keyworld [] = {
- _CMD_HELP,
- _CMD_CLEAR,
- _CMD_SET,
- _CMD_CLR,
- _CMD_DAC_SEND_TEST_VAL};
- // 'set/clear' command argements
- char * set_clear_key [] = {_SCMD_PB, _SCMD_PD};
- // array for comletion
- char * compl_world [_NUM_OF_CMD + 1];
- /**
- * @brief
- * @retval
- */
- void MICRORL_Init(void)
- {
- microrl_init(prl, print);
- microrl_set_execute_callback (prl, execute);
-
- }
- /**
- * @brief Print callback for microrl library
- * @retval
- */
- void print (const char *str)
- {
- printf(str);
- }
- /**
- * @brief
- * @retval
- */
- void MICRORL_GetChar(uint8_t ch)
- {
- microrl_insert_char(prl, ch);
- }
- //*****************************************************************************
- // execute callback for microrl library
- // do what you want here, but don't write to argv!!! read only!!
- int execute (int argc, const char * const * argv)
- {
- int i = 0;
- // just iterate through argv word and compare it with your commands
- while (i < argc) {
- if (strcmp (argv[i], _CMD_HELP) == 0)
- {
- print ("microrl library v");
- print (MICRORL_LIB_VER);
- print ("\n\r");
- print_help (); // print help
- }
- else if (strcmp (argv[i], _CMD_CLEAR) == 0)
- {
- print ("\033[2J"); // ESC seq for clear entire screen
- print ("\033[H"); // ESC seq for move cursor at left-top corner
- }
- else if (strcmp (argv[i], _CMD_DAC_SEND_TEST_VAL) == 0)
- {
- uint16_t val;
- if (++i < argc)
- {
- val = atoi (argv[i]);
- DAC_SendRawData(val);
- return 0;
- }
- }
- else
- {
- print ("command: '");
- print ((char*)argv[i]);
- print ("' Not found.\n\r");
- }
- i++;
- }
- return 0;
- }
- void print_help (void)
- {
- print ("Use TAB key for completion\n\rCommand:\n\r");
- print ("\tclear - clear screen\n\r");
- print ("\tdac - send test value\n\r");
- }
- /******************************* (C) LiteMesh *********************************/
|