Skip to content

Commit

Permalink
Merge pull request #15 from Unreal-Dan/daniel/space_cleanup
Browse files Browse the repository at this point in the history
cleaned up some space and refined some things
Unreal-Dan authored Jan 4, 2024
2 parents 352fa95 + 12402c1 commit 480de4d
Showing 12 changed files with 354 additions and 374 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Helios Build

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch: # manual trigger

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout current repository
uses: actions/checkout@v3
- name: Update Package Lists
run: sudo apt-get update
- name: Install Dependencies
run: sudo apt-get install valgrind g++ make --fix-missing
- name: Build
run: make -j
working-directory: HeliosCLI
- name: Set execute permissions for test script
run: chmod +x ./runtests.sh
working-directory: tests
- name: Run general tests
run: ./runtests.sh
working-directory: tests

embedded:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install Dependencies
run: make install
- name: Build Binary
run: make build
- name: Archive production artifacts
uses: actions/upload-artifact@v3
with:
name: embedded firmware
path: |
helios.bin
helios.elf
helios.map
helios.hex
287 changes: 135 additions & 152 deletions ColorConstants.h

Large diffs are not rendered by default.

11 changes: 8 additions & 3 deletions Colorset.cpp
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ void Colorset::init(RGBColor c1, RGBColor c2, RGBColor c3, RGBColor c4,

void Colorset::clear()
{
memset(m_palette, 0, sizeof(m_palette));
memset((void *)m_palette, 0, sizeof(m_palette));
m_numColors = 0;
resetIndex();
}
@@ -179,9 +179,14 @@ void Colorset::randomize(Random &ctx, uint8_t numColors)
numColors = ctx.next8(2, NUM_COLOR_SLOTS);
}
ValueStyle valStyle = (ValueStyle)ctx.next8(0, VAL_STYLE_COUNT);

for (uint8_t i = 0; i < numColors; ++i) {
addColorWithValueStyle(ctx, ctx.next8(), ctx.next8(), valStyle, numColors, i);
// do not put the next8() calls inside arguments, the order functions in
// arguments are called is undefined behaviour and it's important that
// these are called in the right order otherwise different platforms will
// behave differently when performing this randomization
uint8_t sat = ctx.next8();
uint8_t hue = ctx.next8();
addColorWithValueStyle(ctx, hue, sat, valStyle, numColors, i);
}
}

2 changes: 1 addition & 1 deletion Colorset.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef COLORSET_H
#define COLORSET_H

#include "ColorTypes.h"
#include "Colortypes.h"

#include "HeliosConfig.h"

49 changes: 1 addition & 48 deletions Colortypes.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "ColorTypes.h"
#include "Colortypes.h"

#if ALTERNATIVE_HSV_RGB == 1
// global hsv to rgb algorithm selector
@@ -26,35 +26,12 @@ HSVColor::HSVColor(uint32_t dwVal) :
// assignment from uint32_t
HSVColor &HSVColor::operator=(const uint32_t &rhs)
{
// check for the HSV bit!
if (!(rhs & HSV_BIT)) {
// IT'S NOT AN HSV DWORD!!
*this = RGBColor(rhs);
return *this;
}
hue = ((rhs >> 16) & 0xFF);
sat = ((rhs >> 8) & 0xFF);
val = (rhs & 0xFF);
return *this;
}

// copy construction
HSVColor::HSVColor(const HSVColor &rhs)
{
hue = rhs.hue;
sat = rhs.sat;
val = rhs.val;
}

// assignment operator
HSVColor &HSVColor::operator=(const HSVColor &rhs)
{
hue = rhs.hue;
sat = rhs.sat;
val = rhs.val;
return *this;
}

