Skip to content

Commit

Permalink
Merge pull request #10 from J-Rios/development
Browse files Browse the repository at this point in the history
Version v1.2.0 (command setup and callbacks)
  • Loading branch information
J-Rios authored Mar 5, 2023
2 parents 41c24b6 + 9a4ba69 commit 3d06849
Show file tree
Hide file tree
Showing 123 changed files with 7,781 additions and 401 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/build_avr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- main
- development

jobs:
build_avr:
Expand All @@ -26,6 +27,11 @@ jobs:
sudo apt-get -y install cflow
- name: Build
run: |
cd examples/avr/basic_usage/build
cd examples/avr/
cd basic_usage/build/
make clean
make build DEVICE=atmega328p F_CPU=16000000L
cd ../../
cd basic_usage_callbacks/build/
make clean
make build DEVICE=atmega328p F_CPU=16000000L
8 changes: 7 additions & 1 deletion .github/workflows/build_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- main
- development

jobs:
build_linux:
Expand All @@ -26,6 +27,11 @@ jobs:
sudo apt-get -y install cflow
- name: Build
run: |
cd examples/linux/basic_usage/build
cd examples/linux/
cd basic_usage/build/
make clean
make build
cd ../../
cd basic_usage_callbacks/build/
make clean
make build
15 changes: 8 additions & 7 deletions .github/workflows/build_pio_arduino.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ on:
pull_request:
branches:
- main
- development

jobs:
build_pio_arduino:

runs-on: ubuntu-latest
strategy:
matrix:
example: [examples/arduino/basic_usage/src/main.cpp]

steps:
- uses: actions/checkout@v2
- name: Cache pip
Expand All @@ -33,6 +30,10 @@ jobs:
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Run PlatformIO
run: pio ci --project-conf="examples/arduino/basic_usage/platformio.ini"
env:
PLATFORMIO_CI_SRC: ${{ matrix.example }}
run: |
pio run -c examples/arduino/platformio.ini \
-d examples/arduino/basic_usage \
-e arduino_uno_atmega328 -e arduino_esp32 -e arduino_esp8266
pio run -c examples/arduino/platformio.ini \
-d examples/arduino/basic_usage_callbacks \
-e arduino_uno_atmega328 -e arduino_esp32 -e arduino_esp8266
15 changes: 8 additions & 7 deletions .github/workflows/build_pio_espidf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ on:
pull_request:
branches:
- main
- development

jobs:
build_pio_espidf:

runs-on: ubuntu-latest
strategy:
matrix:
example: [examples/espidf/basic_usage/src/main.cpp]

steps:
- uses: actions/checkout@v2
- name: Cache pip
Expand All @@ -33,6 +30,10 @@ jobs:
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Run PlatformIO
run: pio ci --project-conf="examples/espidf/basic_usage/platformio.ini"
env:
PLATFORMIO_CI_SRC: ${{ matrix.example }}
run: |
pio run -c examples/espidf/platformio.ini \
-d examples/espidf/basic_usage \
-e espidf_esp32 -e espidf_esp32_c3
pio run -c examples/espidf/platformio.ini \
-d examples/espidf/basic_usage_callbacks \
-e espidf_esp32 -e espidf_esp32_c3
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@
**/*.hex
**/memory_ram.txt
**/memory_program.txt

build/
src/main.cpp
src/main.c
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.rulers": [ 79 ]
}
79 changes: 52 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,63 @@ hal/newdev

**Note:** Use any of the other device support implementation of minbasecli_X.h/cpp files as example to edit.

2. Include new device support sources in "minbasecli.h" using an existing global define that allows to know wich device/framework is being compiled (this define should exists in some way in device framework, otherwise, you need to pass it to the compiler at build time, i.e. using -DMY_NEW_DEV for gcc compiler):
2. Include new device support sources in "minbasecli_hal_select.h" using an existing global define that allows to know which device/framework is being compiled (this define should exists in some way in device framework, otherwise, you need to pass it to the compiler at build time, i.e. using -DMY_NEW_DEV for gcc compiler):

