-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#133 Separated utills definition from declaration
- Loading branch information
Showing
2 changed files
with
68 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include "utils.h" | ||
|
||
#include "Constants.h" | ||
|
||
void substring(char* str, uint8_t start, uint8_t size, char* substr) { | ||
strncpy(substr, str + start, size); | ||
substr[size] = '\0'; | ||
} | ||
|
||
void concat(const char* first, char second, const char* third, char* result) { | ||
size_t len1 = strlen(first); | ||
size_t len3 = strlen(third); | ||
|
||
memcpy(result, first, len1); | ||
result[len1] = second; | ||
memcpy(result + len1 + 1, third, len3); | ||
result[len1 + 1 + len3] = '\0'; | ||
} | ||
|
||
void concat(const char* first, char second, char* result) { | ||
size_t len1 = strlen(first); | ||
memcpy(result, first, len1); | ||
result[len1] = second; | ||
result[len1 + 1] = '\0'; | ||
} | ||
|
||
void concat(const char* first, const char* second, char* result) { | ||
strcpy(result, first); | ||
strcat(result, second); | ||
} | ||
|
||
void remove(char* str, uint8_t index, uint8_t count) { | ||
uint8_t len = strlen(str); | ||
if (index + count > len) { | ||
count = len - index; | ||
} | ||
memmove(str + index, str + index + count, len - count - index + 1); | ||
} | ||
|
||
long mapProgress(uint16_t progress, long minValue, long maxValue) { | ||
// Map the progress value to a new range (minValue to maxValue) | ||
return map(progress, MIN_PROGRESS, MAX_PROGRESS, minValue, maxValue); | ||
} | ||
|
||
float mapProgress(uint16_t progress, float minValue, float maxValue) { | ||
// Normalize the progress value and map it to the specified floating-point | ||
// range | ||
return static_cast<float>(progress) / MAX_PROGRESS * (maxValue - minValue) + | ||
minValue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,20 @@ | ||
#pragma once | ||
#ifndef MenuUtils_H | ||
#define MenuUtils_H | ||
|
||
#include <Arduino.h> | ||
|
||
void substring(char* str, uint8_t start, uint8_t size, char* substr) { | ||
strncpy(substr, str + start, size); | ||
substr[size] = '\0'; | ||
} | ||
|
||
void concat(const char* first, char second, const char* third, char* result) { | ||
size_t len1 = strlen(first); | ||
size_t len3 = strlen(third); | ||
|
||
memcpy(result, first, len1); | ||
result[len1] = second; | ||
memcpy(result + len1 + 1, third, len3); | ||
result[len1 + 1 + len3] = '\0'; | ||
} | ||
|
||
void concat(const char* first, char second, char* result) { | ||
size_t len1 = strlen(first); | ||
memcpy(result, first, len1); | ||
result[len1] = second; | ||
result[len1 + 1] = '\0'; | ||
} | ||
|
||
void concat(const char* first, const char* second, char* result) { | ||
strcpy(result, first); | ||
strcat(result, second); | ||
} | ||
|
||
void remove(char* str, uint8_t index, uint8_t count) { | ||
uint8_t len = strlen(str); | ||
if (index + count > len) { | ||
count = len - index; | ||
} | ||
memmove(str + index, str + index + count, len - count - index + 1); | ||
} | ||
|
||
long mapProgress(uint16_t progress, long minValue, long maxValue) { | ||
// Map the progress value to a new range (minValue to maxValue) | ||
return map(progress, MIN_PROGRESS, MAX_PROGRESS, minValue, maxValue); | ||
} | ||
|
||
float mapProgress(uint16_t progress, float minValue, float maxValue) { | ||
// Normalize the progress value and map it to the specified floating-point | ||
// range | ||
return static_cast<float>(progress) / MAX_PROGRESS * (maxValue - minValue) + | ||
minValue; | ||
} | ||
void substring(char* str, uint8_t start, uint8_t size, char* substr); | ||
|
||
void concat(const char* first, char second, const char* third, char* result); | ||
|
||
void concat(const char* first, char second, char* result); | ||
|
||
void concat(const char* first, const char* second, char* result); | ||
|
||
void remove(char* str, uint8_t index, uint8_t count); | ||
|
||
long mapProgress(uint16_t progress, long minValue, long maxValue); | ||
|
||
float mapProgress(uint16_t progress, float minValue, float maxValue); | ||
|
||
#endif |