// construction/assignment from RGB
HSVColor::HSVColor(const RGBColor &rhs)
{
@@ -114,36 +91,12 @@ RGBColor::RGBColor(uint32_t dwVal) :
// assignment from uint32_t
RGBColor &RGBColor::operator=(const uint32_t &rhs)
{
// check for the HSV bit!
if ((rhs & HSV_BIT) != 0) {
// IT'S NOT AN RGB DWORD!!
*this = HSVColor(rhs);
return *this;
}

red = ((rhs >> 16) & 0xFF);
green = ((rhs >> 8) & 0xFF);
blue = (rhs & 0xFF);
return *this;
}

// copy construction
RGBColor::RGBColor(const RGBColor &rhs)
{
red = rhs.red;
green = rhs.green;
blue = rhs.blue;
}

// assignment operator
RGBColor &RGBColor::operator=(const RGBColor &rhs)
{
red = rhs.red;
green = rhs.green;
blue = rhs.blue;
return *this;
}

RGBColor::RGBColor(const HSVColor &rhs)
{
*this = rhs;
13 changes: 1 addition & 12 deletions Colortypes.h
Original file line number Diff line number Diff line change
@@ -31,10 +31,6 @@ class HSVColor
HSVColor(uint32_t dwVal);
HSVColor &operator=(const uint32_t &rhs);

// copy/assignment construction
HSVColor(const HSVColor &rhs);
HSVColor &operator=(const HSVColor &rhs);

// construction/assignment from RGB
HSVColor(const RGBColor &rhs);
HSVColor &operator=(const RGBColor &rhs);
@@ -46,7 +42,7 @@ class HSVColor
bool empty() const;
void clear();

uint32_t raw() const { return HSV_BIT | ((uint32_t)hue << 16) | ((uint32_t)sat << 8) | (uint32_t)val; }
uint32_t raw() const { return ((uint32_t)hue << 16) | ((uint32_t)sat << 8) | (uint32_t)val; }

// public members
uint8_t hue;
@@ -64,11 +60,6 @@ class RGBColor
RGBColor(uint32_t dwVal);
RGBColor &operator=(const uint32_t &rhs);

// copy/assignment construction
RGBColor(const RGBColor &rhs);
RGBColor &operator=(const RGBColor &rhs);

// construction/assignment from HSV
RGBColor(const HSVColor &rhs);
RGBColor &operator=(const HSVColor &rhs);

@@ -80,8 +71,6 @@ class RGBColor
void clear();

RGBColor adjustBrightness(uint8_t fadeBy);
void serialize(ByteStream &buffer) const;
void unserialize(ByteStream &buffer);

uint32_t raw() const { return ((uint32_t)red << 16) | ((uint32_t)green << 8) | (uint32_t)blue; }

132 changes: 47 additions & 85 deletions Helios.cpp
Original file line number Diff line number Diff line change
@@ -204,8 +204,7 @@ void Helios::handle_state()
handle_state_shift_mode();
break;
case STATE_RANDOMIZE:
// TODO: Commented out because for space
// handle_state_randomize();
handle_state_randomize();
break;
#ifdef HELIOS_CLI
case STATE_SLEEP:
@@ -258,83 +257,56 @@ void Helios::handle_state_modes()
return;
}

// check for lock and go back to sleep
if (has_flag(FLAG_LOCKED) && hasReleased && !Button::onRelease()) {
enter_sleep();
return;
}

if (!has_flag(FLAG_LOCKED) && hasReleased) {
// just play the current mode
pat.play();
}

// check how long the button is held
uint16_t holdDur = (uint16_t)Button::holdDuration();
// calculate a magnitude which corresponds to how many times past the MENU_HOLD_TIME
// the user has held the button, so 0 means haven't held fully past one yet, etc
uint8_t magnitude = (uint8_t)(holdDur / MENU_HOLD_TIME);

// check for lock and go back to sleep
if (has_flag(FLAG_LOCKED)) {
// if the button is released and it wasn't released this tick then go to sleep
// Wait for the button to not be released this tick because it's possible to
// pick up the button releasing and wakeup the device again instantly
if (hasReleased && !Button::onRelease()) {
enter_sleep();
} else if (magnitude == 5) {
// otherwise if they have held for 5 Seconds to Exit Lock
// then show a low red flash to show they have hit the threshold
Led::set(RGB_RED_BRI_LOW);
} else {
// otherwise the rest of the time just turn off the led
Led::clear();
}
return;
} else if (hasReleased) {
// otherwise if we're not locked, and we have released the led
// then just play the current mode
pat.play();
}

// whether the user has held the button longer than a short click
bool heldPast = (holdDur > SHORT_CLICK_THRESHOLD);
// if the button is held for at least 1 second
if (Button::isPressed() && heldPast) {
// if the button has been released before then show the on menu
if (hasReleased) {
switch (magnitude) {
case 0:
Led::clear();
break;
case 1: // Color Selection
Led::set(RGB_TURQUOISE_BRI_LOW);
break;
case 2: // Pattern Selection
Led::set(RGB_MAGENTA_BRI_LOW);
break;
case 3: // Conjure Mode
Led::set(RGB_YELLOW_BRI_LOW);
break;
case 4: // Shift Mode
Led::set(RGB_WHITE_BRI_LOW);
break;
case 5: // Randomizer
Led::set(HSVColor(Time::getCurtime(), 255, 180));
break;
default:
Led::clear();
break;
case 0: Led::clear(); break; // Turn off
case 1: Led::set(RGB_TURQUOISE_BRI_LOW); break; // Color Selection
case 2: Led::set(RGB_MAGENTA_BRI_LOW); break; // Pattern Selection
case 3: Led::set(RGB_YELLOW_BRI_LOW); break; // Conjure Mode
case 4: Led::set(RGB_WHITE_BRI_LOW); break; // Shift Mode
case 5: Led::set(HSVColor(Time::getCurtime(), 255, 180)); break; // Randomizer
default: Led::clear(); break; // hold past
}
} else {
// Hold for 5 Seconds to Exit Lock
if (has_flag(FLAG_LOCKED)) {
switch (magnitude) {
case 0:
Led::clear();
break;
case 5: // Exit Lock
Led::set(RGB_RED_BRI_LOW);
break;
default:
Led::clear();
break;
}
} else {
switch (magnitude) {
case 0:
Led::clear();
break;
case 1: // Enter Glow Lock
Led::set(RGB_RED_BRI_LOW);
break;
case 2: // Master Reset
Led::set(RGB_BLUE_BRI_LOW);
break;
case 3: // Global Brightness
Led::set(RGB_GREEN_BRI_LOW);
break;
default:
Led::clear();
break;
}
switch (magnitude) {
case 0: Led::clear(); break; // nothing
case 1: Led::set(RGB_RED_BRI_LOW); break; // Enter Glow Lock
case 2: Led::set(RGB_BLUE_BRI_LOW); break; // Master Reset
case 3: Led::set(RGB_GREEN_BRI_LOW); break; // Global Brightness
default: Led::clear(); break; // hold past
}
}
}
@@ -535,12 +507,12 @@ struct ColorsMenuData {
};
// array of hues for selection
static const ColorsMenuData color_menu_data[4] = {
// hue0 hue1 hue2 hue3
// hue0 hue1 hue2 hue3
// ==================================================================================
{ HSV_HUE_RED, HSV_HUE_CORAL_ORANGE, HSV_HUE_ORANGE, HSV_HUE_YELLOW },
{ HSV_HUE_LIME_GREEN, HSV_HUE_GREEN, HSV_HUE_SEAFOAM, HSV_HUE_TURQUOISE },
{ HSV_HUE_ICE_BLUE, HSV_HUE_LIGHT_BLUE, HSV_HUE_BLUE, HSV_HUE_ROYAL_BLUE },
{ HSV_HUE_PURPLE, HSV_HUE_PINK, HSV_HUE_HOT_PINK, HSV_HUE_MAGENTA },
{ HUE_RED, HUE_CORAL_ORANGE, HUE_ORANGE, HUE_YELLOW },
{ HUE_LIME_GREEN, HUE_GREEN, HUE_SEAFOAM, HUE_TURQUOISE },
{ HUE_ICE_BLUE, HUE_LIGHT_BLUE, HUE_BLUE, HUE_ROYAL_BLUE },
{ HUE_PURPLE, HUE_PINK, HUE_HOT_PINK, HUE_MAGENTA },
};

bool Helios::handle_state_col_select_quadrant()
@@ -618,7 +590,7 @@ bool Helios::handle_state_col_select_sat()
if (menu_selection > 3) {
menu_selection = 3;
}
uint8_t saturation_values[4] = {HSV_SAT_HIGH, HSV_SAT_MEDIUM, HSV_SAT_LOW, HSV_SAT_LOWEST};
static const uint8_t saturation_values[4] = {HSV_SAT_HIGH, HSV_SAT_MEDIUM, HSV_SAT_LOW, HSV_SAT_LOWEST};
uint8_t sat = saturation_values[menu_selection];

// use the nice hue to rgb rainbow
@@ -636,8 +608,8 @@ bool Helios::handle_state_col_select_val()
if (menu_selection > 3) {
menu_selection = 3;
}
uint8_t brightness_values[4] = {HSV_BRI_HIGH, HSV_BRI_MEDIUM, HSV_BRI_LOW, HSV_BRI_LOWEST};
uint8_t val = brightness_values[menu_selection];
static const uint8_t hsv_values[4] = {HSV_VAL_HIGH, HSV_VAL_MEDIUM, HSV_VAL_LOW, HSV_VAL_LOWEST};
uint8_t val = hsv_values[menu_selection];

RGBColor targetCol = HSVColor(selected_hue, selected_sat, val);
// use the nice hue to rgb rainbow
@@ -728,18 +700,8 @@ void Helios::handle_state_set_global_brightness()
}
// when the user long clicks a selection
if (Button::onLongClick()) {
// set the brightness based on the selection
switch (menu_selection) {
case 0:
Led::setBrightness(BRIGHTNESS_HIGH);
break;
case 1:
Led::setBrightness(BRIGHNESS_MEDIUM);
break;
case 2:
Led::setBrightness(BRIGHNESS_LOW);
break;
}
// set the brightness based on the selection * the brightness step amount
Led::setBrightness(menu_selection * BRIGHTNESS_STEP);
cur_state = STATE_MODES;
}
show_selection(RGB_WHITE_BRI_LOW);
24 changes: 11 additions & 13 deletions HeliosConfig.h
Original file line number Diff line number Diff line change
@@ -61,23 +61,21 @@

// Brightness Options
//
// These are the four options available in the global brightness menu
// There is only four options, be careful not to go too low
#define BRIGHTNESS_HIGH 255
#define BRIGHNESS_MEDIUM 170
#define BRIGHNESS_LOW 85
// There are three brightness options, the lowest is equal to this value,
// the middle is 2x this value, and the highest is 3x this value
#define BRIGHTNESS_STEP 85

// Pre-defined saturation values
#define HSV_SAT_HIGH 255
#define HSV_SAT_MEDIUM 220
#define HSV_SAT_LOW 190
#define HSV_SAT_LOWEST 160
#define HSV_SAT_HIGH 255
#define HSV_SAT_MEDIUM 220
#define HSV_SAT_LOW 190
#define HSV_SAT_LOWEST 160

// Pre-defined brightness values
#define HSV_BRI_HIGH 255
#define HSV_BRI_MEDIUM 120
#define HSV_BRI_LOW 60
#define HSV_BRI_LOWEST 10
#define HSV_VAL_HIGH 255
#define HSV_VAL_MEDIUM 120
#define HSV_VAL_LOW 60
#define HSV_VAL_LOWEST 10

// ============================================================================
// Storage Constants
2 changes: 1 addition & 1 deletion Led.h
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

#include <inttypes.h>

#include "ColorTypes.h"
#include "Colortypes.h"

class Led
{
55 changes: 42 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
BINDIR=/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/
AVRDUDEDIR=/usr/local/bin/

CC = ${BINDIR}/avr-g++
LD = ${BINDIR}/avr-g++
OBJCOPY = ${BINDIR}/avr-objcopy -v
AR = ${BINDIR}/avr-gcc-ar
SIZE = ${BINDIR}/avr-size
OBJDUMP = ${BINDIR}/avr-objdump
NM = ${BINDIR}/avr-nm
AVRDUDE = ${AVRDUDEDIR}/avrdude
ifneq ($(OS),Windows_NT)
OS = $(shell uname -s)
endif

ifeq ($(OS),Windows_NT) # Windows
BINDIR="C:/Program Files (x86)/Atmel/Studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/"
AVRDUDEDIR="$(shell echo "$$LOCALAPPDATA")/Arduino15/packages/DxCore/tools/avrdude/6.3.0-arduino17or18/bin"
PYTHON="$(shell echo "$$LOCALAPPDATA")/Arduino15/packages/megaTinyCore/tools/python3/3.7.2-post1/python3"
PYPROG="$(shell echo "$$LOCALAPPDATA")/Arduino15/packages/megaTinyCore/hardware/megaavr/2.6.5/tools/prog.py"
DEVICE_DIR="C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.10.348/gcc/dev/attiny85"
INCLUDE_DIR="C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATtiny_DFP/1.10.348/include/"
else ifeq ($(OS),Linux)
BINDIR=~/atmel_setup/avr8-gnu-toolchain-linux_x86_64/bin/
DEVICE_DIR=~/atmel_setup/gcc/dev/attiny85
INCLUDE_DIR=~/atmel_setup/include/
else ifeq ($(OS),Darwin)
BINDIR=/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/
else
# ??? unknown OS
endif

CC = ${BINDIR}avr-g++
LD = ${BINDIR}avr-g++
OBJCOPY = ${BINDIR}avr-objcopy -v
AR = ${BINDIR}avr-gcc-ar
SIZE = ${BINDIR}avr-size
OBJDUMP = ${BINDIR}avr-objdump
NM = ${BINDIR}avr-nm
AVRDUDE = ${AVRDUDEDIR}avrdude

AVRDUDE_CONF = avrdude.conf
AVRDUDE_PORT = /dev/tty.usbmodem1423201
AVRDUDE_PROGRAMMER = stk500v1
AVRDUDE_BAUDRATE = 19200
AVRDUDE_CHIP = attiny85

ifeq ($(OS),Windows_NT) # Windows
AVRDUDE_PORT = COM12
else ifeq ($(OS),Darwin)
AVRDUDE_PORT = /dev/tty.usbmodem1423201
endif

AVRDUDE_FLAGS = -C$(AVRDUDE_CONF) \
-p$(AVRDUDE_CHIP) \
-c$(AVRDUDE_PROGRAMMER) \
@@ -56,7 +79,12 @@ LDFLAGS = -g \
-Wl,--gc-sections \
-mrelax \
-lm \
-mmcu=$(AVRDUDE_CHIP) \
-mmcu=$(AVRDUDE_CHIP)

ifeq ($(OS),Windows_NT) # Windows
CFLAGS+=-B $(DEVICE_DIR)
LDFLAGS+=-B $(DEVICE_DIR)
endif

INCLUDES=\
-I $(INCLUDE_DIR) \
@@ -81,6 +109,7 @@ DFILES = $(SRCS:.cpp=.d)
TARGET = helios

all: $(TARGET).hex
@echo Detected Operating System: $(OS)
$(OBJDUMP) --disassemble --source --line-numbers --demangle --section=.text $(TARGET).elf > $(TARGET).lst
$(NM) --numeric-sort --line-numbers --demangle --print-size --format=s $(TARGET).elf > $(TARGET).map
chmod +x avrsize.sh
99 changes: 53 additions & 46 deletions avrsize.sh
Original file line number Diff line number Diff line change
@@ -1,46 +1,53 @@
#!/bin/bash

# need megatinycore installed for this

if [ "$(uname -o)" == "Msys" ]; then
AVR_SIZE="C:/Program Files (x86)/Atmel/Studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/avr-size.exe"
else
AVR_SIZE="${HOME}/atmel_setup/avr8-gnu-toolchain-linux_x86_64/bin/avr-size"
fi

# Replace this with the path to your .elf file
ELF_FILE=$1

if [ "$ELF_FILE" == "" ]; then
echo "Please specify a file: $0 <file>"
exit 1
fi

# Constants for program storage and dynamic memory size
PROGRAM_STORAGE=8192
DYNAMIC_MEMORY=512

# Run avr-size and parse the output
if [ "$(uname -o)" == "Msys" ]; then
OUTPUT=$("$AVR_SIZE" -A $ELF_FILE)
else
OUTPUT=$($AVR_SIZE -A $ELF_FILE)
fi

# Extract sizes of .text, .data, .rodata, and .bss sections
TEXT_SIZE=$(echo "$OUTPUT" | grep -E '\.text' | awk '{print $2}')
DATA_SIZE=$(echo "$OUTPUT" | grep -E '\.data' | awk '{print $2}')
RODATA_SIZE=$(echo "$OUTPUT" | grep -E '\.rodata' | awk '{print $2}')
BSS_SIZE=$(echo "$OUTPUT" | grep -E '\.bss' | awk '{print $2}')

# Calculate used program storage and dynamic memory
PROGRAM_STORAGE_USED=$((TEXT_SIZE + DATA_SIZE + RODATA_SIZE))
DYNAMIC_MEMORY_USED=$((DATA_SIZE + BSS_SIZE))

# Calculate percentages
PROGRAM_STORAGE_PERCENT=$(awk -v used="$PROGRAM_STORAGE_USED" -v total="$PROGRAM_STORAGE" 'BEGIN { printf("%.2f", used / total * 100) }')
DYNAMIC_MEMORY_PERCENT=$(awk -v used="$DYNAMIC_MEMORY_USED" -v total="$DYNAMIC_MEMORY" 'BEGIN { printf("%.2f", used / total * 100) }')

# Display the results
echo "Sketch uses $PROGRAM_STORAGE_USED bytes ($PROGRAM_STORAGE_PERCENT%) of program storage space. Maximum is $PROGRAM_STORAGE bytes. (Hex: $(printf '%x' $PROGRAM_STORAGE_USED)/$(printf '%x' $PROGRAM_STORAGE))"
echo "Global variables use $DYNAMIC_MEMORY_USED bytes ($DYNAMIC_MEMORY_PERCENT%) of dynamic memory, leaving $(($DYNAMIC_MEMORY - $DYNAMIC_MEMORY_USED)) bytes for local variables. Maximum is $DYNAMIC_MEMORY bytes. (Hex: $(printf '%x' $DYNAMIC_MEMORY_USED)/$(printf '%x' $DYNAMIC_MEMORY))"
#!/bin/bash

# need megatinycore installed for this

if [ "$OS" == "Windows_NT" ]; then
AVR_SIZE="C:/Program Files (x86)/Atmel/Studio/7.0/toolchain/avr8/avr8-gnu-toolchain/bin/avr-size.exe"
elif [ "$(uname -s)" == "Linux" ]; then
AVR_SIZE="${HOME}/atmel_setup/avr8-gnu-toolchain-linux_x86_64/bin/avr-size"
else
AVR_SIZE="/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-size"
fi

if [ ! -x $AVR_SIZE ]; then
echo "Could not find avr-size program"
exit 1
fi

# Replace this with the path to your .elf file
ELF_FILE=$1

if [ "$ELF_FILE" == "" ]; then
echo "Please specify a file: $0 <file>"
exit 1
fi

# Constants for program storage and dynamic memory size
PROGRAM_STORAGE=8192
DYNAMIC_MEMORY=512

# Run avr-size and parse the output
if [ "$(uname -o)" == "Msys" ]; then
OUTPUT=$("$AVR_SIZE" -A $ELF_FILE)
else
OUTPUT=$($AVR_SIZE -A $ELF_FILE)
fi

# Extract sizes of .text, .data, .rodata, and .bss sections
TEXT_SIZE=$(echo "$OUTPUT" | grep -E '\.text' | awk '{print $2}')
DATA_SIZE=$(echo "$OUTPUT" | grep -E '\.data' | awk '{print $2}')
RODATA_SIZE=$(echo "$OUTPUT" | grep -E '\.rodata' | awk '{print $2}')
BSS_SIZE=$(echo "$OUTPUT" | grep -E '\.bss' | awk '{print $2}')

# Calculate used program storage and dynamic memory
PROGRAM_STORAGE_USED=$((TEXT_SIZE + DATA_SIZE + RODATA_SIZE))
DYNAMIC_MEMORY_USED=$((DATA_SIZE + BSS_SIZE))

# Calculate percentages
PROGRAM_STORAGE_PERCENT=$(awk -v used="$PROGRAM_STORAGE_USED" -v total="$PROGRAM_STORAGE" 'BEGIN { printf("%.2f", used / total * 100) }')
DYNAMIC_MEMORY_PERCENT=$(awk -v used="$DYNAMIC_MEMORY_USED" -v total="$DYNAMIC_MEMORY" 'BEGIN { printf("%.2f", used / total * 100) }')

# Display the results
echo "Sketch uses $PROGRAM_STORAGE_USED bytes ($PROGRAM_STORAGE_PERCENT%) of program storage space. Maximum is $PROGRAM_STORAGE bytes. (Hex: $(printf '%x' $PROGRAM_STORAGE_USED)/$(printf '%x' $PROGRAM_STORAGE))"
echo "Global variables use $DYNAMIC_MEMORY_USED bytes ($DYNAMIC_MEMORY_PERCENT%) of dynamic memory, leaving $(($DYNAMIC_MEMORY - $DYNAMIC_MEMORY_USED)) bytes for local variables. Maximum is $DYNAMIC_MEMORY bytes. (Hex: $(printf '%x' $DYNAMIC_MEMORY_USED)/$(printf '%x' $DYNAMIC_MEMORY))"
3 changes: 3 additions & 0 deletions tests/runtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

echo "Success! All tests completed successfully"

0 comments on commit 480de4d

Please sign in to comment.