diff --git a/tools.c b/tools.c new file mode 100644 index 00000000000..2b452b55b16 --- /dev/null +++ b/tools.c @@ -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; +} diff --git a/tools.h b/tools.h new file mode 100644 index 00000000000..9c71ea6ca73 --- /dev/null +++ b/tools.h @@ -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 diff --git a/usb_hid_autofire.c b/usb_hid_autofire.c index 9d0bb0c78aa..1333ba94ab4 100644 --- a/usb_hid_autofire.c +++ b/usb_hid_autofire.c @@ -4,6 +4,7 @@ #include #include #include "version.h" +#include "tools.h" // Uncomment to be able to make a screenshot //#define USB_HID_AUTOFIRE_SCREENSHOT @@ -25,7 +26,9 @@ uint32_t autofire_delay = 10; static void usb_hid_autofire_render_callback(Canvas* canvas, void* ctx) { UNUSED(ctx); char autofire_delay_str[12]; + //std::string pi = "pi is " + std::to_string(3.1415926); itoa(autofire_delay, autofire_delay_str, 10); + //sprintf(autofire_delay_str, "%lu", autofire_delay); canvas_clear(canvas);