Skip to content
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

Python #102

Merged
merged 2 commits into from
Jun 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ idf_component_register(
"menus/wifi.c"
"menus/sao.c"
"menus/ir.c"
"menus/python.c"
"nametag.c"
"uninstall.c"
"file_browser.c"
Expand Down
14 changes: 2 additions & 12 deletions main/appfs_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ static const char* TAG = "appfs wrapper";

esp_err_t appfs_init(void) { return appfsInit(APPFS_PART_TYPE, APPFS_PART_SUBTYPE); }

static uint8_t* load_file_to_ram(FILE* fd, size_t* fsize) {
fseek(fd, 0, SEEK_END);
*fsize = ftell(fd);
fseek(fd, 0, SEEK_SET);
uint8_t* file = malloc(*fsize);
if (file == NULL) return NULL;
fread(file, *fsize, 1, fd);
return file;
}

void appfs_boot_app(int fd) {
if (fd < 0 || fd > 255) {
REG_WRITE(RTC_CNTL_STORE0_REG, 0);
Expand All @@ -59,8 +49,8 @@ void appfs_store_app(pax_buf_t* pax_buffer, ILI9341* ili9341, const char* path,
vTaskDelay(100 / portTICK_PERIOD_MS);
return;
}
size_t app_size;
uint8_t* app = load_file_to_ram(app_fd, &app_size);
size_t app_size = get_file_size(app_fd);
uint8_t* app = load_file_to_ram(app_fd);
fclose(app_fd);
if (app == NULL) {
display_boot_screen(pax_buffer, ili9341, "Failed to load app to RAM");
Expand Down
2 changes: 1 addition & 1 deletion main/factory_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ void factory_test(pax_buf_t* pax_buffer, ILI9341* ili9341) {
pax_background(pax_buffer, 0xa85a32);
ili9341_write(ili9341, pax_buffer->buf);
}
nvs_set_u8_fixed("system", "force_sponsors", 0x01); // Force showing sponsors on first boot
nvs_set_u8_fixed("system", "force_sponsors", 0x01); // Force showing sponsors on first boot
}

while (true) {
Expand Down
36 changes: 1 addition & 35 deletions main/file_browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "menu.h"
#include "pax_gfx.h"
#include "rp2040.h"
#include "system_wrapper.h"

static const char* TAG = "file browser";

Expand Down Expand Up @@ -115,41 +116,6 @@ void find_parent_dir(char* path, char* parent) {
parent[last_separator] = '\0';
}

static bool wait_for_button(xQueueHandle buttonQueue) {
while (1) {
rp2040_input_message_t buttonMessage = {0};
if (xQueueReceive(buttonQueue, &buttonMessage, 1000 / portTICK_PERIOD_MS) == pdTRUE) {
uint8_t pin = buttonMessage.input;
bool value = buttonMessage.state;
if (value) {
if (pin == RP2040_INPUT_BUTTON_BACK) {
return false;
}
if (pin == RP2040_INPUT_BUTTON_ACCEPT) {
return true;
}
}
}
}
}

static uint8_t* load_file_to_ram(FILE* fd) {
fseek(fd, 0, SEEK_END);
size_t fsize = ftell(fd);
fseek(fd, 0, SEEK_SET);
uint8_t* file = malloc(fsize);
if (file == NULL) return NULL;
fread(file, fsize, 1, fd);
return file;
}

static size_t get_file_size(FILE* fd) {
fseek(fd, 0, SEEK_END);
size_t fsize = ftell(fd);
fseek(fd, 0, SEEK_SET);
return fsize;
}

static bool is_esp32_binary(FILE* fd) {
if (get_file_size(fd) < 1) return false;
fseek(fd, 0, SEEK_SET);
Expand Down
16 changes: 8 additions & 8 deletions main/graphics_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
#include "rp2040.h"

void render_message(pax_buf_t* pax_buffer, char* message) {
const pax_font_t* font = pax_get_font("saira regular");
pax_vec1_t size = pax_text_size(font, 18, message);
float width = size.x + 4;
float posX = (pax_buffer->width - width) / 2;
float height = size.y + 4;
float posY = (pax_buffer->height - height) / 2;
pax_col_t fgColor = 0xFFfa448c;
pax_col_t bgColor = 0xFFFFFFFF;
const pax_font_t* font = pax_get_font("saira regular");
pax_vec1_t size = pax_text_size(font, 18, message);
float width = size.x + 4;
float posX = (pax_buffer->width - width) / 2;
float height = size.y + 4;
float posY = (pax_buffer->height - height) / 2;
pax_col_t fgColor = 0xFFfa448c;
pax_col_t bgColor = 0xFFFFFFFF;
pax_simple_rect(pax_buffer, bgColor, posX, posY, width, height);
pax_outline_rect(pax_buffer, fgColor, posX, posY, width, height);
pax_clip(pax_buffer, posX + 1, posY + 1, width - 2, height - 2);
Expand Down
Loading