So that i do not need to escape all type of // \\ '' and so on.
Code: Select all
#include "IR.htm.h" // This is the file IR.htm converted in Array IR_htm
void handleRoot() {
server.send_P(200, "text/html", IR_htm, sizeof(IR_htm) );
}
#include "favicon.ico.h" // This is the file favicon.ico converted in Array favicon_ico
void faviconico()
{
server.send_P(200, "image/x-icon", favicon_ico , sizeof(favicon_ico));
}
And the Powershell
Code: Select all
function ConvertToBin($path)
{
Write-Output "const char $((Split-Path $path -leaf).Replace('.','_'))[] PROGMEM = {"
$arrayFromFile = Get-Content -Encoding byte -Path ".\$path"
$i=0;
$line="";
$linetxt="";
foreach($item in $arrayFromFile)
{
if($i) { $line+= ","} else { $line+= " "}
$line+= "0x$(([int]$item).ToString('X2'))"
if (($item -ge 32) -and ($item -le 126) -and !($item -eq [int]([char]'\'))) { $linetxt+=[char]$item;} else {$linetxt+='.';}
$i+=1
if(!($i % 31)) {
#Write-Output "$line";
Write-Output "$line // $linetxt";
$line="" ; $linetxt="" }
}
if($i % 31) {
Write-Output "$line // $linetxt";
}
Write-Output "};"
#Write-Output "$(Split-Path $path -Parent)\$(Split-Path $path -leaf).h"
}
function ConvertFileToBin ($file)
{
ConvertToBin($file) | Out-File -FilePath "$file.h" -Encoding ASCII
}
ConvertFileToBin('IR.htm')
ConvertFileToBin('favicon.ico')