mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-19 06:23:44 +02:00
Reformat project using clang-format
This commit is contained in:
@@ -1,85 +1,85 @@
|
||||
#include "helpers.hpp"
|
||||
|
||||
char *Helpers::itoa(int value, char *result, int base)
|
||||
char* Helpers::itoa(int value, char* result, int base)
|
||||
{
|
||||
// check that the base if valid
|
||||
if (base < 2 || base > 36)
|
||||
{
|
||||
*result = '\0';
|
||||
return result;
|
||||
}
|
||||
|
||||
char *ptr = result, *ptr1 = result, tmp_char;
|
||||
int tmp_value;
|
||||
|
||||
do
|
||||
{
|
||||
tmp_value = value;
|
||||
value /= base;
|
||||
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)];
|
||||
} while (value);
|
||||
|
||||
// Apply negative sign
|
||||
if (tmp_value < 0)
|
||||
*ptr++ = '-';
|
||||
*ptr-- = '\0';
|
||||
while (ptr1 < ptr)
|
||||
{
|
||||
tmp_char = *ptr;
|
||||
*ptr-- = *ptr1;
|
||||
*ptr1++ = tmp_char;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void split(const std::string &str, const std::string &splitBy, std::vector<std::string> &tokens)
|
||||
{
|
||||
/* Store the original string in the array, so we can loop the rest
|
||||
* of the algorithm. */
|
||||
tokens.emplace_back(str);
|
||||
|
||||
// Store the split index in a 'size_t' (unsigned integer) type.
|
||||
size_t splitAt;
|
||||
// Store the size of what we're splicing out.
|
||||
size_t splitLen = splitBy.size();
|
||||
// Create a string for temporarily storing the fragment we're processing.
|
||||
std::string frag;
|
||||
// Loop infinitely - break is internal.
|
||||
while (true)
|
||||
{
|
||||
/* Store the last string in the vector, which is the only logical
|
||||
* candidate for processing. */
|
||||
frag = tokens.back();
|
||||
/* The index where the split is. */
|
||||
splitAt = frag.find(splitBy);
|
||||
// If we didn't find a new split point...
|
||||
if (splitAt == std::string::npos)
|
||||
// check that the base if valid
|
||||
if (base < 2 || base > 36)
|
||||
{
|
||||
// Break the loop and (implicitly) return.
|
||||
break;
|
||||
*result = '\0';
|
||||
return result;
|
||||
}
|
||||
/* Put everything from the left side of the split where the string
|
||||
* being processed used to be. */
|
||||
tokens.back() = frag.substr(0, splitAt);
|
||||
/* Push everything from the right side of the split to the next empty
|
||||
* index in the vector. */
|
||||
tokens.emplace_back(frag.substr(splitAt + splitLen, frag.size() - (splitAt + splitLen)));
|
||||
}
|
||||
|
||||
char *ptr = result, *ptr1 = result, tmp_char;
|
||||
int tmp_value;
|
||||
|
||||
do
|
||||
{
|
||||
tmp_value = value;
|
||||
value /= base;
|
||||
*ptr++ = "zyxwvutsrqponmlkjihgfedcba9876543210123456789abcdefghijklmnopqrstuvwxyz"[35 + (tmp_value - value * base)];
|
||||
} while (value);
|
||||
|
||||
// Apply negative sign
|
||||
if (tmp_value < 0)
|
||||
*ptr++ = '-';
|
||||
*ptr-- = '\0';
|
||||
while (ptr1 < ptr)
|
||||
{
|
||||
tmp_char = *ptr;
|
||||
*ptr-- = *ptr1;
|
||||
*ptr1++ = tmp_char;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> Helpers::split(const std::string &s, char delimiter)
|
||||
void split(const std::string& str, const std::string& splitBy, std::vector<std::string>& tokens)
|
||||
{
|
||||
std::vector<std::string> parts;
|
||||
std::string part;
|
||||
std::istringstream tokenStream(s);
|
||||
while (std::getline(tokenStream, part, delimiter))
|
||||
{
|
||||
parts.push_back(part);
|
||||
}
|
||||
return parts;
|
||||
/* Store the original string in the array, so we can loop the rest
|
||||
* of the algorithm. */
|
||||
tokens.emplace_back(str);
|
||||
|
||||
// Store the split index in a 'size_t' (unsigned integer) type.
|
||||
size_t splitAt;
|
||||
// Store the size of what we're splicing out.
|
||||
size_t splitLen = splitBy.size();
|
||||
// Create a string for temporarily storing the fragment we're processing.
|
||||
std::string frag;
|
||||
// Loop infinitely - break is internal.
|
||||
while (true)
|
||||
{
|
||||
/* Store the last string in the vector, which is the only logical
|
||||
* candidate for processing. */
|
||||
frag = tokens.back();
|
||||
/* The index where the split is. */
|
||||
splitAt = frag.find(splitBy);
|
||||
// If we didn't find a new split point...
|
||||
if (splitAt == std::string::npos)
|
||||
{
|
||||
// Break the loop and (implicitly) return.
|
||||
break;
|
||||
}
|
||||
/* Put everything from the left side of the split where the string
|
||||
* being processed used to be. */
|
||||
tokens.back() = frag.substr(0, splitAt);
|
||||
/* Push everything from the right side of the split to the next empty
|
||||
* index in the vector. */
|
||||
tokens.emplace_back(frag.substr(splitAt + splitLen, frag.size() - (splitAt + splitLen)));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> Helpers::split(const std::string& s, char delimiter)
|
||||
{
|
||||
std::vector<std::string> parts;
|
||||
std::string part;
|
||||
std::istringstream tokenStream(s);
|
||||
while (std::getline(tokenStream, part, delimiter))
|
||||
{
|
||||
parts.push_back(part);
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
|
||||
int64_t Helpers::getTimeInMillis()
|
||||
{
|
||||
return (esp_timer_get_time() / 1000);
|
||||
return (esp_timer_get_time() / 1000);
|
||||
}
|
||||
@@ -1,40 +1,40 @@
|
||||
#pragma once
|
||||
#ifndef HELPERS_HPP
|
||||
#define HELPERS_HPP
|
||||
#include "esp_timer.h"
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "esp_timer.h"
|
||||
|
||||
namespace Helpers
|
||||
{
|
||||
char *itoa(int value, char *result, int base);
|
||||
void split(std::string str, std::string splitBy, std::vector<std::string> &tokens);
|
||||
std::vector<std::string> split(const std::string &s, char delimiter);
|
||||
char* itoa(int value, char* result, int base);
|
||||
void split(std::string str, std::string splitBy, std::vector<std::string>& tokens);
|
||||
std::vector<std::string> split(const std::string& s, char delimiter);
|
||||
|
||||
/// @brief
|
||||
/// @tparam ...Args
|
||||
/// @param format
|
||||
/// @param ...args
|
||||
/// @return
|
||||
template <typename... Args>
|
||||
std::string format_string(const std::string &format, Args... args)
|
||||
{
|
||||
int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0'
|
||||
/// @brief
|
||||
/// @tparam ...Args
|
||||
/// @param format
|
||||
/// @param ...args
|
||||
/// @return
|
||||
template <typename... Args>
|
||||
std::string format_string(const std::string& format, Args... args)
|
||||
{
|
||||
int size_s = std::snprintf(nullptr, 0, format.c_str(), args...) + 1; // Extra space for '\0'
|
||||
if (size_s <= 0)
|
||||
{
|
||||
std::cout << "Error during formatting.";
|
||||
return "";
|
||||
std::cout << "Error during formatting.";
|
||||
return "";
|
||||
}
|
||||
auto size = static_cast<size_t>(size_s);
|
||||
std::unique_ptr<char[]> buf(new char[size]);
|
||||
std::snprintf(buf.get(), size, format.c_str(), args...);
|
||||
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
|
||||
}
|
||||
|
||||
int64_t getTimeInMillis();
|
||||
return std::string(buf.get(), buf.get() + size - 1); // We don't want the '\0' inside
|
||||
}
|
||||
|
||||
#endif // HELPERS_HPP
|
||||
int64_t getTimeInMillis();
|
||||
} // namespace Helpers
|
||||
|
||||
#endif // HELPERS_HPP
|
||||
|
||||
@@ -28,12 +28,18 @@ void setStartupPaused(bool startupPaused)
|
||||
}
|
||||
|
||||
// Function to manually activate streaming
|
||||
void activateStreaming(void *arg)
|
||||
void activateStreaming(void* arg)
|
||||
{
|
||||
force_activate_streaming();
|
||||
}
|
||||
|
||||
// USB handover state
|
||||
static bool s_usbHandoverDone = false;
|
||||
bool getUsbHandoverDone() { return s_usbHandoverDone; }
|
||||
void setUsbHandoverDone(bool done) { s_usbHandoverDone = done; }
|
||||
bool getUsbHandoverDone()
|
||||
{
|
||||
return s_usbHandoverDone;
|
||||
}
|
||||
void setUsbHandoverDone(bool done)
|
||||
{
|
||||
s_usbHandoverDone = done;
|
||||
}
|
||||
@@ -9,7 +9,7 @@
|
||||
// Function to manually activate streaming
|
||||
// designed to be scheduled as a task
|
||||
// so that the serial manager has time to return the response
|
||||
void activateStreaming(void *arg);
|
||||
void activateStreaming(void* arg);
|
||||
|
||||
bool getStartupCommandReceived();
|
||||
void setStartupCommandReceived(bool startupCommandReceived);
|
||||
|
||||
Reference in New Issue
Block a user