From a1a8a10223200cd260fa57ac9359764d03fd11e5 Mon Sep 17 00:00:00 2001 From: robert jakub Date: Fri, 1 Nov 2024 06:30:33 +0100 Subject: [PATCH] uconsole-4g-cm4 script --- uconsole/module-4g.nix | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 uconsole/module-4g.nix diff --git a/uconsole/module-4g.nix b/uconsole/module-4g.nix new file mode 100644 index 0000000..037d589 --- /dev/null +++ b/uconsole/module-4g.nix @@ -0,0 +1,57 @@ +{ + pkgs, + lib, + ... +}: let + inherit (lib) mkDefault; + rpi-utils = pkgs.callPackage ../raspberry-pi/packages/rpi-utils {}; + uconsole-4g-cm4 = pkgs.writeShellScriptBin "uconsole-4g-cm4" '' + function tip { + echo "use mmcli -L to see 4G modem or not" + } + + function enable4g { + echo "Power on 4G module on uConsole cm4" + ${rpi-utils}/bin/pinctrl set 24 op dh + ${rpi-utils}/bin/pinctrl set 15 op dh + ${pkgs.coreutils}/bin/sleep 5 + ${rpi-utils}/bin/pinctrl set 15 dl + echo "waiting..." + ${pkgs.coreutils}/bin/sleep 13 + echo "done" + } + + function disable4g { + echo "Power off 4G module" + ${rpi-utils}/bin/pinctrl set 24 op dl + ${rpi-utils}/bin/pinctrl set 24 dh + ${pkgs.coreutils}/bin/sleep 3 + ${rpi-utils}/bin/pinctrl set 24 dl + ${pkgs.coreutils}/bin/sleep 20 + echo "Done" + } + + if [ "$#" -ne 1 ] ; then + echo "$0: enable/disable" + exit 3 + fi + + if [ $1 == "enable" ]; then + enable4g; + tip; + fi + + if [ $1 == "disable" ]; then + disable4g + tip; + fi + ''; +in { + config = { + environment.systemPackages = [ + rpi-utils + uconsole-4g-cm4 + # pkgs.modemmanager + ]; + }; +}