hello c06b3b4f→07b1ee37; mipsel -Wall -Wextra 0 warning; 宿主 P1c/P2/P3 + widgets 全 PASS SDK 后续项(本批 App 层显式驱动适配, 未动 SDK): view enter/leave 不递归 children + on_event 路由未接线 — 待 SDK 侧补
52 lines
1.2 KiB
C
52 lines
1.2 KiB
C
/* logic/state.c — 计数业务态(taps/secs)+ 可选推送监听器(biz→UI)。
|
|
*
|
|
* 纯 C(无 meow_ui.h 依赖):状态 + getter/setter + 监听器。UI 经 logic_taps_bump()/
|
|
* logic_secs_add() 改状态;业务改后触发监听器(若已注册)通知 UI 刷新——契约 ①②(§B.1)。
|
|
*/
|
|
#include "logic.h"
|
|
#include <stddef.h>
|
|
|
|
static int g_taps = 0;
|
|
static int g_secs = 0;
|
|
static int g_prog = 0; /* demo 进度语义值 0..100(批③ 自 ui/demo/demo.c 上收) */
|
|
static logic_listener_fn g_listener = NULL;
|
|
static void *g_listener_ctx = NULL;
|
|
|
|
int logic_taps_get(void)
|
|
{
|
|
return g_taps;
|
|
}
|
|
void logic_taps_bump(void)
|
|
{
|
|
g_taps++;
|
|
if (g_listener) g_listener(LOGIC_EV_TAPS, g_listener_ctx);
|
|
}
|
|
|
|
int logic_secs_get(void)
|
|
{
|
|
return g_secs;
|
|
}
|
|
void logic_secs_add(int n)
|
|
{
|
|
g_secs += n;
|
|
if (g_listener) g_listener(LOGIC_EV_SECS, g_listener_ctx);
|
|
}
|
|
|
|
int logic_prog_get(void)
|
|
{
|
|
return g_prog;
|
|
}
|
|
void logic_prog_set(int p)
|
|
{
|
|
if (p < 0) p = 0;
|
|
if (p > 100) p = 100;
|
|
g_prog = p;
|
|
if (g_listener) g_listener(LOGIC_EV_PROG, g_listener_ctx);
|
|
}
|
|
|
|
void logic_set_listener(logic_listener_fn cb, void *ctx)
|
|
{
|
|
g_listener = cb;
|
|
g_listener_ctx = ctx;
|
|
}
|