Files
gronod 84b60155dd
ci / firmware (jc4827w543, sdkconfig.s3, esp32s3) (push) Canceled after 0s
ci / firmware (wroom, sdkconfig.wroom, esp32) (push) Canceled after 0s
ci / test (push) Canceled after 15s
ci / test (pull_request) Successful in 1m15s
ci / firmware (jc4827w543, sdkconfig.s3, esp32s3) (pull_request) Failing after 6m1s
ci / firmware (wroom, sdkconfig.wroom, esp32) (pull_request) Failing after 6m5s
Update components/app_ui/app_ui.c
2026-09-16 16:34:14 +01:00

201 lines
5.2 KiB
C

#include "app_ui.h"
#include "screens.h"
#include "app_machine.h"
#include "app_process.h"
#include "hal_display.h"
void app_ui_draw_color_chrome(machine_state_t st);
#include <stdio.h>
#include <string.h>
static ui_evt_t s_last;
static bool s_have;
static bool s_dirty;
static void fmt_mmss(char *buf, size_t n, uint32_t total_s)
{
unsigned m = (unsigned)(total_s / 60u);
unsigned s = (unsigned)(total_s % 60u);
if (m > 99u) {
m = 99u;
}
snprintf(buf, n, "%02u:%02u", m, s);
}
static void draw_temp_row3(const ui_evt_t *ev)
{
/* row3 col13: thermo + tt.tC or -- */
char tbuf[8];
if (ev != NULL && ev->temp_ok) {
snprintf(tbuf, sizeof(tbuf), "%4.1fC", (double)ev->temp_c);
hal_display_glyph_thermo(13, 3);
hal_display_text(14, 3, tbuf);
} else {
hal_display_text(13, 3, " --");
}
}
static const char *step_name(uint8_t proc, uint8_t step)
{
const process_def_t *p = app_process_get(proc);
if (p == NULL || step >= p->step_count) {
return "";
}
return p->steps[step].name;
}
static void draw_program_select(void)
{
hal_display_clear();
hal_display_text(0, 0, "Select Programme:");
hal_display_text(0, 1, "1. C41 4. ECN-2");
hal_display_text(0, 2, "2. E6 5. Custom");
hal_display_text(0, 3, "3. B&W 6. B&W Rev");
}
static void draw_step_select(const ui_evt_t *ev)
{
char line[32];
char mm[8];
uint16_t ts = ev->time_s;
fmt_mmss(mm, sizeof(mm), ts);
int pref = (int)(ev->temp_pref_c + (ev->temp_pref_c >= 0 ? 0.5f : -0.5f));
hal_display_clear();
hal_display_text(0, 0, "Step Time Temp");
snprintf(line, sizeof(line), "%-9.9s %s %2dC", step_name(ev->process_id, ev->step_index), mm, pref);
hal_display_text(0, 1, line);
hal_display_text(0, 2, "Scroll / Esc / Ent");
draw_temp_row3(ev);
}
static void draw_armed(const ui_evt_t *ev)
{
char line[32];
char mm[8];
fmt_mmss(mm, sizeof(mm), ev->time_s);
int pref = (int)(ev->temp_pref_c + (ev->temp_pref_c >= 0 ? 0.5f : -0.5f));
hal_display_clear();
snprintf(line, sizeof(line), "%-10.10s %s %2dC", step_name(ev->process_id, ev->step_index), mm, pref);
hal_display_text(0, 0, line);
hal_display_text(0, 1, "Ent:start Esc:quit");
draw_temp_row3(ev);
}
static void draw_running(const ui_evt_t *ev)
{
char line[32];
char mm[8];
uint32_t rem_s = (ev->remaining_ms + 999u) / 1000u;
fmt_mmss(mm, sizeof(mm), rem_s);
hal_display_clear();
snprintf(line, sizeof(line), "%-20.20s", step_name(ev->process_id, ev->step_index));
hal_display_text(0, 0, line);
snprintf(line, sizeof(line), "Remaining: %s", mm);
hal_display_text(0, 1, line);
draw_temp_row3(ev);
}
static void draw_stopped(const ui_evt_t *ev)
{
char line[32];
char mm[8];
uint32_t rem_s = (ev->remaining_ms + 999u) / 1000u;
fmt_mmss(mm, sizeof(mm), rem_s);
hal_display_clear();
snprintf(line, sizeof(line), "%-10.10s %s", step_name(ev->process_id, ev->step_index), mm);
hal_display_text(0, 0, line);
hal_display_text(0, 1, "E:resume X:back");
draw_temp_row3(ev);
}
static void draw_complete(const ui_evt_t *ev)
{
char line[32];
hal_display_clear();
snprintf(line, sizeof(line), "%-10.10s Done", step_name(ev->process_id, ev->step_index));
hal_display_text(0, 0, line);
hal_display_text(0, 1, "E:next X:back");
draw_temp_row3(ev);
}
void app_ui_init(void)
{
memset(&s_last, 0, sizeof(s_last));
s_have = false;
s_dirty = true;
}
void app_ui_on_event(const ui_evt_t *ev)
{
if (ev == NULL) {
return;
}
if (ev->id == EVT_TEMP_UPDATED && s_have) {
s_last.temp_c = ev->temp_c;
s_last.temp_ok = ev->temp_ok;
s_dirty = true;
return;
}
if (ev->id == EVT_STEP_PROGRESS && s_have) {
s_last.remaining_ms = ev->remaining_ms;
s_last.id = ev->id;
s_dirty = true;
return;
}
s_last = *ev;
s_have = true;
s_dirty = true;
}
bool app_ui_is_dirty(void)
{
return s_dirty;
}
void app_ui_draw(void)
{
machine_state_t st = app_machine_state();
ui_evt_t ev = s_last;
if (!s_have) {
ev.temp_ok = false;
}
ev.remaining_ms = app_machine_remaining_ms();
ev.process_id = app_machine_process_id();
ev.step_index = app_machine_step_index();
if (app_process_get(ev.process_id) != NULL) {
ev.time_s = app_process_time_s(ev.process_id, ev.step_index);
const process_def_t *p = app_process_get(ev.process_id);
if (p != NULL && ev.step_index < p->step_count) {
ev.temp_pref_c = p->steps[ev.step_index].temp_pref_c;
}
}
switch (st) {
case ST_IDLE:
draw_program_select();
break;
case ST_STEP_SELECT:
draw_step_select(&ev);
break;
case ST_ARMED:
draw_armed(&ev);
break;
case ST_RUNNING:
draw_running(&ev);
break;
case ST_STOPPED:
draw_stopped(&ev);
break;
case ST_COMPLETE:
draw_complete(&ev);
break;
default:
draw_program_select();
break;
}
app_ui_draw_color_chrome(st);
hal_display_flush();
s_dirty = false;
}