-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandLineTest.ino
More file actions
126 lines (103 loc) · 2.66 KB
/
CommandLineTest.ino
File metadata and controls
126 lines (103 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* NAME: CommandLineTest.c
*
* WHAT:
* A simple Arduino serial command line I/F test program.
*
* It demonstrates use of CommandLine library:
* - command line menus (stored and acted on in Flash)
* - parsing command line parameters
*
* Can be used as a template for a larger application.
*
* SPECIAL CONSIDERATIONS:
* None.
*
* AUTHOR:
* D.L. Karmann
*
* MODIFIED:
*
*/
#include <ctype.h>
#include <stdint.h>
#include <stdio.h>
#include <CommandLine.h>
#define TITLE_MSG "Arduino Command Line Testing"
#define LED_PIN LED_BUILTIN // the Arduino LED pin
#define LED_ON HIGH
#define LED_OFF LOW
#define LED_HB -1
#define TIMER_EXPIRED(start, interval) ((millis() - start) >= interval)
#define HEARTBEAT_OFF_INTERVAL 950 // mS
#define HEARTBEAT_ON_INTERVAL 50 // mS
int8_t LedState = LED_HB;
CommandLine CmdLine(Serial); // setup CommandLine to use standard Arduino Serial and echo on
void setup()
{
// init Arduino LED
pinMode(LED_PIN, OUTPUT);
LED_off();
// setup serial port
Serial.begin(115200);
// generate the sign-on banner
Serial.println(F(CLS_HOME));
Serial.println(F("CommandLineTest.ino"));
Serial.println(F(TITLE_MSG));
// CmdLine.Echo(false); // disable echo of received characters (default enabled)
// CmdLine.CrLfCommand(false); // disable sending CR/LF characters before processing command (default enabled)
// CmdLine.Delimiter(','); // change delimiter from default ' ' to ',' (space to comma)
delay(50);
}
void loop()
{
static bool new_prompt = true;
if (new_prompt)
{
new_prompt = false;
//
// Print a prompt to the console.
//
Serial.println();
Serial.print(F("-> "));
}
new_prompt = CmdLine.DoCmdLine();
// do other stuff here
// do Heartbeat
DoHeartbeat();
}
// do Heartbeat
void DoHeartbeat(void)
{
static uint32_t last_HB_tick = 0;
static uint8_t last_HB_state = false;
if (LedState == LED_HB)
{
if (last_HB_state)
{
if (TIMER_EXPIRED(last_HB_tick, HEARTBEAT_ON_INTERVAL))
{
LED_off(); // off
last_HB_state = false;
last_HB_tick = millis();
}
}
else
{
if (TIMER_EXPIRED(last_HB_tick, HEARTBEAT_OFF_INTERVAL))
{
LED_on(); // on
last_HB_state = true;
last_HB_tick = millis();
}
}
}
}
void LED_on(void)
{
digitalWrite(LED_PIN, LED_ON);
}
void LED_off(void)
{
digitalWrite(LED_PIN, LED_OFF);
}