Estoy desarrollando un código de programación para ESP8266. En este, se almacena en un archivo en SPIFFS el código RAW del artefacto que deseo accionar. Un ejemplo del archivo que tengo almacenado en SPIFFS es:
3480, 1760, 400, 444, 424, 1308, 420, 444, 424, 444, 424, 440, 424, 440, 424, 444, 420, 444, 420, 444, 424, 444, 448, 444, 420, 444, 420, 448, 420, 1332, 400, 444, 420, 444, 420, 444, 424, 444, 420, 444, 420, 444, 424, 444, 420, 1332, 400, 1332, 396, 1312, 420, 444, 452, 440, 424, 1308, 420, 448, 420, 444, 420, 444, 420, 448, 420, 444, 420, 444, 424, 440, 424, 444, 420, 444, 424, 444, 420, 444, 420, 444, 424, 444, 448, 444, 420, 444, 424, 444, 420, 444, 420, 444, 420, 448, 420, 444, 420, 444, 424, 444, 420, 444, 420, 444, 424, 444, 420, 444, 420, 448, 448, 440, 424, 444, 420, 444, 420, 1336, 396, 1332, 400, 444, 420, 444, 424, 444, 420, 444, 420, 444, 424, 10008, 3484, 1736, 404, 440, 424, 1308, 448, 448, 420, 444, 420, 444, 424, 440, 424, 444, 420, 444, 424, 440, 424, 444, 420, 444, 424, 444, 420, 444, 420, 1332, 400, 444, 424, 440, 452, 444, 420, 444, 420, 444, 424, 440, 424, 444, 424, 1304, 424, 1332, 400, 1308, 424, 440, 424, 444, 420, 1332, 400, 444, 424, 440, 424, 440, 424, 444, 424, 440, 448, 444, 424, 440, 424, 444, 424, 440, 424, 444, 420, 444, 424, 440, 424, 444, 424, 440, 424, 440, 424, 444, 424, 1308, 420, 1308, 424, 1308, 424, 440, 452, 440, 424, 440, 428, 440, 424, 1308, 424, 1304, 424, 444, 424, 1304, 424, 444, 424, 440, 428, 440, 424, 440, 428, 436, 428, 436, 428, 440, 428, 436, 456, 436, 428, 1304, 424, 1308, 424, 440, 428, 436, 428, 440, 428, 1300, 428, 1304, 428, 440, 424, 440, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 452, 440, 424, 440, 428, 440, 424, 440, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 424, 440, 424, 440, 428, 440, 424, 1308, 424, 1300, 432, 1304, 452, 440, 424, 440, 428, 440, 424, 440, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 424, 1328, 404, 1304, 428, 1304, 424, 440, 428, 436, 428, 440, 452, 440, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 428, 436, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 424, 440, 428, 1304, 452, 440, 428, 436, 428, 1304, 428, 436, 428, 440, 424, 440, 428, 1304, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 452, 440, 428, 436, 428, 436, 428, 440, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 428, 1300, 428, 440, 424, 440, 428, 1300, 428, 440, 428, 436, 456, 1324, 408
El código del aire declarado en el código sin estar en SPIFFS se vería así:
uint16_t powerOff[439] = {3480, 1760, 400, 444, 424, 1308, 420, 444, 424, 444, 424, 440, 424, 440, 424, 444, 420, 444, 420, 444, 424, 444, 448, 444, 420, 444, 420, 448, 420, 1332, 400, 444, 420, 444, 420, 444, 424, 444, 420, 444, 420, 444, 424, 444, 420, 1332, 400, 1332, 396, 1312, 420, 444, 452, 440, 424, 1308, 420, 448, 420, 444, 420, 444, 420, 448, 420, 444, 420, 444, 424, 440, 424, 444, 420, 444, 424, 444, 420, 444, 420, 444, 424, 444, 448, 444, 420, 444, 424, 444, 420, 444, 420, 444, 420, 448, 420, 444, 420, 444, 424, 444, 420, 444, 420, 444, 424, 444, 420, 444, 420, 448, 448, 440, 424, 444, 420, 444, 420, 1336, 396, 1332, 400, 444, 420, 444, 424, 444, 420, 444, 420, 444, 424, 10008, 3484, 1736, 404, 440, 424, 1308, 448, 448, 420, 444, 420, 444, 424, 440, 424, 444, 420, 444, 424, 440, 424, 444, 420, 444, 424, 444, 420, 444, 420, 1332, 400, 444, 424, 440, 452, 444, 420, 444, 420, 444, 424, 440, 424, 444, 424, 1304, 424, 1332, 400, 1308, 424, 440, 424, 444, 420, 1332, 400, 444, 424, 440, 424, 440, 424, 444, 424, 440, 448, 444, 424, 440, 424, 444, 424, 440, 424, 444, 420, 444, 424, 440, 424, 444, 424, 440, 424, 440, 424, 444, 424, 1308, 420, 1308, 424, 1308, 424, 440, 452, 440, 424, 440, 428, 440, 424, 1308, 424, 1304, 424, 444, 424, 1304, 424, 444, 424, 440, 428, 440, 424, 440, 428, 436, 428, 436, 428, 440, 428, 436, 456, 436, 428, 1304, 424, 1308, 424, 440, 428, 436, 428, 440, 428, 1300, 428, 1304, 428, 440, 424, 440, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 452, 440, 424, 440, 428, 440, 424, 440, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 424, 440, 424, 440, 428, 440, 424, 1308, 424, 1300, 432, 1304, 452, 440, 424, 440, 428, 440, 424, 440, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 424, 1328, 404, 1304, 428, 1304, 424, 440, 428, 436, 428, 440, 452, 440, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 428, 436, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 424, 440, 428, 1304, 452, 440, 428, 436, 428, 1304, 428, 436, 428, 440, 424, 440, 428, 1304, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 452, 440, 428, 436, 428, 436, 428, 440, 428, 436, 428, 440, 424, 440, 428, 436, 428, 440, 428, 1300, 428, 440, 424, 440, 428, 1300, 428, 440, 428, 436, 456, 1324, 408};
Pero precisamente la idea es grabarlos en SPIFFS para poderlos cambiar en cualquier momento y sobre todo ahorrar espacio en la ESP, la cual se me está quedando corta de memoria, y solo cargar el código IR cuando se vaya a mandar y sea necesario.
Probé lo siguiente (no me dio resultados):
Primera prueba:
bool SPIFFSCodes::loadPowerOff()
{
File file_id= SPIFFS.open("/powerOff", "r");
if (!file_id)
{
Serial.println("Failed to open powerOff file");
return false;
}
size_t size = file_id.size();
std::unique_ptr<char[]> buf(new char[size]);
file_id.readBytes(buf.get(), size);
uint16_t powerOff[439];
for (int i = 0; i != 439; i++)
{
powerOff[i] = 256*buf[2*i]+buf[2*i+1];
}
// show the data in console and check if it is correct:
for (int i = 0; i != 439; i++)
{
Serial.print(powerOff[i]);
Serial.print(", ");
}
irsend1.sendRaw(powerOff,439,38);
return true;
}
Segunda prueba:
bool SPIFFSCodes::loadPowerOff()
{
File file_id= SPIFFS.open("/powerOff", "r");
if (!file_id)
{
Serial.println("Failed to open powerOff file");
return false;
}
size_t size = file_id.size();
std::unique_ptr<char[]> buf(new char[size]);
file_id.readBytes(buf.get(), size);
uint16_t powerOff[439];
for (int i = 0; i != 439; i++)
{
powerOff[i] = buf[2*i]+64*buf[2*i+1];
}
// show the data in console and check if it is correct:
for (int i = 0; i != 439; i++)
{
Serial.print(powerOff[i]);
Serial.print(", ");
}
irsend1.sendRaw(powerOff,439,38);
return true;
}
Ambas dieron resultados con valores erróneos y muy altos al que debería ser. Necesito que la salida sea en uint16_t dado que es el tipo de dato que necesita la librería IR para mandar la señal.