forked from flipperdevices/flipperzero-firmware
-
-
Notifications
You must be signed in to change notification settings - Fork 540
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
66 additions
and
0 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,56 @@ | ||
// | ||
// Tools for USB HID Autofire | ||
// | ||
|
||
void strrev(char* arr, int start, int end) { | ||
char temp; | ||
|
||
if (start >= end) | ||
return; | ||
|
||
temp = *(arr + start); | ||
*(arr + start) = *(arr + end); | ||
*(arr + end) = temp; | ||
|
||
start++; | ||
end--; | ||
strrev(arr, start, end); | ||
} | ||
|
||
char *itoa(int number, char *arr, int base) | ||
{ | ||
int i = 0, r, negative = 0; | ||
|
||
if (number == 0) | ||
{ | ||
arr[i] = '0'; | ||
arr[i + 1] = '\0'; | ||
return arr; | ||
} | ||
|
||
if (number < 0 && base == 10) | ||
{ | ||
number *= -1; | ||
negative = 1; | ||
} | ||
|
||
while (number != 0) | ||
{ | ||
r = number % base; | ||
arr[i] = (r > 9) ? (r - 10) + 'a' : r + '0'; | ||
i++; | ||
number /= base; | ||
} | ||
|
||
if (negative) | ||
{ | ||
arr[i] = '-'; | ||
i++; | ||
} | ||
|
||
strrev(arr, 0, i - 1); | ||
|
||
arr[i] = '\0'; | ||
|
||
return arr; | ||
} |
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,7 @@ | ||
#ifndef FLIPPERZERO_FIRMWARE_TOOLS_H | ||
#define FLIPPERZERO_FIRMWARE_TOOLS_H | ||
|
||
void strrev(char *arr, int start, int end); | ||
char *itoa(int number, char *arr, int base); | ||
|
||
#endif //FLIPPERZERO_FIRMWARE_TOOLS_H |
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