-
Notifications
You must be signed in to change notification settings - Fork 11
feat: Add native esp-idf template #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+210
−4
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
export const espidfTemplate = ` | ||
//engine: espidf | ||
//cmdline: {{{commandLine}}} | ||
{{#if created }} | ||
//created: {{now}} | ||
{{/if}} | ||
// | ||
{{#switch etag}} | ||
{{#case "true"}} | ||
#ifdef {{definePrefix}}_ENABLE_ETAG | ||
#warning {{definePrefix}}_ENABLE_ETAG has no effect because it is permanently switched ON | ||
#endif | ||
{{/case}} | ||
{{#case "false"}} | ||
#ifdef {{definePrefix}}_ENABLE_ETAG | ||
#warning {{definePrefix}}_ENABLE_ETAG has no effect because it is permanently switched OFF | ||
#endif | ||
{{/case}} | ||
{{/switch}} | ||
{{#switch gzip}} | ||
{{#case "true"}} | ||
#ifdef {{definePrefix}}_ENABLE_GZIP | ||
#warning {{definePrefix}}_ENABLE_GZIP has no effect because it is permanently switched ON | ||
#endif | ||
{{/case}} | ||
{{#case "false"}} | ||
#ifdef {{definePrefix}}_ENABLE_GZIP | ||
#warning {{definePrefix}}_ENABLE_GZIP has no effect because it is permanently switched OFF | ||
#endif | ||
{{/case}} | ||
{{/switch}} | ||
// | ||
{{#if version }} | ||
#define {{definePrefix}}_VERSION "{{version}}" | ||
{{/if}} | ||
#define {{definePrefix}}_COUNT {{fileCount}} | ||
#define {{definePrefix}}_SIZE {{fileSize}} | ||
#define {{definePrefix}}_SIZE_GZIP {{fileGzipSize}} | ||
// | ||
{{#each sources}} | ||
#define {{../definePrefix}}_FILE_{{this.datanameUpperCase}} | ||
{{/each}} | ||
// | ||
{{#each filesByExtension}} | ||
#define {{../definePrefix}}_{{this.extension}}_FILES {{this.count}} | ||
{{/each}} | ||
#include <stdint.h> | ||
#include <esp_err.h> | ||
#include <esp_http_server.h> | ||
// | ||
{{#switch gzip}} | ||
{{#case "true"}} | ||
{{#each sources}} | ||
const char datagzip_{{this.dataname}}[{{this.lengthGzip}}] = { {{this.bytesGzip}} }; | ||
{{/each}} | ||
{{/case}} | ||
{{#case "false"}} | ||
{{#each sources}} | ||
const char data_{{this.dataname}}[{{this.length}}] = { {{this.bytes}} }; | ||
{{/each}} | ||
{{/case}} | ||
{{#case "compiler"}} | ||
#ifdef {{definePrefix}}_ENABLE_GZIP | ||
{{#each sources}} | ||
const char datagzip_{{this.dataname}}[{{this.lengthGzip}}] = { {{this.bytesGzip}} }; | ||
{{/each}} | ||
#else | ||
{{#each sources}} | ||
const char data_{{this.dataname}}[{{this.length}}] = { {{this.bytes}} }; | ||
{{/each}} | ||
#endif | ||
{{/case}} | ||
{{/switch}} | ||
// | ||
{{#switch etag}} | ||
{{#case "true"}} | ||
{{#each sources}} | ||
const char * etag_{{this.dataname}} = "{{this.md5}}"; | ||
{{/each}} | ||
{{/case}} | ||
{{#case "false"}} | ||
{{/case}} | ||
{{#case "compiler"}} | ||
#ifdef {{definePrefix}}_ENABLE_ETAG | ||
{{#each sources}} | ||
const char * etag_{{this.dataname}} = "{{this.md5}}"; | ||
{{/each}} | ||
#endif | ||
{{/case}} | ||
{{/switch}} | ||
{{#each sources}} | ||
static esp_err_t file_handler_{{this.datanameUpperCase}} (httpd_req_t *req) | ||
{ | ||
httpd_resp_set_type(req, "{{this.mime}}"); | ||
{{#switch ../gzip}} | ||
{{#case "true"}} | ||
{{#if this.isGzip}} | ||
httpd_resp_set_hdr(req, "Content-Encoding", "gzip"); | ||
{{/if}} | ||
{{/case}} | ||
{{#case "compiler"}} | ||
{{#if this.isGzip}} | ||
#ifdef {{../definePrefix}}_ENABLE_GZIP | ||
httpd_resp_set_hdr(req, "Content-Encoding", "gzip"); | ||
#endif | ||
{{/if}} | ||
{{/case}} | ||
{{/switch}} | ||
{{#switch ../etag}} | ||
{{#case "true"}} | ||
{{#../cacheTime}} | ||
httpd_resp_set_hdr(req, "Cache-Control", "max-age={{value}}"); | ||
{{/../cacheTime}} | ||
{{^../cacheTime}} | ||
httpd_resp_set_hdr(req, "Cache-Control", "no-cache"); | ||
{{/../cacheTime}} | ||
httpd_resp_set_hdr(req, "ETag", etag_{{this.dataname}}); | ||
{{/case}} | ||
{{#case "compiler"}} | ||
#ifdef {{../definePrefix}}_ENABLE_ETAG | ||
{{#../cacheTime}} | ||
httpd_resp_set_hdr(req, "Cache-Control", "max-age={{value}}"); | ||
{{/../cacheTime}} | ||
{{^../cacheTime}} | ||
httpd_resp_set_hdr(req, "Cache-Control", "no-cache"); | ||
{{/../cacheTime}} | ||
httpd_resp_set_hdr(req, "ETag", etag_{{this.dataname}}); | ||
#endif | ||
{{/case}} | ||
{{/switch}} | ||
{{#switch ../gzip}} | ||
{{#case "true"}} | ||
httpd_resp_send(req, datagzip_{{this.dataname}}, {{this.lengthGzip}}); | ||
{{/case}} | ||
{{#case "false"}} | ||
httpd_resp_send(req, data_{{this.dataname}}, {{this.length}}); | ||
{{/case}} | ||
{{#case "compiler"}} | ||
#ifdef {{../definePrefix}}_ENABLE_GZIP | ||
httpd_resp_send(req, datagzip_{{this.dataname}}, {{this.lengthGzip}}); | ||
#else | ||
httpd_resp_send(req, data_{{this.dataname}}, {{this.length}}); | ||
#endif | ||
{{/case}} | ||
{{/switch}} | ||
return ESP_OK; | ||
} | ||
{{#if this.isDefault}} | ||
static const httpd_uri_t route_def_{{this.datanameUpperCase}} = { | ||
.uri = "/", | ||
.method = HTTP_GET, | ||
.handler = file_handler_{{this.datanameUpperCase}}, | ||
}; | ||
{{/if}} | ||
static const httpd_uri_t route_{{this.datanameUpperCase}} = { | ||
.uri = "/{{this.filename}}", | ||
.method = HTTP_GET, | ||
.handler = file_handler_{{this.datanameUpperCase}}, | ||
}; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{{/each}} | ||
static inline void {{methodName}}(httpd_handle_t server) { | ||
{{#each sources}} | ||
{{#if this.isDefault}} | ||
httpd_register_uri_handler(server, &route_def_{{this.datanameUpperCase}}); | ||
{{/if}} | ||
httpd_register_uri_handler(server, &route_{{this.datanameUpperCase}}); | ||
{{/each}} | ||
}`; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Data type inconsistency with other templates.
The data arrays are defined as
const char
in this template while other templates useuint8_t
. According to the learning from your feedback, you intended to keep the data asuint8_t
arrays for compatibility.And similar changes for the other data definitions on lines 66, 72, and 76.
📝 Committable suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol :) correct! but no. it's fixed code for esp32, it might as well just use const char to avoid the casts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karlp Understood! Makes perfect sense to use
const char
for the ESP-IDF template to avoid unnecessary type casting in the ESP32 code. Thanks for the clarification.✏️ Learnings added