I have Arduino program that use IRsend Library to send IR code, this library need a raw uint16_t array like:
uint16_t rawData[229] = {3114, 2996, 3114, 4374, 598, 486, 598, 1596, 598, 486, 596, 1596, 598, 1596, 598, 486, 596, 486, 596, 1596, 598, 486, 596, 486, 596, 486, 596, 486, 596, 486, 596, 1596, 598, 1596, 600, 486, 600, 484, 596, 486, 598, 486, 598, 486, 598, 486, 596, 486, 598, 486, 598, 1596, 598, 486, 598, 486, 596, 486, 598, 486, 596, 486, 598, 486, 596, 1596, 598, 486, 596, 486, 596, 1594, 600, 1594, 600, 1596, 598, 486, 596, 1596, 598, 488, 596, 1596, 598, 486, 598, 1594, 600, 1596, 598, 486, 598, 486, 596, 486, 596, 486, 596, 486, 596, 486, 598, 1596, 598, 486, 596, 488, 596, 486, 598, 486, 596, 486, 596, 486, 598, 486, 596, 486, 596, 1596, 598, 486, 598, 486, 596, 486, 596, 486, 598, 486, 596, 486, 596, 486, 598, 486, 598, 486, 598, 486, 596, 486, 598, 486, 598, 486, 596, 486, 638, 444, 596, 486, 598, 486, 596, 486, 598, 486, 598, 486, 596, 486, 598, 486, 598, 486, 596, 486, 598, 486, 598, 486, 596, 486, 598, 486, 598, 486, 596, 486, 598, 486, 598, 486, 596, 486, 596, 486, 598, 486, 598, 486, 598, 486, 598, 486, 598, 486, 598, 486, 598, 1596, 598, 486, 598, 1596, 598, 486, 598, 1596, 600, 1596, 598, 486, 598, 1596, 598, 486, 598, 1596, 598, 1596, 598, 486, 596, 486, 596}; // UNKNOWN 80C9BEC5
I stored this uint16_t array to file called (Turbo_swing_middle) inside data folder then upload it to esp32.
I tried the following code to read the file from SPIFFS:
#include <Arduino.h>
#include "SPIFFS.h"
#include <IRremote.hpp>
#define LENGTH 2048
uint16_t rawData[LENGTH];
String st;
void parseCharToUint16WithIrSend(char* textData){
Serial.printf("Parsing '%s':\n", textData);
char *end;
int sizeArray = 0;
for (unsigned long i = strtoul(textData, &end, 10);
textData != end;
i = strtoul(textData, &end, 10))
{
textData = end;
rawData[sizeArray] = i;
Serial.printf("Value = %d\n", rawData[sizeArray]);
sizeArray++;
}
printf("Actual array data size: %d\n", sizeArray);
// IrSender.sendRaw(rawData,sizeArray,38); // here in rawData we have converted all values from char* to uint16_t
Serial.println("=> DATA WAS SEND BY IR LED");
sizeArray=0; // set index to 0
memset(rawData, 0, LENGTH); // clear array
}
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
IrSender.begin(2);
if(!SPIFFS.begin(true)){
Serial.println("An Error has occurred while mounting SPIFFS");
return;
}
File myFile = SPIFFS.open("/Turbo_swing_middle","r");
while (myFile.available()) {
st = myFile.readStringUntil('\n');
Serial.println("Content of file:");
//Serial.println(st);
char buf[2048];
st.toCharArray(buf,2048);
Serial.println(buf);
Serial.println("\n\n");
parseCharToUint16WithIrSend(buf);
myFile.close();
}
}
void loop() {
}
I Successfully read the file content but the problem how to place that array to uint16_t?
the output of the code is :
Content of file:
3146,2964,3144,4342,630,454,628,1564,630,454,628,1564,630,1564,630,454,628,454,628,1564,630,454,628,454,628,454,628,454,630,454,628,1562,630,1564,630,454,630,454,628,454,630,454,630,454,628,454,628,456,628,456,628,1564,630,454,628,454,628,454,630,454,628,454,630,454,628,1562,630,454,628,454,630,1564,630,1564,630,1564,630,456,628,1564,630,454,630,454,628,454,630,1564,630,1562,630,454,628,454,628,454,628,454,628,454,628,454,628,1564,630,454,628,454,628,454,628,454,628,454,628,456,628,454,628,454,628,1566,628,454,628,454,628,454,628,454,630,456,628,454,628,454,630,454,628,454,628,456,628,454,630,454,628,454,628,454,628,454,628,454,628,454,628,454,628,454,628,454,628,454,630,454,628,456,628,454,628,454,628,454,630,454,628,454,628,454,630,456,628,454,628,456,628,454,630,454,630,454,628,454,630,454,630,454,628,456,628,454,628,454,628,454,628,454,628,454,628,1564,630,1564,630,456,628,454,628,1564,630,454,630,1562,632,1564,630,1564,630
Parsing '3146,2964,3144,4342,630,454,628,1564,630,454,628,1564,630,1564,630,454,628,454,628,1564,630,454,628,454,628,454,628,454,630,454,628,1562,630,1564,630,454,630,454,628,454,630,454,630,454,628,454,628,456,628,456,628,1564,630,454,628,454,628,454,630,454,628,454,630,454,628,1562,630,454,628,454,630,1564,630,1564,630,1564,630,456,628,1564,630,454,630,454,628,454,630,1564,630,1562,630,454,628,454,628,454,628,454,628,454,628,454,628,1564,630,454,628,454,628,454,628,454,628,454,628,456,628,454,628,454,628,1566,628,454,628,454,628,454,628,454,630,456,628,454,628,454,630,454,628,454,628,456,628,454,630,454,628,454,628,454,628,454,628,454,628,454,628,454,628,454,628,454,628,454,630,454,628,456,628,454,628,454,628,454,630,454,628,454,628,454,630,456,628,454,628,456,628,454,630,454,630,454,628,454,630,454,630,454,628,456,628,454,628,454,628,454,628,454,628,454,628,1564,630,1564,630,456,628,454,628,1564,630,454,630,1562,632,1564,630,1564,630':
Value = 3146
Actual array data size: 1
=> DATA WAS SEND BY IR LED
I used parseCharToUint16WithIrSend() function from this thread , but it read only one value and not the whole file contents.
What i want is to read the raw data from the SPIFFS file then place the content inside uint16_t array so i can use it in IRsender like this:
uint16_t rawData[229] = {3114, 2996, 3114, 4374, 598, 486, 598, 1596, 598, 486, 596, 1596, 598, 1596, 598, 486, 596, 486, 596, 1596, 598, 486, 596, 486, 596, 486, 596, 486, 596, 486, 596, 1596, 598, 1596, 600, 486, 600, 484, 596, 486, 598, 486, 598, 486, 598, 486, 596, 486, 598, 486, 598, 1596, 598, 486, 598, 486, 596, 486, 598, 486, 596, 486, 598, 486, 596, 1596, 598, 486, 596, 486, 596, 1594, 600, 1594, 600, 1596, 598, 486, 596, 1596, 598, 488, 596, 1596, 598, 486, 598, 1594, 600, 1596, 598, 486, 598, 486, 596, 486, 596, 486, 596, 486, 596, 486, 598, 1596, 598, 486, 596, 488, 596, 486, 598, 486, 596, 486, 596, 486, 598, 486, 596, 486, 596, 1596, 598, 486, 598, 486, 596, 486, 596, 486, 598, 486, 596, 486, 596, 486, 598, 486, 598, 486, 598, 486, 596, 486, 598, 486, 598, 486, 596, 486, 638, 444, 596, 486, 598, 486, 596, 486, 598, 486, 598, 486, 596, 486, 598, 486, 598, 486, 596, 486, 598, 486, 598, 486, 596, 486, 598, 486, 598, 486, 596, 486, 598, 486, 598, 486, 596, 486, 596, 486, 598, 486, 598, 486, 598, 486, 598, 486, 598, 486, 598, 486, 598, 1596, 598, 486, 598, 1596, 598, 486, 598, 1596, 600, 1596, 598, 486, 598, 1596, 598, 486, 598, 1596, 598, 1596, 598, 486, 596, 486, 596}; // UNKNOWN 80C9BEC5
IrSender.sendRaw(rawData, 229, 38); // Send a raw data capture at 38kHz.
array size is fixed at 229, but i prefer dynamic size if possible!