|
6 | 6 | #include <rtt.h>
|
7 | 7 |
|
8 | 8 | /* ATTENTION
|
9 |
| - Please append your new shell commands and variables to "shell_cmd.h" and |
10 |
| - "shell_var.h". |
| 9 | + - Please enable "CONFIG_USING_FINSH" in "rtconfig.h" |
| 10 | + - Please add new shell commands to "shell_cmd.h". |
11 | 11 | */
|
12 | 12 |
|
13 | 13 | /* NOTES
|
14 |
| - When using FinSH without MSH (CONFIG_USING_FINSH == 1 && |
15 |
| - CONFIG_USING_MSH == 0): |
16 |
| - - please append the following line to "shell_cmd.h": |
17 |
| - ADD_FINSH_CMD(led, Turn on/off builtin LED, led, rt_uint32_t, rt_uint32_t id, rt_uint8_t state) |
18 |
| - - and append the following 2 lines to "shell_var.h" |
19 |
| - ADD_SHELL_VAR(id, LED ID, led_id, finsh_type_uint) |
20 |
| - ADD_SHELL_VAR(state, LED state, led_state, finsh_type_uchar) |
21 |
| -
|
22 |
| - After uploaded, please send the following command through "Serial Monitor" |
23 |
| - and observe the output: |
24 |
| - led(0, 1) |
25 |
| - led(0, 0) |
26 |
| - led(id, state) |
27 |
| - state |
28 |
| - state=0 |
29 |
| - led(id, state) |
30 |
| - */ |
31 |
| - |
32 |
| -/* NOTES |
33 |
| - When using FinSH with MSH (default, CONFIG_USING_FINSH == 1 && |
34 |
| - CONFIG_USING_MSH == 1): |
35 |
| - - please append the following line to "shell_cmd.h": |
36 |
| - ADD_MSH_CMD(led, Turn on/off builtin LED, led, int, int argc, char **argv) |
37 |
| - - due to MSH doesn't support shell variables, "ADD_SHELL_VAR" has no effect |
38 |
| -
|
39 |
| - After uploaded, please send the following command through "Serial Monitor" |
40 |
| - and observe the output: |
41 |
| - led 0, 1, 2 |
42 |
| - led 1, 1 |
43 |
| - led 0, 1 |
| 14 | + - Using "MSH_CMD_EXPORT_ALIAS" macro to export shell command with the following format: |
| 15 | + MSH_CMD_EXPORT_ALIAS(function_name, command_name, command description) |
| 16 | + - Using "ADD_MSH_CMD" macro to add shell command to system with the following format: |
| 17 | + ADD_MSH_CMD(function_name) |
| 18 | + - Please insert the following line to "shell_cmd.h": |
| 19 | + ADD_MSH_CMD(led) |
| 20 | +
|
| 21 | + After uploaded, please send the following command through "Serial Monitor" and observe the output: |
| 22 | + led 0 1 2 |
| 23 | + led 1 1 |
| 24 | + led 0 1 |
44 | 25 | */
|
45 | 26 |
|
46 | 27 | extern "C" {
|
47 | 28 |
|
48 |
| -#if !CONFIG_USING_MSH |
49 |
| - |
50 |
| - rt_uint32_t led_id = 0; |
51 |
| - rt_uint32_t led_state = 1; |
52 |
| - |
53 |
| - rt_uint32_t led(rt_uint32_t id, rt_uint32_t state) { |
54 |
| - rt_kprintf("led%d=%d\n", id, state); |
55 |
| - if (id != 0) { |
56 |
| - return 1; |
57 |
| - } |
58 |
| - if (state) { |
59 |
| - digitalWrite(LED_BUILTIN, HIGH); |
60 |
| - } else { |
61 |
| - digitalWrite(LED_BUILTIN, LOW); |
62 |
| - } |
63 |
| - return 0; |
64 |
| - } |
65 |
| - |
66 |
| -#else /* !CONFIG_USING_MSH */ |
67 |
| - |
68 |
| - int led(int argc, char **argv) { |
| 29 | + int led_set(int argc, char **argv) { |
69 | 30 | // argc - the number of arguments
|
70 | 31 | // argv[0] - command name, e.g. "led"
|
71 | 32 | // argv[n] - nth argument in the type of char array
|
@@ -93,10 +54,8 @@ extern "C" {
|
93 | 54 | }
|
94 | 55 | return 0;
|
95 | 56 | }
|
96 |
| - |
97 |
| -#endif |
98 |
| - |
99 | 57 | }
|
| 58 | +MSH_CMD_EXPORT_ALIAS(led_set, led, Turn on/off builtin LED.); |
100 | 59 |
|
101 | 60 | void setup() {
|
102 | 61 | pinMode(LED_BUILTIN, OUTPUT);
|
|
0 commit comments