Skip to content

Instantly share code, notes, and snippets.

@nrobinson2000
Last active September 29, 2017 07:56
Show Gist options
  • Select an option

  • Save nrobinson2000/6be1dbf6ef77bb947e42 to your computer and use it in GitHub Desktop.

Select an option

Save nrobinson2000/6be1dbf6ef77bb947e42 to your computer and use it in GitHub Desktop.

Revisions

  1. nrobinson2000 revised this gist Apr 23, 2016. 2 changed files with 10 additions and 196 deletions.
    196 changes: 0 additions & 196 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -1,196 +0,0 @@
    #!/bin/bash
    # Particle Offline Utility

    if [ "$1" == "help" ];
    then
    echo " po-util 1.1
    To install dependencies run \"po-util install\"
    To correctly format a project folder run \"po-util init\"
    To build a binary run \"po-util DEVICE build\", with DEVICE as either \"photon\"
    or \"electron\"
    To build a binary and upload (flash) to the connected device using dfu-util
    run \"po-util DEVICE flash\"
    If you need to reset the build directory run \"po-util DEVICE clean\"
    Summary: Code in the firmware/ directory is compiled and saved as a binary.
    The binary can be flashed to a connected device over dfu-util."
    exit
    fi

    if [ "$(uname -s)" == "Darwin" ];
    then
    modem=`ls -1 /dev/cu.* | grep -vi bluetooth | tail -1`
    fi

    CWD=$(pwd)

    if [ "$1" == "install" ];
    then
    mkdir ~/github
    cd ~/github
    git clone https://github.com/spark/firmware.git
    if [ "$(uname -s)" == "Linux" ];
    then
    cd ~/github || exit
    # Install dependencies
    echo "installing dependencies..."
    curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
    sudo apt-get remove -y node modemmanager gcc-arm-none-eabi
    sudo apt-get install -y nodejs python-software-properties python g++ make build-essential libusb-1.0-0-dev
    # Install dfu-util
    wget "https://sourceforge.net/projects/dfu-util/files/dfu-util-0.9.tar.gz/download"
    tar -xzvf download
    rm download
    cd dfu-util-0.9 || exit
    ./configure
    make
    sudo make install
    cd ..
    rm -rf dfu-util-0.9
    # Install gcc-arm-embedded
    sudo apt-add-repository ppa:terry.guo/gcc-arm-embedded
    sudo apt-get update
    sudo apt-get install gcc-arm-none-eabi
    # clone firmware repository
    cd ~/github || exit
    git clone https://github.com/spark/firmware.git
    # install particle-cli
    sudo npm install -g node-pre-gyp npm
    sudo npm install -g particle-cli
    # create udev rules file
    wget https://gist.github.com/monkbroc/b283bb4da8c10228a61e/raw/e59c77021b460748a9c80ef6a3d62e17f5947be1/50-particle.rules
    sudo mv 50-particle.rules /etc/udev/rules.d/50-particle.rules
    fi
    if [ "$(uname -s)" == "Darwin" ];
    then
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    brew tap PX4/homebrew-px4
    brew update
    brew install gcc-arm-none-eabi-49 dfu-util wget
    wget https://nodejs.org/dist/v5.8.0/node-v5.8.0.pkg
    sudo installer -pkg node-v5.8.0.pkg -target /
    rm node-v5.8.0.pkg
    sudo npm install -g node-pre-gyp npm
    sudo npm install -g particle-cli
    fi
    echo "Sucessfully Installed!" && exit
    fi


    if [ "$1" == "init" ];
    then
    mkdir firmware/
    cp *.cpp firmware/
    cp *.h firmware/
    ls firmware/ | grep -v "particle.include" | cat > firmware/particle.include
    echo "Copied c++ files into firmware directory. Setup complete."
    exit
    fi

    if [ -d "firmware" ];
    then echo
    else echo "Please run with \"init\" to setup this project directory." && exit
    fi

    if [ "$1" == "dfu" ];
    then
    if [ "$(uname -s)" == "Darwin" ];
    then
    stty -f $modem 19200
    sleep 1
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"
    exit
    else
    stty -F /dev/ttyACM0 19200
    sleep 1
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"
    exit
    fi
    fi

    if [ "$1" == "dfu-open" ];
    then
    if [ "$(uname -s)" == "Darwin" ];
    then
    stty -f $modem 19200
    exit
    else
    stty -F /dev/ttyACM0 19200
    exit
    fi
    fi

    if [ "$1" == "dfu-close" ];
    then
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D /dev/null
    exit
    fi

    if [ "$1" == "photon" ] || [ "$1" == "electron" ];
    then echo "$1 selected."
    else echo "Please select photon or electron. Try \"po-util help\" for help." && exit
    fi


    cd ~/github/firmware || exit

    if [ "$1" == "photon" ];
    then git checkout release/v0.5.0
    fi

    if [ "$1" == "electron" ];
    then git checkout release/v0.5.0
    fi

    if [ "$2" == "patch" ];
    then
    cd "$CWD"
    sed '2s/.*/START_DFU_FLASHER_SERIAL_SPEED=19200/' ~/github/firmware/build/module-defaults.mk > temp
    rm -f ~/github/firmware/build/module-defaults.mk
    mv temp ~/github/firmware/build/module-defaults.mk

    cd ~/github/firmware/modules/"$1"/system-part1
    make clean all PLATFORM="$1" program-dfu

    cd ~/github/firmware/modules/"$1"/system-part2
    make clean all PLATFORM="$1" program-dfu
    sleep 1
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D /dev/null
    exit
    fi


    if [ "$2" == "update" ];
    then git pull
    fi

    if [ "$2" == "clean" ];
    then make clean
    fi

    if [ "$2" == "ota" ];
    then
    particle flash "$3" "$CWD/bin/firmware.bin"
    fi

    if [ "$2" == "build" ];
    then make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    echo "Binary saved to $CWD/bin/firmware.bin"
    fi

    if [ "$2" == "flash" ];
    then
    if [ "$(uname -s)" == "Darwin" ];
    then
    stty -f $modem 19200
    make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1" || exit
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

    else
    stty -F /dev/ttyACM0 19200
    make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1" || exit
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

    fi
    fi
    10 changes: 10 additions & 0 deletions update.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    # UPDATE: [![Build Status](https://travis-ci.org/nrobinson2000/po-util.svg?branch=master)](https://travis-ci.org/nrobinson2000/po-util)

    [I have moved this script over from a gist to a repository.](https://github.com/nrobinson2000/po-util)

    I have also made it super easy to install this utility:
    ```
    curl -fsSL https://git.io/vwRRf | bash
    ```
    Additional functions have also been added, including OTA flashing and manual DFU control.
    Find out more in the repository, https://github.com/nrobinson2000/po-util
  2. nrobinson2000 revised this gist Apr 22, 2016. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -136,11 +136,11 @@ fi
    cd ~/github/firmware || exit

    if [ "$1" == "photon" ];
    then git checkout latest
    then git checkout release/v0.5.0
    fi

    if [ "$1" == "electron" ];
    then git checkout latest
    then git checkout release/v0.5.0
    fi

    if [ "$2" == "patch" ];
  3. nrobinson2000 revised this gist Apr 22, 2016. 1 changed file with 17 additions and 1 deletion.
    18 changes: 17 additions & 1 deletion po-util.sh
    Original file line number Diff line number Diff line change
    @@ -101,14 +101,30 @@ stty -f $modem 19200
    sleep 1
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"
    exit

    else
    stty -F /dev/ttyACM0 19200
    sleep 1
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"
    exit
    fi
    fi

    if [ "$1" == "dfu-open" ];
    then
    if [ "$(uname -s)" == "Darwin" ];
    then
    stty -f $modem 19200
    exit
    else
    stty -F /dev/ttyACM0 19200
    exit
    fi
    fi

    if [ "$1" == "dfu-close" ];
    then
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D /dev/null
    exit
    fi

    if [ "$1" == "photon" ] || [ "$1" == "electron" ];
  4. nrobinson2000 revised this gist Apr 3, 2016. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -124,7 +124,7 @@ then git checkout latest
    fi

    if [ "$1" == "electron" ];
    then git checkout prereleases/electron-v0.4.8-rc.6
    then git checkout latest
    fi

    if [ "$2" == "patch" ];
    @@ -134,11 +134,11 @@ sed '2s/.*/START_DFU_FLASHER_SERIAL_SPEED=19200/' ~/github/firmware/build/module
    rm -f ~/github/firmware/build/module-defaults.mk
    mv temp ~/github/firmware/build/module-defaults.mk

    cd ~/github/firmware/modules/photon/system-part1
    make clean all PLATFORM="photon" program-dfu
    cd ~/github/firmware/modules/"$1"/system-part1
    make clean all PLATFORM="$1" program-dfu

    cd ~/github/firmware/modules/photon/system-part2
    make clean all PLATFORM="photon" program-dfu
    cd ~/github/firmware/modules/"$1"/system-part2
    make clean all PLATFORM="$1" program-dfu
    sleep 1
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D /dev/null
    exit
    @@ -159,7 +159,7 @@ particle flash "$3" "$CWD/bin/firmware.bin"
    fi

    if [ "$2" == "build" ];
    then make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1" || exit
    then make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    echo "Binary saved to $CWD/bin/firmware.bin"
    fi

    @@ -177,4 +177,4 @@ make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PL
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

    fi
    fi
    fi
  5. nrobinson2000 revised this gist Apr 2, 2016. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -159,7 +159,7 @@ particle flash "$3" "$CWD/bin/firmware.bin"
    fi

    if [ "$2" == "build" ];
    then make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    then make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1" || exit
    echo "Binary saved to $CWD/bin/firmware.bin"
    fi

    @@ -168,12 +168,12 @@ then
    if [ "$(uname -s)" == "Darwin" ];
    then
    stty -f $modem 19200
    make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1" || exit
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

    else
    stty -F /dev/ttyACM0 19200
    make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1" || exit
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

    fi
  6. nrobinson2000 revised this gist Apr 1, 2016. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -139,6 +139,8 @@ make clean all PLATFORM="photon" program-dfu

    cd ~/github/firmware/modules/photon/system-part2
    make clean all PLATFORM="photon" program-dfu
    sleep 1
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D /dev/null
    exit
    fi

  7. nrobinson2000 revised this gist Apr 1, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion po-util.sh
    Original file line number Diff line number Diff line change
    @@ -137,7 +137,7 @@ mv temp ~/github/firmware/build/module-defaults.mk
    cd ~/github/firmware/modules/photon/system-part1
    make clean all PLATFORM="photon" program-dfu

    cd ~/github/firmware/modules/photon/system-part1
    cd ~/github/firmware/modules/photon/system-part2
    make clean all PLATFORM="photon" program-dfu
    exit
    fi
  8. nrobinson2000 revised this gist Apr 1, 2016. No changes.
  9. nrobinson2000 revised this gist Apr 1, 2016. No changes.
  10. nrobinson2000 revised this gist Apr 1, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion po-util.sh
    Original file line number Diff line number Diff line change
    @@ -139,7 +139,7 @@ make clean all PLATFORM="photon" program-dfu

    cd ~/github/firmware/modules/photon/system-part1
    make clean all PLATFORM="photon" program-dfu

    exit
    fi


  11. nrobinson2000 revised this gist Mar 31, 2016. 1 changed file with 27 additions and 19 deletions.
    46 changes: 27 additions & 19 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,6 @@
    #!/bin/bash
    # Particle Offline Utility

    if [ "$1" == "help" ];
    then
    echo " po-util 1.1
    @@ -17,6 +18,11 @@ Summary: Code in the firmware/ directory is compiled and saved as a binary.
    exit
    fi

    if [ "$(uname -s)" == "Darwin" ];
    then
    modem=`ls -1 /dev/cu.* | grep -vi bluetooth | tail -1`
    fi

    CWD=$(pwd)

    if [ "$1" == "install" ];
    @@ -56,7 +62,6 @@ sudo npm install -g particle-cli
    wget https://gist.github.com/monkbroc/b283bb4da8c10228a61e/raw/e59c77021b460748a9c80ef6a3d62e17f5947be1/50-particle.rules
    sudo mv 50-particle.rules /etc/udev/rules.d/50-particle.rules
    fi

    if [ "$(uname -s)" == "Darwin" ];
    then
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    @@ -72,13 +77,6 @@ fi
    echo "Sucessfully Installed!" && exit
    fi

    if [ "$1" == "install-helper" ];
    then
    cd ~
    curl -O https://gist.github.com/nrobinson2000/7f9dfaef66dccc6c34834ca2ef5dd8ca/raw/d02769d732801965e8bddbd89887755d6e7bc4d5/po-helper-linux.py
    chmod +x po-helper-linux.py
    fi


    if [ "$1" == "init" ];
    then
    @@ -99,31 +97,25 @@ if [ "$1" == "dfu" ];
    then
    if [ "$(uname -s)" == "Darwin" ];
    then
    stty -f /dev/tty.usbmodem1411 14400
    stty -f $modem 19200
    sleep 1
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"
    exit

    else
    ~/po-helper-linux.py
    stty -F /dev/ttyACM0 19200
    sleep 1
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"
    exit

    fi
    fi


    if [ "$1" == "photon" ] || [ "$1" == "electron" ];
    then echo "$1 selected."
    else echo "Please select photon or electron. Try \"po-util help\" for help." && exit
    fi

    if [ "$2" == "build" ] || [ "$2" == "flash" ] || [ "$2" == "clean" ] || [ "$2" == "update" ] || [ "$2" == "ota" ] || [ "$2" == "dfu" ];
    then echo "$2 selected."
    else echo "Please decide whether to update, dfu, ota, clean, build, or build and flash. Try \"po-util help\" for
    help." && exit
    fi

    cd ~/github/firmware || exit

    @@ -135,6 +127,22 @@ if [ "$1" == "electron" ];
    then git checkout prereleases/electron-v0.4.8-rc.6
    fi

    if [ "$2" == "patch" ];
    then
    cd "$CWD"
    sed '2s/.*/START_DFU_FLASHER_SERIAL_SPEED=19200/' ~/github/firmware/build/module-defaults.mk > temp
    rm -f ~/github/firmware/build/module-defaults.mk
    mv temp ~/github/firmware/build/module-defaults.mk

    cd ~/github/firmware/modules/photon/system-part1
    make clean all PLATFORM="photon" program-dfu

    cd ~/github/firmware/modules/photon/system-part1
    make clean all PLATFORM="photon" program-dfu

    fi


    if [ "$2" == "update" ];
    then git pull
    fi
    @@ -157,14 +165,14 @@ if [ "$2" == "flash" ];
    then
    if [ "$(uname -s)" == "Darwin" ];
    then
    stty -f /dev/tty.usbmodem1411 14400
    stty -f $modem 19200
    make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

    else
    ~/po-helper-linux.py
    stty -F /dev/ttyACM0 19200
    make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

    fi
    fi
    fi
  12. nrobinson2000 revised this gist Mar 31, 2016. 1 changed file with 19 additions and 14 deletions.
    33 changes: 19 additions & 14 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -95,6 +95,25 @@ then echo
    else echo "Please run with \"init\" to setup this project directory." && exit
    fi

    if [ "$1" == "dfu" ];
    then
    if [ "$(uname -s)" == "Darwin" ];
    then
    stty -f /dev/tty.usbmodem1411 14400
    sleep 1
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"
    exit

    else
    ~/po-helper-linux.py
    sleep 1
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"
    exit

    fi
    fi


    if [ "$1" == "photon" ] || [ "$1" == "electron" ];
    then echo "$1 selected."
    else echo "Please select photon or electron. Try \"po-util help\" for help." && exit
    @@ -149,17 +168,3 @@ dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

    fi
    fi

    if [ "$2" == "dfu" ];
    then
    if [ "$(uname -s)" == "Darwin" ];
    then
    stty -f /dev/tty.usbmodem1411 14400
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

    else
    ~/po-helper-linux.py
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

    fi
    fi
  13. nrobinson2000 revised this gist Mar 31, 2016. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -100,9 +100,9 @@ then echo "$1 selected."
    else echo "Please select photon or electron. Try \"po-util help\" for help." && exit
    fi

    if [ "$2" == "build" ] || [ "$2" == "flash" ] || [ "$2" == "clean" ] || [ "$2" == "update" ] || [ "$2" == "upload" ] || [ "$2" == "dfu" ];
    if [ "$2" == "build" ] || [ "$2" == "flash" ] || [ "$2" == "clean" ] || [ "$2" == "update" ] || [ "$2" == "ota" ] || [ "$2" == "dfu" ];
    then echo "$2 selected."
    else echo "Please decide whether to update, dfu, upload, clean, build, or build and flash. Try \"po-util help\" for
    else echo "Please decide whether to update, dfu, ota, clean, build, or build and flash. Try \"po-util help\" for
    help." && exit
    fi

    @@ -124,7 +124,7 @@ if [ "$2" == "clean" ];
    then make clean
    fi

    if [ "$2" == "upload" ];
    if [ "$2" == "ota" ];
    then
    particle flash "$3" "$CWD/bin/firmware.bin"
    fi
  14. nrobinson2000 revised this gist Mar 31, 2016. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,5 @@
    # Particle Offline Utility

    #!/bin/bash

    # Particle Offline Utility
    if [ "$1" == "help" ];
    then
    echo " po-util 1.1
    @@ -105,8 +103,7 @@ fi
    if [ "$2" == "build" ] || [ "$2" == "flash" ] || [ "$2" == "clean" ] || [ "$2" == "update" ] || [ "$2" == "upload" ] || [ "$2" == "dfu" ];
    then echo "$2 selected."
    else echo "Please decide whether to update, dfu, upload, clean, build, or build and flash. Try \"po-util help\" for
    help."
    && exit
    help." && exit
    fi

    cd ~/github/firmware || exit
    @@ -155,6 +152,8 @@ fi

    if [ "$2" == "dfu" ];
    then
    if [ "$(uname -s)" == "Darwin" ];
    then
    stty -f /dev/tty.usbmodem1411 14400
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

  15. nrobinson2000 revised this gist Mar 31, 2016. 1 changed file with 21 additions and 2 deletions.
    23 changes: 21 additions & 2 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -102,9 +102,11 @@ then echo "$1 selected."
    else echo "Please select photon or electron. Try \"po-util help\" for help." && exit
    fi

    if [ "$2" == "build" ] || [ "$2" == "flash" ] || [ "$2" == "clean" ] || [ "$2" == "update" ];
    if [ "$2" == "build" ] || [ "$2" == "flash" ] || [ "$2" == "clean" ] || [ "$2" == "update" ] || [ "$2" == "upload" ] || [ "$2" == "dfu" ];
    then echo "$2 selected."
    else echo "Please decide whether to update, clean, build, or build and flash. Try \"po-util help\" for help." && exit
    else echo "Please decide whether to update, dfu, upload, clean, build, or build and flash. Try \"po-util help\" for
    help."
    && exit
    fi

    cd ~/github/firmware || exit
    @@ -125,6 +127,11 @@ if [ "$2" == "clean" ];
    then make clean
    fi

    if [ "$2" == "upload" ];
    then
    particle flash "$3" "$CWD/bin/firmware.bin"
    fi

    if [ "$2" == "build" ];
    then make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    echo "Binary saved to $CWD/bin/firmware.bin"
    @@ -145,3 +152,15 @@ dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

    fi
    fi

    if [ "$2" == "dfu" ];
    then
    stty -f /dev/tty.usbmodem1411 14400
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

    else
    ~/po-helper-linux.py
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

    fi
    fi
  16. nrobinson2000 revised this gist Mar 31, 2016. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -5,15 +5,15 @@
    if [ "$1" == "help" ];
    then
    echo " po-util 1.1
    To install dependencies run \"po-util install\"
    To correctly format a project folder run \"po-util init\"
    To build a binary run \"po-util DEVICE build\", with DEVICE as either \"photon\"
    or \"electron\"
    To build a binary and upload (flash) to the connected device using dfu-util
    run \"po-util DEVICE flash\"
    If you need to reset the build directory run \"po-util DEVICE clean\"
    Summary: Code in the firmware/ directory is compiled and saved as a binary.
    The binary can be flashed to a connected device over dfu-util."
    exit
    @@ -74,7 +74,7 @@ fi
    echo "Sucessfully Installed!" && exit
    fi

    if [ "$1" == "install-helper ];
    if [ "$1" == "install-helper" ];
    then
    cd ~
    curl -O https://gist.github.com/nrobinson2000/7f9dfaef66dccc6c34834ca2ef5dd8ca/raw/d02769d732801965e8bddbd89887755d6e7bc4d5/po-helper-linux.py
    @@ -133,7 +133,7 @@ fi
    if [ "$2" == "flash" ];
    then
    if [ "$(uname -s)" == "Darwin" ];
    then
    then
    stty -f /dev/tty.usbmodem1411 14400
    make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"
  17. nrobinson2000 revised this gist Mar 31, 2016. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -74,6 +74,14 @@ fi
    echo "Sucessfully Installed!" && exit
    fi

    if [ "$1" == "install-helper“ ];
    then
    cd ~
    curl -O https://gist.github.com/nrobinson2000/7f9dfaef66dccc6c34834ca2ef5dd8ca/raw/d02769d732801965e8bddbd89887755d6e7bc4d5/po-helper-linux.py
    chmod +x po-helper-linux.py
    fi
    if [ "$1" == "init" ];
    then
    mkdir firmware/
    @@ -131,6 +139,7 @@ make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PL
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"
    else
    ~/po-helper-linux.py
    make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"
  18. nrobinson2000 revised this gist Mar 31, 2016. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -94,9 +94,9 @@ then echo "$1 selected."
    else echo "Please select photon or electron. Try \"po-util help\" for help." && exit
    fi

    if [ "$2" == "build" ] || [ "$2" == "flash" ] || [ "$2" == "clean" ];
    if [ "$2" == "build" ] || [ "$2" == "flash" ] || [ "$2" == "clean" ] || [ "$2" == "update" ];
    then echo "$2 selected."
    else echo "Please decide whether to clean, build, or build and flash. Try \"po-util help\" for help." && exit
    else echo "Please decide whether to update, clean, build, or build and flash. Try \"po-util help\" for help." && exit
    fi

    cd ~/github/firmware || exit
    @@ -109,7 +109,9 @@ if [ "$1" == "electron" ];
    then git checkout prereleases/electron-v0.4.8-rc.6
    fi

    git pull
    if [ "$2" == "update" ];
    then git pull
    fi

    if [ "$2" == "clean" ];
    then make clean
  19. nrobinson2000 revised this gist Mar 31, 2016. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -123,13 +123,14 @@ fi
    if [ "$2" == "flash" ];
    then
    if [ "$(uname -s)" == "Darwin" ];
    then make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    then
    stty -f /dev/tty.usbmodem1411 14400
    particle flash --usb "$CWD/bin/firmware.bin"
    make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

    else
    make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    particle flash --usb "$CWD/bin/firmware.bin"
    dfu-util -d 2b04:d006 -a 0 -i 0 -s 0x080A0000:leave -D "$CWD/bin/firmware.bin"

    fi
    fi
  20. nrobinson2000 revised this gist Mar 31, 2016. 1 changed file with 10 additions and 3 deletions.
    13 changes: 10 additions & 3 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -116,13 +116,20 @@ then make clean
    fi

    if [ "$2" == "build" ];
    then make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1" && echo "Binary saved to $CWD/bin/firmware.bin"
    then make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    echo "Binary saved to $CWD/bin/firmware.bin"
    fi

    if [ "$2" == "flash" ];
    then
    if [ "$(uname -s)" == "Darwin" ];
    then make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1" && stty -f /dev/tty.usbmodem1411 14400 && particle flash --usb "$CWD/bin/firmware.bin"
    else make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1" && particle flash --usb "$CWD/bin/firmware.bin"
    then make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    stty -f /dev/tty.usbmodem1411 14400
    particle flash --usb "$CWD/bin/firmware.bin"

    else
    make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"
    particle flash --usb "$CWD/bin/firmware.bin"

    fi
    fi
  21. nrobinson2000 revised this gist Mar 31, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion po-util.sh
    Original file line number Diff line number Diff line change
    @@ -123,6 +123,6 @@ if [ "$2" == "flash" ];
    then
    if [ "$(uname -s)" == "Darwin" ];
    then make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1" && stty -f /dev/tty.usbmodem1411 14400 && particle flash --usb "$CWD/bin/firmware.bin"
    else make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"&& particle flash --usb "$CWD/bin/firmware.bin"
    else make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1" && particle flash --usb "$CWD/bin/firmware.bin"
    fi
    fi
  22. nrobinson2000 revised this gist Mar 31, 2016. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ then
    mkdir ~/github
    cd ~/github
    git clone https://github.com/spark/firmware.git
    if [ $(uname -s) == "Linux" ];
    if [ "$(uname -s)" == "Linux" ];
    then
    cd ~/github || exit
    # Install dependencies
    @@ -59,7 +59,7 @@ wget https://gist.github.com/monkbroc/b283bb4da8c10228a61e/raw/e59c77
    sudo mv 50-particle.rules /etc/udev/rules.d/50-particle.rules
    fi

    if [ $(uname -s) == "Darwin" ];
    if [ "$(uname -s)" == "Darwin" ];
    then
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    brew tap PX4/homebrew-px4
    @@ -120,5 +120,9 @@ then make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bi
    fi

    if [ "$2" == "flash" ];
    then make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1" && particle flash --usb "$CWD/bin/firmware.bin"
    then
    if [ "$(uname -s)" == "Darwin" ];
    then make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1" && stty -f /dev/tty.usbmodem1411 14400 && particle flash --usb "$CWD/bin/firmware.bin"
    else make all -s -C ~/github/firmware APPDIR="$CWD/firmware" TARGET_DIR="$CWD/bin" PLATFORM="$1"&& particle flash --usb "$CWD/bin/firmware.bin"
    fi
    fi
  23. nrobinson2000 revised this gist Mar 13, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion po-util.sh
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@
    if [ "$1" == "help" ];
    then
    echo " po-util 1.1
    To install dependencies run \"po-util install\"
    To correctly format a project folder run \"po-util init\"
    To build a binary run \"po-util DEVICE build\", with DEVICE as either \"photon\"
  24. nrobinson2000 revised this gist Mar 13, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,7 @@ echo " po-util 1.1
    Summary: Code in the firmware/ directory is compiled and saved as a binary.
    The binary can be flashed to a connected device over dfu-util."
    exit
    fi

    CWD=$(pwd)
  25. nrobinson2000 revised this gist Mar 13, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,7 @@ echo " po-util 1.1
    To build a binary and upload (flash) to the connected device using dfu-util
    run \"po-util DEVICE flash\"
    If you need to reset the build directory run \"po-util DEVICE clean\"
    Summary: Code in the firmware/ directory is compiled and saved as a binary.
    The binary can be flashed to a connected device over dfu-util."
    fi
  26. nrobinson2000 revised this gist Mar 13, 2016. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -69,6 +69,7 @@ rm node-v5.8.0.pkg
    sudo npm install -g node-pre-gyp npm
    sudo npm install -g particle-cli
    fi
    echo "Sucessfully Installed!" && exit
    fi

    if [ "$1" == "init" ];
  27. nrobinson2000 revised this gist Mar 13, 2016. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion po-util.sh
    Original file line number Diff line number Diff line change
    @@ -21,9 +21,11 @@ CWD=$(pwd)

    if [ "$1" == "install" ];
    then
    mkdir ~/github
    cd ~/github
    git clone https://github.com/spark/firmware.git
    if [ $(uname -s) == "Linux" ];
    then
    mkdir ~/github
    cd ~/github || exit
    # Install dependencies
    echo "installing dependencies..."
  28. nrobinson2000 revised this gist Mar 13, 2016. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,6 @@ echo " po-util 1.1
    To build a binary and upload (flash) to the connected device using dfu-util
    run \"po-util DEVICE flash\"
    If you need to reset the build directory run \"po-util DEVICE clean\"
    Summary: Code in the firmware/ directory is compiled and saved as a binary.
    The binary can be flashed to a connected device over dfu-util."
    fi
    @@ -22,7 +21,7 @@ CWD=$(pwd)

    if [ "$1" == "install" ];
    then
    if [ uname -s == "Linux" ];
    if [ $(uname -s) == "Linux" ];
    then
    mkdir ~/github
    cd ~/github || exit
    @@ -56,7 +55,7 @@ wget https://gist.github.com/monkbroc/b283bb4da8c10228a61e/raw/e59c77
    sudo mv 50-particle.rules /etc/udev/rules.d/50-particle.rules
    fi

    if [ uname -s == "Darwin" ];
    if [ $(uname -s) == "Darwin" ];
    then
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    brew tap PX4/homebrew-px4
  29. nrobinson2000 revised this gist Mar 13, 2016. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions po-util.sh
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,10 @@ echo " po-util 1.1
    To install dependencies run \"po-util install\"
    To correctly format a project folder run \"po-util init\"
    To build a binary run \"po-util DEVICE build\", with DEVICE as either \"photon\" or \"electron\"
    To build a binary and upload (flash) to the connected device using dfu-util run \"po-util DEVICE flash\"
    To build a binary run \"po-util DEVICE build\", with DEVICE as either \"photon\"
    or \"electron\"
    To build a binary and upload (flash) to the connected device using dfu-util
    run \"po-util DEVICE flash\"
    If you need to reset the build directory run \"po-util DEVICE clean\"
    Summary: Code in the firmware/ directory is compiled and saved as a binary.
  30. nrobinson2000 revised this gist Mar 13, 2016. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion po-util.sh
    Original file line number Diff line number Diff line change
    @@ -68,7 +68,6 @@ sudo npm install -g particle-cli
    fi
    fi


    if [ "$1" == "init" ];
    then
    mkdir firmware/