Skip to content

Commit e7d19b5

Browse files
committed
Implement now missing itoa (#1)
1 parent 7d592af commit e7d19b5

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

tools.c

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// Tools for USB HID Autofire
3+
//
4+
5+
void strrev(char* arr, int start, int end) {
6+
char temp;
7+
8+
if (start >= end)
9+
return;
10+
11+
temp = *(arr + start);
12+
*(arr + start) = *(arr + end);
13+
*(arr + end) = temp;
14+
15+
start++;
16+
end--;
17+
strrev(arr, start, end);
18+
}
19+
20+
char *itoa(int number, char *arr, int base)
21+
{
22+
int i = 0, r, negative = 0;
23+
24+
if (number == 0)
25+
{
26+
arr[i] = '0';
27+
arr[i + 1] = '\0';
28+
return arr;
29+
}
30+
31+
if (number < 0 && base == 10)
32+
{
33+
number *= -1;
34+
negative = 1;
35+
}
36+
37+
while (number != 0)
38+
{
39+
r = number % base;
40+
arr[i] = (r > 9) ? (r - 10) + 'a' : r + '0';
41+
i++;
42+
number /= base;
43+
}
44+
45+
if (negative)
46+
{
47+
arr[i] = '-';
48+
i++;
49+
}
50+
51+
strrev(arr, 0, i - 1);
52+
53+
arr[i] = '\0';
54+
55+
return arr;
56+
}

tools.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef FLIPPERZERO_FIRMWARE_TOOLS_H
2+
#define FLIPPERZERO_FIRMWARE_TOOLS_H
3+
4+
void strrev(char *arr, int start, int end);
5+
char *itoa(int number, char *arr, int base);
6+
7+
#endif //FLIPPERZERO_FIRMWARE_TOOLS_H

usb_hid_autofire.c

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <gui/gui.h>
55
#include <input/input.h>
66
#include "version.h"
7+
#include "tools.h"
78

89
// Uncomment to be able to make a screenshot
910
//#define USB_HID_AUTOFIRE_SCREENSHOT
@@ -25,7 +26,9 @@ uint32_t autofire_delay = 10;
2526
static void usb_hid_autofire_render_callback(Canvas* canvas, void* ctx) {
2627
UNUSED(ctx);
2728
char autofire_delay_str[12];
29+
//std::string pi = "pi is " + std::to_string(3.1415926);
2830
itoa(autofire_delay, autofire_delay_str, 10);
31+
//sprintf(autofire_delay_str, "%lu", autofire_delay);
2932

3033
canvas_clear(canvas);
3134

0 commit comments

Comments
 (0)