Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
berrak committed Dec 18, 2022
0 parents commit d38155a
Show file tree
Hide file tree
Showing 9 changed files with 416 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Git ignore list
.git

# Project files
.vscode
.komodotools
*.komodoproject

# Formatters and checks
Doxyfile*
*.doxyfile
_clang-format

# Other potential files
*.zip
*.bak

# Build and test
Makefile
test/
build/
23 changes: 23 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
The MIT License (MIT)
Copyright (c) 2021 Ralph Bacon

Adapted and simplified original code.
Copyright (C) 2022 Debinix Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
![serial-output](./images/serial-monitor.png)

[![GitHub license](https://img.shields.io/github/license/berrak/Rdebug.svg?logo=gnu&logoColor=ffffff)](https://github.com/berrak/Rdebug/blob/master/LICENSE)
[![GitHub version](https://img.shields.io/github/release/berrak/Rdebug.svg?logo=github&logoColor=ffffff)](https://github.com/berrak/Rdebug/releases/latest)
[![GitHub Release Date](https://img.shields.io/github/release-date/berrak/Rdebug.svg?logo=github&logoColor=ffffff)](https://github.com/berrak/Rdebug/releases/latest)
[![GitHub stars](https://img.shields.io/github/stars/berrak/Rdebug.svg?logo=github&logoColor=ffffff)](https://github.com/berrak/Rdebug/stargazers)
[![GitHub issues](https://img.shields.io/github/issues/berrak/Rdebug.svg?logo=github&logoColor=ffffff)](https://github.com/berrak/Rdebug/issues)
![Badge Hit Counter](https://visitor-badge.laobi.icu/badge?page_id=berrak_Rdebug)

# A handy library to smash out Arduino bugs.

As in many similar debugging frameworks, the `Rdebug library` defines different `debug levels`. So with a simple `#define`, you can turn the `On` and `Off` serial monitor output for these statements.

```
ON < DEBUG < INFO < WARN < ERROR
```

The heart of the library is the hierarchy. Set the log level to `WARN`, then the `lower` groups are also included. In this case, it enables `ON`, `DEBUG`, and `INFO`.

Set the level to the highest level, i.e., `ERROR` during development, and reduce it once the code is released.

If the level is `OFF`, then all debug macros are disabled, and only the usual Arduino serial print statement emits any text to the user.

If the level is `ON`, a.k.a. `lazy mode`, you can use the `debug` and the `debugln` macros to save you from typing in `Serial.print` and `Serial.println` all the time. The macro expands to the latter two functions.

# Debug levels

The library includes the following defined levels:

```
DEBUGLEVEL_OFF - all debug macros are disabled
DEBUGLEVEL_ON - the non-traced macro (lazy mode) is enabled
DEBUGLEVEL_DEBUG - traced debug messages
DEBUGLEVEL_INFO - traced information messages
DEBUGLEVEL_WARN - traced warning messages
DEBUGLEVEL_ERROR - traced error messages
```

The latter four are identical and produce a slightly different monitor output. You, as the user, decide how to apply these in the code such that it makes sense. They all have the following generic form.

```
[level][function name:line number] "string message"
```
The traced macros end with `D`, `I`, `W`, and `E` for their log level.

```
debugD(), debuglnD() // DEBUGLEVEL_DEBUG
debugI(), debuglnI() // DEBUGLEVEL_INFO
debugW(), debuglnW() // DEBUGLEVEL_WARN
debugE(), debuglnE() // DEBUGLEVEL_ERROR
```

The `lazy` non-trace macro does not have these letters at the end.
```
debug() ---> Serial.print() // DEBUGLEVEL_ON
debugln() ---> Serial.println() // DEBUGLEVEL_ON
```

# Usage

Initially, in your sketch, set the debugging level to `DEBUGLEVEL_ERROR` so that **all** debugging messages appear:

```
#define DEBUGLEVEL_ERROR
```
Then include the header file:
```
#include <Rdebug.h>
```

# Run the example code
Experiment with different debug levels to include or exclude the above debug statements with the sketch `Rdebug.ino` in the examples folder.

## Credits.
Thanks to `Ralph S Bacon` for his enjoyable [YT channel](https://www.youtube.com/@RalphBacon) with many valuable tips and hints related to microcontrollers, coding, and everything related to the Arduino echo system.

# References
Ralph's information to his original [superior debugging](https://github.com/RalphBacon/224-Superior-Serial.print-statements) repository.

117 changes: 117 additions & 0 deletions examples/Rdebug/Rdebug.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#include <Arduino.h>

// The heart of the library is the hierarchy. Set the log level
// to `WARN`, then the `lower` groups are also included. In this
// case, it enables `ON`, `DEBUG`, and `INFO`.

// ON < DEBUG < INFO < WARN < ERROR

// DEBUGLEVEL_OFF - all debug macros are disabled
// DEBUGLEVEL_ON - the non-traced macro (lazy mode) are enabled
// DEBUGLEVEL_DEBUG - traced debug messages
// DEBUGLEVEL_INFO - traced imnformation messages
// DEBUGLEVEL_WARN - traced warning messages
// DEBUGLEVEL_ERROR - traced error messages

#define DEBUGLEVEL_ERROR
#include <Rdebug.h>

void fadeLED(void);
int fadeDebug(int loop_counter);
int fadeInfo(int loop_counter);
int fadeWarn(int loop_counter);
int fadeError(int loop_counter);

int ledPin = LED_BUILTIN;

// ------------------------------------------------------------------
// SETUP SETUP SETUP SETUP SETUP SETUP SETUP
// ------------------------------------------------------------------
void setup() {
Serial.begin(9600);
do {
delay(2000);
} while (!Serial);

Serial.println("Serial.println: Setup complete.");
}
// ------------------------------------------------------------------
// MAIN LOOP MAIN LOOP MAIN LOOP MAIN LOOP MAIN LOOP
// ------------------------------------------------------------------
void loop() {

static int loop_counter = 0;

Serial.println("Serial.println: In the loop");

fadeDebug(loop_counter); // Uses Debug level macros only
fadeInfo(loop_counter); // Uses Info level macros only
fadeWarn(loop_counter); // Uses Warn level macros only
fadeError(loop_counter); // Uses Error level macros only

debugln("All four calls done!"); // no trace data added

loop_counter++;
}
// ------------------------------------------------------------------
// HELPERS HELPERS HELPERS HELPERS HELPERS
// ------------------------------------------------------------------
void fadeLED(void) {
for (int fadeValue = 0; fadeValue <= 255; fadeValue += 10) {
analogWrite(ledPin, fadeValue);
delay(30);
}

for (int fadeValue = 255; fadeValue >= 0; fadeValue -= 10) {
analogWrite(ledPin, fadeValue);
delay(30);
}
}
// ------------------------------------------------------------------
int fadeDebug(int loop_counter) {
debugD("Received value:");
debuglnD(loop_counter);

fadeLED();

debugD("Returning: ");
debuglnD(loop_counter + 1);
return loop_counter + 1;
}

// -----------------------------------------------------------------
int fadeInfo(int loop_counter) {
debugI("Received value:");
debuglnI(loop_counter);

fadeLED();

debugI("Returning: ");
debuglnI(loop_counter + 1);
return loop_counter + 1;
}
// ------------------------------------------------------------------
int fadeWarn(int loop_counter) {
debugW("Received value:");
debuglnW(loop_counter);

fadeLED();

debugW("Returning: ");
debuglnW(loop_counter + 1);
return loop_counter + 1;
}

// -----------------------------------------------------------------
int fadeError(int loop_counter) {
debugE("Received value:");
debuglnE(loop_counter);

fadeLED();

debugE("Returning: ");
debuglnE(loop_counter + 1);
return loop_counter + 1;
}

/* EOF */
Binary file added images/serial-monitor.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Rdebug
# Note: Only ONE true tab-char to separate items!
# Syntax Coloring Map

# Datatypes: (KEYWORD1)
# Classes & Namespaces: (KEYWORD2)
# Methods and Functions: (KEYWORD2)
# Structure: (KEYWORD3)
# Constants: (LITERAL1)

Rdebug KEYWORD2

DEBUGLEVEL_OFF LITERAL1
DEBUGLEVEL_ON LITERAL1
DEBUGLEVEL_DEBUG LITERAL1
DEBUGLEVEL_INFO LITERAL1
DEBUGLEVEL_WARN LITERAL1
DEBUGLEVEL_ERROR LITERAL1
10 changes: 10 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name=Rdebug
version=0.1.0
author=Debinix Team <[email protected]>
maintainer=Debinix Team <[email protected]>
sentence=The Arduino library provides a unique form of debugging.
paragraph=The Rdebug library defines different debug levels, as in many similar debugging frameworks. Turn these On and Off statements at will. The debugging library is an adaption of Ralph S Bacons original code.
category=Other
url=https://github.com/berrak/Rdebug
architectures=*
includes=Rdebug.h
14 changes: 14 additions & 0 deletions src/Rdebug.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* File: Rdebug.cpp
* The Arduino library provides a unique form of debugging.
*
* Copyright (c) 2021 Ralph Bacon
* https://github.com/RalphBacon/224-Superior-Serial.print-statements
*
* Adapted and modified original code.
* Copyright (C) 2022 Debinix Team
* https://github.com/berrak/Rdebug
*
* The MIT License
*
*/
Loading

0 comments on commit d38155a

Please sign in to comment.