```c++

/* ... */

/* Use Specific HAL for build system */

#if defined(__linux__)
#include "hal/linux/minbasecli_linux.h"
#define MINBASECLI_HAL MINBASECLI_LINUX
#elif defined(_WIN32) || defined(_WIN64)
#include "hal/windows/minbasecli_windows.h"
#define MINBASECLI_HAL MINBASECLI_WINDOWS
#elif defined(ARDUINO)
#include "hal/arduino/minbasecli_arduino.h"
#define MINBASECLI_HAL MINBASECLI_ARDUINO
#elif defined(__AVR)
#include "hal/avr/minbasecli_avr.h"
#define MINBASECLI_HAL MINBASECLI_AVR
#elif defined(ESP_PLATFORM)
#include "hal/espidf/minbasecli_espidf.h"
#define MINBASECLI_HAL MINBASECLI_ESPIDF
#elif defined(MY_NEW_DEV) // This has been include
#include "hal/newdev/minbasecli_newdev.h" // This has been include
#define MINBASECLI_HAL MINBASECLI_NEWDEV // This has been include
#else
#warning "minbasecli - Unsupported device/system."
#define HAL_NONE
#include "hal/none/minbasecli_none.h"
#define MINBASECLI_HAL MINBASECLI_NONE
#endif
/*****************************************************************************/

/* Hardware Abstraction Layer: NewDevice */

#elif defined(MY_NEW_DEV)

// Interface HAL Selection
#include "hal/newdev/minbasecli_newdev.h"
#define MINBASECLI_HAL MINBASECLI_NEWDEV

// Default CLI Baud Rate Speed to use if not provided
#if !defined(MINBASECLI_DEFAULT_BAUDS)
#define MINBASECLI_DEFAULT_BAUDS 115200
#endif

// Maximum CLI read buffer size
#if !defined(MINBASECLI_MAX_READ_SIZE)
#define MINBASECLI_MAX_READ_SIZE 64
#endif

// Maximum CLI Command length
#if !defined(MINBASECLI_MAX_CMD_LEN)
#define MINBASECLI_MAX_CMD_LEN 24
#endif

// Maximum CLI Command Argument length
#if !defined(MINBASECLI_MAX_ARGV_LEN)
#define MINBASECLI_MAX_ARGV_LEN 32
#endif

// Maximum number of arguments to check on a received CLI command
#if !defined(MINBASECLI_MAX_ARGV)
#define MINBASECLI_MAX_ARGV 4
#endif

// Maximum Print formatted number array size
#if !defined(MINBASECLI_MAX_PRINT_SIZE)
#define MINBASECLI_MAX_PRINT_SIZE 22
#endif

// Maximum number of commands that can be added to the CLI
#if !defined(MINBASECLI_MAX_CMD_TO_ADD)
#define MINBASECLI_MAX_CMD_TO_ADD 16
#endif

// Maximum length of command description text
#if !defined(MINBASECLI_MAX_CMD_DESCRIPTION)
#define MINBASECLI_MAX_CMD_DESCRIPTION 64
#endif

/*****************************************************************************/

/* ... */

Expand Down
24 changes: 16 additions & 8 deletions examples/arduino/basic_usage/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

[platformio]
default_envs = arduino_esp32 ; Build ESP32 with Arduino Framework
;default_envs = arduino_esp32_c3 ; Build ESP32-C3 with Arduino Framework
;default_envs = arduino_esp8266 ; Build ESP8266 with Arduino Framework
;default_envs = arduino_uno_atmega328 ; Build Arduino Uno with Arduino Framework
;default_envs = arduino_mega_atmega2560 ; Build Arduino Mega with Arduino Framework
Expand All @@ -19,51 +20,58 @@ default_envs = arduino_esp32 ; Build ESP32 with Arduino Framework
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

[env]
lib_deps = minbasecli@1.1.1
lib_deps = minbasecli

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; Arduino Build Configs

; ESP32 Arduino
[env:arduino_esp32]
platform = espressif32@3.5.0
platform = espressif32@5.0.0
board = esp32dev
framework = arduino

; ESP32-C3 Arduino
[env:arduino_esp32_c3]
platform = espressif32@5.0.0
board = esp32-c3-devkitm-1
framework = arduino
board_build.mcu = esp32c3

; ESP8266 Arduino
[env:arduino_esp8266]
platform = espressif8266@3.2.0
platform = espressif8266@4.0.1
board = esp12e
framework = arduino

; Arduino Uno (atmega328)
[env:arduino_uno_atmega328]
platform = atmelavr@3.3.0
platform = atmelavr@4.0.0
board = uno
framework = arduino

; Arduino Mega (atmega2560)
[env:arduino_mega_atmega2560]
platform = atmelavr@3.3.0
platform = atmelavr@4.0.0
board = megaatmega2560
framework = arduino

; Arduino Nano (atmega168)
[env:arduino_nano_atmega168]
platform = atmelavr@3.3.0
platform = atmelavr@4.0.0
board = nanoatmega168
framework = arduino

; Arduino Nano (atmega328)
[env:arduino_nano_atmega328]
platform = atmelavr@3.3.0
platform = atmelavr@4.0.0
board = nanoatmega328
framework = arduino

; Arduino Pro Micro (atmega32u4)
[env:arduino_micro_atmega32u4]
platform = atmelavr@3.3.0
platform = atmelavr@4.0.0
board = micro
framework = arduino
;build_flags = -DUSBCON=1
42 changes: 21 additions & 21 deletions examples/arduino/basic_usage/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* @file examples/arduino/basic_usage/basic_usage.ino
* @file examples/arduino/basic_usage/src/main.cpp
* @author Jose Miguel Rios Rubio <jrios.github@gmail.com>
* @date 02-04-2022
* @version 1.0.1
* @date 05-03-2023
* @version 1.0.3
*
* @section DESCRIPTION
*
Expand Down Expand Up @@ -75,7 +75,7 @@ void setup()
Serial.begin(SERIAL_BAUDS);

// CLI init to use Serial as interface
Cli.setup(&Serial);
Cli.setup(&Serial, SERIAL_BAUDS);
Cli.printf("\nCommand Line Interface is ready\n\n");
}

Expand All @@ -84,58 +84,58 @@ void loop()
t_cli_result cli_read;

// If any command was received
if(Cli.manage(&cli_read))
if (Cli.manage(&cli_read))
{
// Show read result element
Cli.printf("Command received: %s\n", cli_read.cmd);
Cli.printf("Number of arguments: %d\n", (int)(cli_read.argc));
for(int i = 0; i < cli_read.argc; i++)
Cli.printf(" Argument %d: %s", i, cli_read.argv[i]);
Cli.printf("Number of arguments: %d\n"), (int)(cli_read.argc);
for (int i = 0; i < cli_read.argc; i++)
{ Cli.printf(" Argument %d: %s", i, cli_read.argv[i]); }
Cli.printf("\n");

// Handle Commands
if(strcmp(cli_read.cmd, "help") == 0)
if (strcmp(cli_read.cmd, "help") == 0)
{
Cli.printf("Available Commands:\n");
Cli.printf(" help - Current info.\n");
Cli.printf(" led [on/off] - Turn LED ON or OFF\n");
Cli.printf(" version - Shows current firmware version\n");
Cli.printf(" led [on/off] - Turn LED ON or OFF.\n");
Cli.printf(" version - Shows current firmware version.\n");
}
else if(strcmp(cli_read.cmd, "led") == 0)
else if (strcmp(cli_read.cmd, "led") == 0)
{
bool invalid_argv = false;
char* led_mode = NULL;

// Check for argument
if(cli_read.argc == 0)
invalid_argv = true;
if (cli_read.argc == 0)
{ invalid_argv = true; }
else
{
led_mode = cli_read.argv[0];
if(strcmp(led_mode, "on") == 0)
if (strcmp(led_mode, "on") == 0)
{
Cli.printf("Turning LED ON.\n");
digitalWrite(COMMAND_LED, HIGH);
}
else if(strcmp(led_mode, "off") == 0)
else if (strcmp(led_mode, "off") == 0)
{
Cli.printf("Turning LED OFF.\n");
digitalWrite(COMMAND_LED, LOW);
}
else
invalid_argv = true;
{ invalid_argv = true; }
}

if(invalid_argv)
Cli.printf("led command needs \"on\" or \"off\" arg.\n");
if (invalid_argv)
{ Cli.printf("led command needs \"on\" or \"off\" arg.\n"); }
}
else if(strcmp(cli_read.cmd, "version") == 0)
else if (strcmp(cli_read.cmd, "version") == 0)
{
Cli.printf("FW App Version: %s\n", FW_APP_VERSION);
}
// ...
else
Cli.printf("Unkown command.\n");
{ Cli.printf("Unkown command.\n"); }
Cli.printf("\n");
}
}
5 changes: 5 additions & 0 deletions examples/arduino/basic_usage_callbacks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
Loading

0 comments on commit 3d06849

Please sign in to comment.