From 36fda4825087f02ba5ceed33b43b75526b469be8 Mon Sep 17 00:00:00 2001 From: arfrie22 <43021241+arfrie22@users.noreply.github.com> Date: Mon, 5 Aug 2024 15:16:48 -0400 Subject: [PATCH] change build script not to override i2c --- build.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/build.sh b/build.sh index b9f01ce3..e17439e6 100755 --- a/build.sh +++ b/build.sh @@ -3,13 +3,15 @@ set -e function enable_i2c { if command -v raspi-config &> /dev/null; then + if [[ $(sudo raspi-config nonint get_i2c) -eq 1 ]] ; then echo "Enabling i2c" sudo modprobe i2c-dev sudo raspi-config nonint do_i2c 0 - if [[ ! -z $(grep 'dtparam=i2c_arm=on$' /boot/config.txt) ]] ; then - echo "Setting the i2c clock speed to 400 kHz, you will have to reboot for this to take effect." - sudo sed -i -e 's/dtparam=i2c_arm=on$/dtparam=i2c_arm=on,i2c_arm_baudrate=400000/g' /boot/config.txt - fi + fi + if [[ $(grep -c '^dtparam=i2c_arm=on$' /boot/config.txt) -ge 1 ]] ; then + echo "Setting the i2c clock speed to 400 kHz, you will have to reboot for this to take effect." + sudo sed -i -e 's/dtparam=i2c_arm=on$/dtparam=i2c_arm=on,i2c_arm_baudrate=400000/g' /boot/config.txt + fi else echo "Can not automatically enable i2c you might have to do this manually" fi