<commit_before>#!/bin/bash
if [ -z "$1" -o ! -f "$1" ]
then
  echo "You must specify a firmware file"
  exit 1
fi

problem="null"
eclear="/var/www/html/OctoGUI/scripts/eeprom_clear.hex"

status=$(curl -s http://localhost/api/printer?apikey=ABAABABB)
if [ "$status" != "Printer is not operational" ]
then
  check=$(echo "$status"|grep -i Error)
  if [ "$status" != "Operational" -a -z "$check" ]
  then
    problem="$status"
  else
    curl -H "Content-Type: application/json" -X POST -d '{"command":"disconnect"}' http://localhost/api/connection?apikey=ABAABABB
  fi
fi

if [ ! -f "$eclear" ]
then
  echo "eeprom_clear.hex not found"
  exit 1
fi

if [ "$problem" == "null" ]
then
  echo -n "Cycling USB bus ... "
  sudo /usr/local/bin/hub-ctrl -h 0 -P 2 -p 0
  sleep 2
  sudo /usr/local/bin/hub-ctrl -h 0 -P 2 -p 1
  echo "DONE"
  sleep 2
  avrdude -v -p m2560 -c stk500v2 -P /dev/ttyACM0 -b 115200 -D -U flash:w:$eclear:i
  sleep 2
  echo -n "Cycling USB bus ... "
  sudo /usr/local/bin/hub-ctrl -h 0 -P 2 -p 0
  sleep 2
  sudo /usr/local/bin/hub-ctrl -h 0 -P 2 -p 1
  echo "DONE"
  sleep 2
  avrdude -v -p m2560 -c stk500v2 -P /dev/ttyACM0 -b 115200 -D -U flash:w:$1:i
  sleep 15
  curl -H "Content-Type: application/json" -X POST -d '{"command":"connect","port":"/dev/ttyACM0"}' http://localhost/api/connection?apikey=ABAABABB
else
  echo "Cannot flash firmware when printer is $problem"
fi<commit_msg>firmware-update finds the correct port before every command<commit_after>#!/bin/bash
if [ -z "$1" -o ! -f "$1" ]
then
  echo "You must specify a firmware file"
  exit 1
fi

function getPort {
  let p=0
  while [ $p -lt 9 -a -z "$port" ]
  do
    if [ -e /dev/ttyACM$p ]
    then
      port=/dev/ttyACM$p
    fi
  done
  if [ -n "$port" ]
  then
    echo $port
  else
    exit 1
  fi
}

problem="null"
eclear="/var/www/html/OctoGUI/scripts/eeprom_clear.hex"

status=$(curl -s http://localhost/api/printer?apikey=ABAABABB)
if [ "$status" != "Printer is not operational" ]
then
  check=$(echo "$status"|grep -i Error)
  if [ "$status" != "Operational" -a -z "$check" ]
  then
    problem="$status"
  else
    curl -H "Content-Type: application/json" -X POST -d '{"command":"disconnect"}' http://localhost/api/connection?apikey=ABAABABB
  fi
fi

if [ ! -f "$eclear" ]
then
  echo "eeprom_clear.hex not found"
  exit 1
fi

if [ "$problem" == "null" ]
then
  echo -n "Cycling USB bus ... "
  sudo /usr/local/bin/hub-ctrl -h 0 -P 2 -p 0
  sleep 2
  sudo /usr/local/bin/hub-ctrl -h 0 -P 2 -p 1
  echo "DONE"
  sleep 2
  avrdude -v -p m2560 -c stk500v2 -P $(getPort) -b 115200 -D -U flash:w:$eclear:i
  sleep 2
  echo -n "Cycling USB bus ... "
  sudo /usr/local/bin/hub-ctrl -h 0 -P 2 -p 0
  sleep 2
  sudo /usr/local/bin/hub-ctrl -h 0 -P 2 -p 1
  echo "DONE"
  sleep 2
  avrdude -v -p m2560 -c stk500v2 -P $(getPort) -b 115200 -D -U flash:w:$1:i
  sleep 15
  curl -H "Content-Type: application/json" -X POST -d "{\"command\":\"connect\",\"port\":\"$(getPort)\"}" http://localhost/api/connection?apikey=ABAABABB
else
  echo "Cannot flash firmware when printer is $problem"
fi
{'fraction_non_alphanumeric': 0.16574405731032238, 'fraction_numerical': 0.035818951481602086, 'mean_word_length': 2.7832512315270934, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5294258', 'n_tokens_mistral': 1365, 'n_tokens_neox': 1246, 'n_words': 381}