Debug.ino
3.22 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
/*
Debug.ino - CLI library sample implementing a CLI for the Blink sample code
Version 1.0, latest version, documentation and bugtracker available at:
https://gitlab.lindenaar.net/arduino/CLI
Copyright (c) 2019 Frederik Lindenaar
This sketch demonstrates the debugging commands available as part of the CLI
library. These commands are intended to eliminate the need to write code to
check things in or connected to your microcontroller. Over time, additional
commands will be added, when needed (feel free to submit your favorites for
inclusion!). At this moment it makes the following commands available through
the Serial Monitor (available from the Tools menu of the Arduino IDE):
- eeprom_dump dump the contents of the built-in EEPROM
- i2c_scan scan the I2C bus for slave devices
- i2c_dump dump the contents of I2C attached EEPROM or Memory
- reset restart the microcontroller (software reset)
- help show the available commands and how to use them
For each of these commands the implementation is included in the CLI library.
This sketch is free software: you can redistribute it and/or modify it under
the terms of version 3 of the GNU General Public License as published by the
Free Software Foundation, or (at your option) a later version of the license.
This code is distributed in the hope that it will be useful but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, visit <http://www.gnu.org/licenses/> to download it.
*/
#include <CLI.h>
#include <Wire.h>
// Initialize the Debug Command Line Interface
const char banner[] PROGMEM = "Debug Sample CLI"; // Banner to show upon startup of the CLI
CLI CLI(Serial, banner); // Initialize the CLI, telling it to attach to Serial
EEPROM_Dump_Command EEPROM_Dump(CLI); // Initialize/Register (built-in) eeprom_dump command
I2C_Scan_Command I2C_Scan(CLI); // Initialize/Register (built-in) i2c_scan command
I2C_Dump_Command I2C_Dump(CLI); // Initialize/Register (built-in) i2c_dump command
Reset_Command Reset(CLI); // Initialize/Register (built-in) reset command
Help_Command Help(CLI); // Initialize/Register (built-in) help command
// the setup function runs once when you reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
// Initialize the Serial port for the CLI
while (!Serial); // For Leonardo: wait for serial USB to connect
Serial.begin(9600);
// Initialize the Wire Interface
Wire.begin();
}
// the loop function runs over and over again forever
void loop() {
// handle CLI, if this returns true a command is running. Set Builtin LED accordingly
if (CLI.process()) {
digitalWrite(LED_BUILTIN, HIGH); // turn LED on when processing CLI command
} else {
digitalWrite(LED_BUILTIN, LOW); // turn LED off when not processing CLI command
}
}