魔盒最新版本,更新了充电检测,鸟叫,dp4对声音的控制,声音模块由于硬件问题暂未实测

This commit is contained in:
2026-09-09 15:32:50 +08:00
parent 3ab37b7845
commit b576f31113
22 changed files with 871 additions and 528 deletions
+17 -63
View File
@@ -14,7 +14,7 @@
#include "jb_product.h"
#include "app_function.h"
#include "usr_rtc.h"
#include "app_no_disturb.h"
/* ════════════════════════════════════════════════════════════════
* 全局变量
@@ -30,70 +30,26 @@ static volatile uint32_t timerMs;
#define JB_DND_START_MIN_OFFSET 10
#define JB_DND_END_HOUR_OFFSET 11
#define JB_DND_END_MIN_OFFSET 12
static uint8_t jbLastNoDisturbActive;
/* Return weekday with Monday=0, matching DP7 bytes 2..8. */
static uint8_t jbWeekdayMonday0(const struct sys_time *time)
{
static const uint8_t monthOffset[12] = {
0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4
};
uint16_t year = time->year;
uint8_t sunday0;
if (time->month < 3) {
year--;
}
sunday0 = (uint8_t)((year + year / 4U - year / 100U + year / 400U +
monthOffset[time->month - 1U] + time->day) % 7U);
return (uint8_t)((sunday0 + 6U) % 7U);
}
static void jbNoDisturbNormalize(uint8_t *cfg)
static void jbNoDisturbApply(uint8_t *cfg)
{
uint8_t i;
uint8_t weekdays = 0;
uint16_t start_minute;
uint16_t end_minute;
cfg[JB_DND_ENABLE_OFFSET] = !!cfg[JB_DND_ENABLE_OFFSET];
for (i = 0; i < 7; i++) {
cfg[JB_DND_WEEK_OFFSET + i] = !!cfg[JB_DND_WEEK_OFFSET + i];
}
}
static uint8_t jbNoDisturbScheduleValid(const uint8_t *cfg)
{
uint8_t i;
if (cfg[JB_DND_START_HOUR_OFFSET] >= 24 ||
cfg[JB_DND_END_HOUR_OFFSET] >= 24 ||
cfg[JB_DND_START_MIN_OFFSET] >= 60 ||
cfg[JB_DND_END_MIN_OFFSET] >= 60) {
return 0;
}
for (i = 0; i < 7; i++) {
if (cfg[JB_DND_WEEK_OFFSET + i]) {
return 1;
weekdays |= (uint8_t)(1U << i);
}
}
return 0;
}
static uint8_t jbNoDisturbActive(void)
{
/* Match the verified product behavior: DP7 byte 0 is the global
* no-disturb switch. Schedule bytes are retained and reported, but do
* not gate the local vibration wake path. */
return !!gDevData.no_disturb_enable[JB_DND_ENABLE_OFFSET];
}
static void jbNoDisturbUpdate(void)
{
uint8_t active = jbNoDisturbActive();
if (active == jbLastNoDisturbActive) {
return;
}
jbLastNoDisturbActive = active;
app_function_set_no_disturb(active);
start_minute = (uint16_t)(cfg[JB_DND_START_HOUR_OFFSET] * 60U +
cfg[JB_DND_START_MIN_OFFSET]);
end_minute = (uint16_t)(cfg[JB_DND_END_HOUR_OFFSET] * 60U +
cfg[JB_DND_END_MIN_OFFSET]);
app_no_disturb_configure(cfg[JB_DND_ENABLE_OFFSET], weekdays,
start_minute, end_minute);
}
/* ════════════════════════════════════════════════════════════════
@@ -110,11 +66,11 @@ void userInit(void)
gDevData.beep_trig = 0; /* DP4 声音开关 0=关 1=开 */
gDevData.battery = 0; /* DP5 电量上报 */
gDevData.shake_wake = 0; /* DP6 震动触发开机 0=关 1=开 */
memset(gDevData.no_disturb_enable, 0, 13); /* DP7 勿扰模式开关 */
memset(gDevData.no_disturb_enable, 0, APP_NO_DISTURB_CFG_LEN); /* DP7 勿扰模式开关 */
app_no_disturb_storage_load(gDevData.no_disturb_enable);
gDevData.charge = 0; /* CHARGE_0 (不支持充电) */
gDevData.reserva_dp3 = 0; /* DP10 预留DP3 */
jbLastNoDisturbActive = 0xff;
jbNoDisturbUpdate();
jbNoDisturbApply(gDevData.no_disturb_enable);
}
/* ════════════════════════════════════════════════════════════════
@@ -123,8 +79,6 @@ void userInit(void)
* ════════════════════════════════════════════════════════════════ */
void userHandle(void)
{
jbNoDisturbUpdate();
/* ── 可上报 DP (RO / RW): 用户数据采集 ── */
// gDevData.power = read_sensor(); /* DP0 开关 */
// gDevData.play_mode = read_sensor(); /* DP1 自动模式 */
@@ -196,8 +150,8 @@ int8_t jbEventProcess(jb_event_info_t *info, jb_data_point_t *ctrl)
case DP_ID_NO_DISTURB_ENABLE:
memcpy(gDevData.no_disturb_enable, ctrl->no_disturb_enable,
JB_DND_LEN);
jbNoDisturbNormalize(gDevData.no_disturb_enable);
jbNoDisturbUpdate();
jbNoDisturbApply(gDevData.no_disturb_enable);
app_no_disturb_storage_save(gDevData.no_disturb_enable);
break;
/* ── DP10 预留DP3 (uint32) ── */
+10
View File
@@ -36,6 +36,7 @@
#include "system/includes.h"
#include "app_config.h"
#include "asm/dac.h"
#include "app_main.h"
#include "app_task.h"
#include "user_cfg.h"
@@ -52,11 +53,13 @@
#include "app_pair.h"
#include "app_boot.h"
#include "app_function.h"
#include "app_audio_debug.h"
#include "app_mode.h"
#include "app_led.h"
#include "key_manager.h"
#include "asm/power/power_api.h"
#define LOG_TAG_CONST APP
#define LOG_TAG "[USR_JB]"
#define LOG_INFO_ENABLE
@@ -285,6 +288,13 @@ void usr_jb_init(void)
{
usr_log_boot_version(); /* UART 已在 app_main 起来,按键判定前就能看到版本 */
MAGIC_AUDIO_LOG("诊断固件启动:编译=%s %s,UART0使能=%dTX引脚编号=%u,波特率=%u",
__DATE__, __TIME__, TCFG_UART0_ENABLE,
(unsigned)TCFG_UART0_TX_PORT, (unsigned)TCFG_UART0_BAUDRATE);
MAGIC_AUDIO_LOG("配置:提示音=%dMP3=%dDAC=%dDAC通道=%dDAC模式=%d,音量类型=%d",
TCFG_KEY_TONE_EN, TCFG_DEC_MP3_ENABLE, TCFG_AUDIO_DAC_ENABLE,
TCFG_AUDIO_DAC_CONNECT_MODE, TCFG_AUDIO_DAC_MODE, SYS_VOL_TYPE);
MAGIC_AUDIO_LOG("鸟叫资源路径=%s,中文显示请使用UTF-8", SDFILE_RES_ROOT_PATH"bird.mp3");
bsp_hw_init();
app_led_init(); /* 提前到按键判定之前:3s/5s/拒绝开机低电闪都要直接用灯效事件表 */