我是初学者。
我正在为ESP8266开发编程代码。在这种情况下,我要激活的工件的RAW代码存储在SPIFFS中的文件中。我存储在SPIFFS中的文件的示例是:
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
代码中未包含SPIFFS的工件的IR代码如下所示:
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};
重要的是,存储在SPIFFS中的IR代码的输出应如下所示,因为IR库需要位于uint16_t中
但是精确的想法是将它们记录在SPIFFS中,以便可以随时更改它们并节省ESP中的空间,因为我的内存不足,并且仅在要发送的IR代码中加载和必要的。
我尝试了以下操作(无效):
第一次测试:
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;
}
第二项测试:
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;
}
两者给出的结果都带有错误的值,并且非常高。我需要输出在uint16_t中,因为这是IR库发送信号所需的数据类型。
希望你能帮助我。
Giampaolo。