]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Lib/CMake/sizeCalculator
affb1637b8a94dea393f1179930666b560ddbe3a
[kiibohd-controller.git] / Lib / CMake / sizeCalculator
1 #!/bin/bash
2 #| Jacob Alexander 2014
3 #| Arg List
4 #| 1 - size binary   (e.g. avr-size)
5 #| 2 - measurement type (flash or ram)
6 #| 3 - binary file   (e.g. kiibohd.hex)
7 #| 4 - total available (flash/ram) in bytes
8 #| 5 - flash/ram text
9
10
11 case "$2" in
12 "flash")
13         USED=$("$1" "$3" | tail -n-1 | awk '{ print $1+$2 }')
14         ;;
15 "ram")
16         USED=$("$1" "$3" | tail -n-1 | awk '{ print $2+$3 }')
17         ;;
18 *)
19         echo "INVALID Measurement type: $2"
20         exit 1
21 esac
22
23
24 # Calculates the total flash/ram used
25 TOTAL="$4"
26 PERCENTAGE=$((USED * 100 / TOTAL))
27
28 # Size Colours
29 # Red/Flashing - Almost full
30 if (( PERCENTAGE > 95 )); then
31         COLOR="\t\033[1;5;31m"
32 # Red - Getting full
33 elif (( PERCENTAGE > 90 )); then
34         COLOR="\t\033[1;31m"
35
36 # Yellow - Starting to fill up
37 elif (( PERCENTAGE > 50 )); then
38         COLOR="\t\033[1;33m"
39
40 # Green - Lots of room
41 else
42         COLOR="\t\033[1;32m"
43 fi
44
45 # Displays Results
46 NAME="$5"
47 echo -e "\t\033[1m${NAME}\033[m: ${COLOR}${PERCENTAGE}%\033[m \t${USED}/${TOTAL}\tbytes"
48
49 exit 0
50