Skip to content

Commit

Permalink
Added message on how to exit monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
robdobsn committed Feb 15, 2024
1 parent 74fe93f commit bed2376
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "raftcli"
version = "1.0.0"
version = "1.0.1"
authors = ["Rob Dobson <[email protected]>"]
license = "MIT"
keywords = ["cli", "esp32", "espressif", "raft", "framework"]
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Options:
-h, --help Print help
```

To exit the app press ESC

## Installation

You can either install this app from the crates.io package registry (which is part of the Rust ecosystem) or build from source code.
Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
[] possibly include size of flash as a user input - issues with this are different flash types such as OCTAL in addition to size
[] fix problem invalid string ... thread 'tokio-runtime-worker' panicked at src/serial_monitor.rs:179:68: Failed to read from RX stream: Custom { kind: Other, error: "Invalid String" }
[] add monitor as option in Makefile?
[] bug noticed on Mac with invalid chars immediately after boot
35 changes: 31 additions & 4 deletions raft_templates/Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
# Build Project
DOCKER ?= 1
WSL ?= $(if $(findstring Windows_NT,$(OS)),1,0)

# Detect whether the OS is Windows Subsystem for Linux (WSL)
ifeq ($(OS),Windows_NT)
WSL ?= 0
else
WSL ?= $(shell uname -r | grep -i microsoft > /dev/null && echo 1 || echo 0)
endif

# Set the ESP IDF version
ESP_IDF_PATH ?= ~/esp/esp-idf-v{{esp_idf_version}}

# Set the build base folders
BUILD_BASE_FOLDER ?= build
BUILD_CONFIG_BASE_DIR = systypes
BUILD_RAFT_ARTEFACTS_DIR ?= build_raft_artefacts

# Set the SysType
SYSTYPE ?= $(notdir $(firstword $(filter-out $(BUILD_CONFIG_BASE_DIR)/Common, $(wildcard $(BUILD_CONFIG_BASE_DIR)/*))))

# Set the build configuration folders based on the SysType
BUILD_CONFIG_DIR = $(BUILD_CONFIG_BASE_DIR)/$(SYSTYPE)
COMMON_CONFIG_DIR = $(BUILD_CONFIG_BASE_DIR)/Common
BUILD_RAFT_ARTEFACTS_DIR ?= build_raft_artefacts

# Set the build directory
BUILD_DIR = $(BUILD_BASE_FOLDER)/$(SYSTYPE)
ROOTDIR = $(realpath $(CURDIR))

# Set the sdkconfig files
SDKCONFIG_DEFAULTS_FILE ?= $(BUILD_CONFIG_DIR)/sdkconfig.defaults
SDKCONFIG_FILE ?= $(BUILD_RAFT_ARTEFACTS_DIR)/sdkconfig

# Set the target binary
TARGET_BINARY = $(BUILD_DIR)/$(SYSTYPE).bin
# DOCKER_EXEC ?= docker run --rm -v $(ROOTDIR):/project -w /project espressif/idf:v5.1.2

# Set the build commands
DOCKER_EXEC = docker build -t raftbuilder . && docker run --rm -v $(ROOTDIR):/project -w /project raftbuilder
LOCAL_EXEC = . $(ESP_IDF_PATH)/export.sh
CMD ?= idf.py -B $(BUILD_DIR) build

# Prepare build commands depending on the OS
ifeq ($(WSL),1)
SERIAL_MONITOR ?= raft.exe monitor
PYTHON_FOR_FLASH ?= python.exe
Expand Down Expand Up @@ -45,18 +67,22 @@ BUILD_TARGET=\
$(LOCAL_EXEC) && $(CMD)
endif

# Default target
all: build

# Dependencies of target binary
$(TARGET_BINARY): $(wildcard $(BUILD_CONFIG_DIR)/*) $(wildcard $(COMMON_CONFIG_DIR)/*) $(wildcard $(COMMON_CONFIG_DIR)/FSImage/*) $(wildcard $(COMMON_CONFIG_DIR)/WebUI*)
@$(DELETE_BUILD_FOLDERS)

# Clean the build
clean:
@$(DELETE_BUILD_FOLDERS)

# Build the project
build: $(TARGET_BINARY)
@$(BUILD_TARGET)

# Flash the project
ifneq ($(SERIAL_MONITOR),)
flash: build
@$(PYTHON_FOR_FLASH) $(BUILD_DIR)/_deps/raftcore-src/scripts/flashUsingPartitionCSV.py $(BUILD_RAFT_ARTEFACTS_DIR)/partitions.csv $(BUILD_DIR) $(SYSTYPE).bin $(PORT) -s $(SDKCONFIG_FILE) -f fs.bin
Expand All @@ -66,4 +92,5 @@ flash: build
@$(PYTHON_FOR_FLASH) $(BUILD_DIR)/_deps/raftcore-src/scripts/flashUsingPartitionCSV.py $(BUILD_RAFT_ARTEFACTS_DIR)/partitions.csv $(BUILD_DIR) $(SYSTYPE).bin $(PORT) -s $(SDKCONFIG_FILE) -f fs.bin
endif

.PHONY: build clean flash test
# Phony targets to avoid name clashes with files
.PHONY: build clean flash test
9 changes: 8 additions & 1 deletion src/serial_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ pub async fn start(port: String, baud: u32, log: bool, log_folder: String) -> to
// Clone the log file for use in the serial_rx task
let log_file_clone = log_file.clone();

// Write welcome message to the termainal
println!("Raft Serial Monitor - press Esc (or Ctrl+X) to exit");

// Create a separate task to read from the serial port and send to the terminal
tokio::spawn(async move {
loop {
Expand Down Expand Up @@ -241,11 +244,15 @@ pub async fn start(port: String, baud: u32, log: bool, log_folder: String) -> to

// Handle key press
match key.code {
// Break out of the serial monitor on Esc key
// Break out of the serial monitor on Esc key or Ctrl+X
KeyCode::Esc => {
let _ = oneshot_exit_send.send(());
break;
},
KeyCode::Char('x') if key.modifiers == crossterm::event::KeyModifiers::CONTROL => {
let _ = oneshot_exit_send.send(());
break;
},
// Check for Enter key and send the user input buffer
KeyCode::Enter => {
// Clear the user input display line before sending.
Expand Down

0 comments on commit bed2376

Please sign in to comment.