mirror of
https://github.com/femtofox/femtofox.git
synced 2026-11-22 07:56:35 -05:00
Add meshtastic i2c support to menus.
This commit is contained in:
parent
97ba36396b
commit
8e4895320e
3 changed files with 67 additions and 8 deletions
|
|
@ -433,10 +433,11 @@ meshtastic_settings() {
|
|||
4 "Security settings" "" \
|
||||
5 "Mesh connectivity test" "" \
|
||||
6 "Manage Meshtasticd service" "" \
|
||||
7 "Upgrade/install Meshtasticd" "" \
|
||||
8 "Uninstall Meshtasticd" "" \
|
||||
7 "Enable/disable i2c devices" "" \
|
||||
8 "Upgrade/install Meshtasticd" "" \
|
||||
9 "Uninstall Meshtasticd" "" \
|
||||
" " "" "" \
|
||||
9 "Back to main menu" "" 3>&1 1>&2 2>&3)
|
||||
10 "Back to main menu" "" 3>&1 1>&2 2>&3)
|
||||
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
|
||||
case $meshtastic_choice in
|
||||
1) # view node info)
|
||||
|
|
@ -593,21 +594,48 @@ meshtastic_settings() {
|
|||
esac
|
||||
done
|
||||
;;
|
||||
7) #Upgrade meshtasticd)
|
||||
7) #i2c)
|
||||
choice="" # zero the choice before loading the submenu
|
||||
while true; do
|
||||
i2c_state=$(femto-utils.sh -R "$(femto-meshtasticd-config.sh -I check)")
|
||||
choice=$(dialog --no-collapse --colors --cancel-label "Back" --title "Meshtastic i2c" --default-item "$choice" --menu "i2c is used for sensors and displays.\nCurrently \Zu$i2c_state." 12 42 5 \
|
||||
$(if echo "$i2c_state" | grep -q 'disabled'; then echo "Enable i2c x"; fi) \
|
||||
$(if echo "$i2c_state" | grep -q 'enabled'; then echo "Disable i2c x"; fi) \
|
||||
" " "" \
|
||||
"Back" "x" 3>&1 1>&2 2>&3)
|
||||
[ $? -eq 1 ] && break # Exit the loop if the user selects "Cancel" or closes the dialog
|
||||
case $choice in
|
||||
"Enable i2c")
|
||||
dialog --no-collapse --colors --title "$title" --yesno "Enable i2c?\n\nEnabling i2c without devices connected will lead to slowdowns and error messages." 9 47
|
||||
if [ $? -eq 0 ]; then #unless cancel/no
|
||||
femto-meshtasticd-config.sh -I enable
|
||||
fi
|
||||
;;
|
||||
"Disable i2c")
|
||||
dialog --no-collapse --colors --title "$title" --yesno "Disable i2c?\n\nDisabling i2c will only apply to Meshtastic, not to Foxbuntu." 9 50
|
||||
if [ $? -eq 0 ]; then #unless cancel/no
|
||||
femto-meshtasticd-config.sh -I disable
|
||||
fi
|
||||
;;
|
||||
"Back") break ;;
|
||||
esac
|
||||
done
|
||||
;;
|
||||
8) #Upgrade meshtasticd)
|
||||
dialog --no-collapse --title "$title" --yesno "Upgrade Meshtasticd?\nRequires internet connection." 0 0
|
||||
if [ $? -eq 0 ]; then #unless cancel/no
|
||||
femto-meshtasticd-config.sh -z
|
||||
pause
|
||||
fi
|
||||
;;
|
||||
8) #uninstall meshtasticd)
|
||||
9) #uninstall meshtasticd)
|
||||
dialog --no-collapse --colors --title "$title" --yesno "Uninstall Meshtasticd?\n\nFoxbuntu was designed with Meshtasticd integration in mind, and may behave unexpectedly if Meshtasticd is removed.\n\nThis will take the node \Zu\Z1OFFLINE\Zn and will not restart!" 0 0
|
||||
if [ $? -eq 0 ]; then
|
||||
femto-meshtasticd-config.sh -x
|
||||
dialog --no-collapse --colors --msgbox "Meshtasticd uninstalled. To purge all remnants, run \`\Zusudo apt purge\Zn\`." 8 40
|
||||
fi
|
||||
;;
|
||||
9)
|
||||
10)
|
||||
return
|
||||
;;
|
||||
esac
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ Options are:
|
|||
-t Stop Meshtasticd service
|
||||
-M "enable" Enable/disable Meshtasticd service. Options: "enable" "disable"
|
||||
-S Get Meshtasticd service state
|
||||
-I "enable" Manage i2c state. Options: "enable" "disable" "check"
|
||||
-z Upgrade Meshtasticd
|
||||
-x Uninstall Meshtasticd
|
||||
-m Meshtastic update tool. Syntax: \`femto-meshtasticd-config.sh -m \"--set security.admin_channel_enabled false\" 10 \"Disable legacy admin\"\`
|
||||
|
|
@ -186,7 +187,7 @@ get_meshtastic_settings() {
|
|||
}
|
||||
|
||||
# Parse options
|
||||
while getopts ":hiC:gkl:q:uU:rR:aA:cpo:sM:Stwuxm" opt; do
|
||||
while getopts ":hiC:gkl:q:uU:rR:aA:cpo:sM:StI:wuxm" opt; do
|
||||
case ${opt} in
|
||||
h) # Option -h (help)
|
||||
echo -e "$help"
|
||||
|
|
@ -326,6 +327,26 @@ Nodes in db:$metadata_nodedbCount"
|
|||
systemctl stop meshtasticd
|
||||
echo "Meshtasticd service stopped."
|
||||
;;
|
||||
I) # Option -I (Manage i2c state. Options: "enable" "disable" "check")
|
||||
yaml_file="/etc/meshtasticd/config.d/femto_config.yaml"
|
||||
if [ "$OPTARG" = "enable" ]; then
|
||||
echo -e "\nI2C:\n I2CDevice: /dev/i2c-3" >> $yaml_file
|
||||
femto-meshtasticd-config.sh -s
|
||||
elif [ "$OPTARG" = "disable" ]; then
|
||||
sed -i '/I2C:/,/I2CDevice: \/dev\/i2c-3/d' $yaml_file
|
||||
femto-meshtasticd-config.sh -s
|
||||
elif [ "$OPTARG" = "check" ]; then
|
||||
if grep -q "I2C:" $yaml_file && grep -q "I2CDevice: /dev/i2c-3" $yaml_file; then
|
||||
echo -e "\033[0;34menabled\033[0m"
|
||||
else
|
||||
echo -e "\033[0;31mdisabled\033[0m"
|
||||
fi
|
||||
else
|
||||
echo "Invalid argument \`-I $OPTARG\`. Options are \`enable\` \`disable\` \`check\`."
|
||||
echo -e "$help"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
z) # Option -z (upgrade meshtasticd)
|
||||
apt update
|
||||
apt install --only-upgrade meshtasticd
|
||||
|
|
|
|||
|
|
@ -118,6 +118,8 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
|
|||
wifi_command="femto-network-config.sh"
|
||||
meshtastic_security_command="femto-meshtasticd-config.sh"
|
||||
dont_run_if_log_exists=""
|
||||
software_install=""
|
||||
meshtastic_i2c=""
|
||||
|
||||
# Escape and read the fields from the USB config file if they exist
|
||||
while IFS='=' read -r key value; do
|
||||
|
|
@ -140,8 +142,9 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
|
|||
meshtastic_admin_key) meshtastic_admin_key=$(escape_sed "$value") ;;
|
||||
dont_run_if_log_exists) dont_run_if_log_exists=$(escape_sed "$value") ;;
|
||||
software_install) software_install=$(escape_sed "$value") ;;
|
||||
meshtastic_i2c) meshtastic_i2c=$(escape_sed "$value") ;;
|
||||
esac
|
||||
done < <(grep -E '^(act_led|wifi_ssid|wifi_psk|wifi_country|meshtastic_lora_radio|timezone|meshtastic_url|meshtastic_legacy_admin|meshtastic_public_key|meshtastic_private_key|meshtastic_admin_key|dont_run_if_log_exists|software_install)=' "$usb_config")
|
||||
done < <(grep -E '^(act_led|wifi_ssid|wifi_psk|wifi_country|meshtastic_lora_radio|timezone|meshtastic_url|meshtastic_legacy_admin|meshtastic_public_key|meshtastic_private_key|meshtastic_admin_key|dont_run_if_log_exists|software_install|meshtastic_i2c)=' "$usb_config")
|
||||
|
||||
# Check if the log exits and if the dont_run_if_log_exists line is set in the script
|
||||
if $log_exists && [[ $dont_run_if_log_exists = "true" ]]; then
|
||||
|
|
@ -339,6 +342,13 @@ if [ -f "$mount_point/femtofox-config.txt" ]; then
|
|||
fi
|
||||
done
|
||||
|
||||
if [[ -n "$meshtastic_i2c" ]]; then # set meshtastic i2c state
|
||||
femto-meshtasticd-config.sh -I $meshtastic_i2c 2>&1 | tee -a /tmp/femtofox-config.log
|
||||
log_message "Set Meshtastic i2c state to \`$meshtastic_i2c\`."
|
||||
found_config="true"
|
||||
fi
|
||||
|
||||
|
||||
if [ "$found_config" = true ]; then #if we found a config file containing valid data
|
||||
|
||||
if [ "$meshtastic_url" != "" ]; then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue