]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Lib/CMake/sizeCalculator
Adding chip usage display after build completion.
[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 - target binary (e.g. ihex)
6 #| 3 - binary file   (e.g. kiibohd.hex)
7 #| 4 - total available (flash/ram) in bytes
8 #| 5 - flash/ram
9
10
11 # Looks for the data column, to get the flash/ram used (in bytes)
12 # <size binary> --target=<target binary> <binary file> | cut -f2 | tail -n 1
13 USED=$("$1" --target="$2" "$3" | cut -f2 | tail -n 1)
14
15 # Calculates the total flash/ram used
16 TOTAL="$4"
17 PERCENTAGE=$((USED * 100 / TOTAL))
18
19 # Size Colours
20 # Red/Flashing - Almost full
21 if (( PERCENTAGE > 95 )); then
22         COLOR="\t\033[1;5;31m"
23 # Red - Getting full
24 elif (( PERCENTAGE > 90 )); then
25         COLOR="\t\033[1;31m"
26
27 # Yellow - Starting to fill up
28 elif (( PERCENTAGE > 50 )); then
29         COLOR="\t\033[1;33m"
30
31 # Green - Lots of room
32 else
33         COLOR="\t\033[1;32m"
34 fi
35
36 # Displays Results
37 NAME="$5"
38 echo -e "\t\033[1m${NAME}\033[m: ${COLOR}${PERCENTAGE}%\033[m ${USED}/${TOTAL}\tbytes"
39
40 exit 0
41