#define maxBufferLen 80
char *buffer;
char *upperCase;
char *lowerCase;
char *numbers;
static SemaphoreHandle_t mutex;
static volatile bool allocated = 0;
unsigned short bufferIndex = 0;
TaskHandle_t listenHandle = NULL;
TaskHandle_t separateHandle = NULL;
void listenToSerialMonitor(void*) {
while (1) {
if (!allocated) {
buffer = (char *)calloc(maxBufferLen, sizeof(char));
if (buffer == NULL) {
Serial.println("Memory allocation failed!");
} else {
allocated = 1;
}
}
while (Serial.available()) {
char c = Serial.read();
if (bufferIndex < maxBufferLen - 1 && c != '\n') {
buffer[bufferIndex++] = c;
} else {
buffer[bufferIndex] = '\0';
bufferIndex = 0;
vTaskResume(separateHandle);
}
}
}
}
void separate(void*) {
while (1) {
for (i = 0; i < maxBufferLen; i++) {
if (buffer[i] >= 65 && buffer[i] <= 90) { //separando as Maiúsculas
upperCase[i] = buffer[i];
}
if (buffer[i] >= 97 && buffer[i] <= 122) { //separando as minúsculas
lowerCase[i] = buffer[i];
}
if (buffer[i] >= 48 && buffer[i] <= 57) { //separando os números
numbers[i] = buffer[i];
}
}
free(buffer);
allocated = 0;
vTaskSuspend(NULL);
}
}
void ordenar(char *x) {
int temp = 0;
for (int i = 0; i < t; i++) {
for (int j = i + 1; j < t; j++) {
if (x[i] > x[j]) {
temp = x[i];
x[i] = x[j];
x[j] = temp;
}
}
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
xTaskCreatePinnedToCore(listenToSerialMonitor,
"Listen to Serial Monitor",
1024,
NULL,
1,
&listenHandle,
1);
xTaskCreatePinnedToCore(separate,
"Send to Serial Monitor",
1024,
NULL,
1,
&separateHandle,
2);
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}