Move split function.

This commit is contained in:
2023-08-22 14:11:04 +02:00
parent d4c7536408
commit 200a27fd06
4 changed files with 34 additions and 37 deletions

View File

@@ -30,7 +30,6 @@ typedef enum
int EEPROM_read_address(int address);
String leading_zero2digit(int value);
String split(String s, char parser, int index);
void check_night_mode(void);
void EEPROM_write_to_address(int address, int value);
void handle_button(void);

View File

@@ -4,6 +4,7 @@
#include <Arduino.h>
int show_string_on_clock(String message, uint32_t color);
String split(String s, char parser, int index);
String time_to_string(uint8_t hours, uint8_t minutes);
void draw_minute_indicator(uint8_t minutes, uint32_t color);

View File

@@ -939,37 +939,6 @@ void handle_command()
webserver.send(204, "text/plain", "No Content"); // this page doesn't send back content --> 204
}
/**
* @brief Splits a string at given character and return specified element
*
* @param s string to split
* @param parser separating character
* @param index index of the element to return
* @return String
*/
String split(String s, char parser, int index)
{
String rs = "";
int parser_cnt = 0;
int r_from_index = 0, r_to_index = -1;
while (index >= parser_cnt)
{
r_from_index = r_to_index + 1;
r_to_index = s.indexOf(parser, r_from_index);
if (index == parser_cnt)
{
if (r_to_index == 0 || r_to_index == -1)
{
return "";
}
return s.substring(r_from_index, r_to_index);
}
else
parser_cnt++;
}
return rs;
}
/**
* @brief Handler for GET requests
*

View File

@@ -3,11 +3,9 @@
#include "ledmatrix.h"
#include "udp_logger.h"
extern LEDMatrix led_matrix;
extern String split(String s, char parser, int index); // TODO cleanup
const String clockStringGerman = "ESPISTAFUNFVIERTELZEHNZWANZIGUVORTECHNICNACHHALBMELFUNFXCONTROLLEREINSEAWZWEIDREITUMVIERSECHSQYACHTSIEBENZWOLFZEHNEUNJUHR";
const String clock_chars_as_string = "ESRISTNFUNFVIERTELZEHNZWANZIGHVORPIKACHUNACHHALBMELFUNFMITTERNACHTEINSUWUZWEIDREIFUNVIERSECHSOBACHTSIEBENZWOLFZEHNEUNEUHR";
/**
* @brief control the four minute indicator LEDs
@@ -82,7 +80,7 @@ int show_string_on_clock(String message, uint32_t color)
if (word.length() > 0)
{
// find word in clock string
word_position = clockStringGerman.indexOf(word, last_letter_clock);
word_position = clock_chars_as_string.indexOf(word, last_letter_clock);
if (word_position >= 0)
{
@@ -104,7 +102,6 @@ int show_string_on_clock(String message, uint32_t color)
}
else // end - no more word in message
{
break;
}
}
@@ -236,3 +233,34 @@ String time_to_string(uint8_t hours, uint8_t minutes)
return message;
}
/**
* @brief Splits a string at given character and return specified element
*
* @param s string to split
* @param parser separating character
* @param index index of the element to return
* @return String
*/
String split(String s, char parser, int index)
{
String rs = "";
int parser_cnt = 0;
int r_from_index = 0, r_to_index = -1;
while (index >= parser_cnt)
{
r_from_index = r_to_index + 1;
r_to_index = s.indexOf(parser, r_from_index);
if (index == parser_cnt)
{
if (r_to_index == 0 || r_to_index == -1)
{
return "";
}
return s.substring(r_from_index, r_to_index);
}
else
parser_cnt++;
}
return rs;
}