You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.5 KiB

3 years ago
3 years ago
3 years ago
  1. #!/bin/bash -x
  2. COUNTER=0
  3. while test $COUNTER -lt 1; do #run forever #this seems to expect a file named 1 in the directory. no idea why. EDIT: that was with counter < 1. must use -lt
  4. #if load gt 1, then load == 1
  5. LOAD=$(cat /proc/loadavg | cut -c 1-4)
  6. FIRSTVAL=$(echo $LOAD | cut -c 1) #check if 1 or higher
  7. test $FIRSTVAL == 1; #is equal to 1?
  8. if test $? == 0; then #return value
  9. FINALVAL=47
  10. fi
  11. test $FIRSTVAL > 1;
  12. if test $? == 0; then #if test is succesful, returns zero, so we are looking for a zero
  13. FINALVAL=47
  14. fi
  15. test $FIRSTVAL < 1;
  16. if test $? == 0; then #i know this isn't efficient. could combine if else. dont care.
  17. FINALVAL=$(echo $LOAD | cut -c 3-4)
  18. fi
  19. echo $FINALVAL
  20. #otherwise load x 47 == VAL
  21. DIVIDEBYTWO=$(expr $FINALVAL / 2) #must be space between / and numbers
  22. # if test $DIVIDEBYTWO > 50; then #hmmm... needs -gt not >
  23. # DIVIDEBYTWO=50;
  24. # fi
  25. # echo "DIVIDEBY TWO IS: $DIVIDEBYTWO"
  26. #seems to need a space after the first funct. parenthesis, and the call to function
  27. #seems to not like function named gopher, so set to go4. perhaps character limit.
  28. echo "(defun go4() (with-i2c (str 96) (write-byte #x40 str) (write-byte $DIVIDEBYTWO str) (write-byte #x00 str))) (go4)" > /dev/ttyUS>
  29. # echo " (go4)" > /dev/ttyUSB0
  30. sleep 5
  31. done