#!/bin/bash DIALOG_CANCEL=1 DIALOG_ESC=255 HEIGHT=-1 WIDTH=-1 # Choices PLATTFORM=nrf52840dongle_nrf52840 CONNECTIVITY= INTERFACES= PROTOCOLS= SENSORS= ACTUATORS= display_result() { dialog --title "$1" \ --backtitle "Configure Zephyr RTOS" \ --no-collapse \ --msgbox "$2" -1 -1 } main_dialog() { selection=$(dialog --stdout \ --backtitle "Configure Zephyr RTOS" \ --title "Menu" \ --no-cancel \ --menu "Please select:" $HEIGHT $WIDTH 4 \ "1" "Init Zephyr workspace" \ "2" "Create empty project" \ "3" "Add additional functionalities" \ "4" "Build project" \ "5" "Flash project" \ "6" "Clean build directory" \ "7" "Exit") case $selection in 1 ) init_workspace ;; 2 ) init_project ;; 3 ) settings_dialog ;; 4 ) build_project ;; 5 ) flash_project ;; 6 ) clean_build_dir ;; 7 ) clear exit ;; esac } settings_dialog() { selection=$(dialog --stdout \ --backtitle "Configure Zephyr RTOS" \ --title "Menu" \ --cancel-label "Exit" \ --menu "Please select:" $HEIGHT $WIDTH 4 \ "1" "Connectivity" \ "2" "Protocols" \ "3" "Interfaces" \ "4" "Sensors" \ "5" "Actuators" ) case $selection in 1 ) connectivity_dialog ;; 2 ) protocols_dialog ;; 3 ) interfaces_dialog ;; 4 ) sensors_dialog ;; 5 ) actuators_dialog ;; esac } plattform_dialog() { plattform=$( dialog --stdout \ --backtitle "Plattform" \ --default-item "$PLATTFORM" \ --no-tags \ --no-cancel \ --radiolist "Select plattform:" $HEIGHT $WIDTH 4 \ esp32c3_devkitm "ESP32-C3" $(equals "$PLATTFORM" "esp32c3_devkitm") \ nrf5340dk_nrf5340_cpuapp "nRF5340 DK" $(equals "$PLATTFORM" "nrf5340dk_nrf5340_cpuapp") \ nrf52840dongle_nrf52840 "nRF52840 Dongle" $(equals "$PLATTFORM" "nrf52840dongle_nrf52840") \ thingy91_nrf9160_ns "Thingy:91 (nRF9160)" $(equals "$PLATTFORM" "thingy91_nrf9160_ns") \ thingy91_nrf52840 "Thingy:91 (nRF52840)" $(equals "$PLATTFORM" "thingy91_nrf52840") ) if [ ! -z "$plattform" ]; then PLATTFORM=$plattform fi } connectivity_dialog() { connectivity=$( dialog --stdout \ --backtitle "Connectivity" \ --checklist "Select connectivity:" $HEIGHT $WIDTH 4 \ 1 "WiFi" $(in_array "$CONNECTIVITY" 1) \ 2 "Bluetooth" $(in_array "$CONNECTIVITY" 2) \ 3 "LoRaWAN" $(in_array "$CONNECTIVITY" 3) \ 4 "NB-IoT" $(in_array "$CONNECTIVITY" 4) ) if [ ! -z "$connectivity" ]; then CONNECTIVITY=$connectivity fi } protocols_dialog() { protocols=$( dialog --stdout \ --backtitle "Protocols" \ --checklist "Select protocols:" $HEIGHT $WIDTH 4 \ 1 "MQTT" $(in_array "$PROTOCOLS" 1) \ 2 "REST" $(in_array "$PROTOCOLS" 2) \ 3 "CoAP" $(in_array "$PROTOCOLS" 3) ) if [ ! -z "$protocols" ]; then PROTOCOLS=$protocols fi } interfaces_dialog() { interfaces=$( dialog --stdout \ --backtitle "Interfaces" \ --checklist "Select interfaces:" $HEIGHT $WIDTH 4 \ 1 "I2C" $(in_array "$INTERFACES" 1) \ 2 "SPI" $(in_array "$INTERFACES" 2) \ 3 "UART" $(in_array "$INTERFACES" 3) ) if [ ! -z "$interfaces" ]; then INTERFACES=$interfaces fi } sensors_dialog() { sensors=$( dialog --stdout \ --backtitle "Sensors" \ --checklist "Select sensors:" $HEIGHT $WIDTH 4 \ 1 "Sensor 1" $(in_array "$SENSORS" 1) \ 2 "Sensor 2" $(in_array "$SENSORS" 2) \ 3 "Sensor 3" $(in_array "$SENSORS" 3) \ 4 "Sensor 4" $(in_array "$SENSORS" 4) ) if [ ! -z "$sensors" ]; then SENSORS=$sensors fi } actuators_dialog() { actuators=$( dialog --stdout \ --backtitle "Actuators" \ --checklist "Select actuators:" $HEIGHT $WIDTH 4 \ 1 "Actuators 1" $(in_array "$ACTUATORS" 1) \ 2 "Actuators 2" $(in_array "$ACTUATORS" 2) \ 3 "Actuators 3" $(in_array "$ACTUATORS" 3) \ 4 "Actuators 4" $(in_array "$ACTUATORS" 4) ) if [ ! -z "$actuators" ]; then ACTUATORS=$actuators fi } init_workspace() { cd /workdir { west init; west update; west zephyr-export; echo "Created workspace successfully"; } 2>&1 | dialog --programbox -1 -1 } init_project() { mkdir /workdir/app mkdir /workdir/app/src cp /opt/data/main.c /workdir/app/src/main.c cp /opt/data/app.overlay /workdir/app/app.overlay cp /opt/data/CMakeLists.txt /workdir/app/CMakeLists.txt cp /opt/data/prj.conf /workdir/app/prj.conf cp /opt/data/VERSION /workdir/app/VERSION display_result 'Created project' "Project created successfully.\nThe project is located in /workdir.\nYou can edit it by using your favorite IDE." } build_project() { plattform_dialog { cd /workdir/app/; west build -b $PLATTFORM; } 2>&1 | dialog --programbox -1 -1 } flash_project() { plattform_dialog case "$PLATTFORM" in "nrf52840dongle_nrf52840") display_result 'Flash project' "Please run those commands in an environment where nrfutil and the compiled hex files are available:\\n\\n\\nnrfutil pkg generate --hw-version 52 --sd-req=0x00 --application build/zephyr/zephyr.hex --application-version 1 mcuboot.zip\\n\\nnrfutil dfu usb-serial -pkg mcuboot.zip -p /dev/ttyACM0" ;; *) display_result "Error" "Board not configured in this tool yet\nSee https://docs.zephyrproject.org/latest/boards/index.html#boards" ;; esac } clean_build_dir() { rm -rf /workdir/app/build/* display_result "Cleaned build" "Cleaned build directory successfully" } in_array() { if [[ $1 =~ (^|[[:space:]])"$2"($|[[:space:]]) ]] ; then echo on; else echo off; fi } equals() { if [[ $1 == "$2" ]] ; then echo on; else echo off; fi } if ! command -v dialog &> /dev/null then sudo apt update && sudo apt install dialog fi while true; do main_dialog done