remove long press for volume buttons
This commit is contained in:
@@ -100,10 +100,9 @@ timer tm;
|
||||
// 改动原因:DAC寄存器按2个码值对应1dB,按键每次调节步进固定为2,确保与硬件音量刻度一致。
|
||||
#define C1_DAC_VOL_STEP 0x02
|
||||
|
||||
// 改动原因:C1的TIMER_PERIOD为20ms,按DS1同类短按/长按模型换算阈值;长按1s后每100ms连续调节音量。
|
||||
// 改动原因:C1的TIMER_PERIOD为20ms,按DS1同类短按/长按模型换算阈值;mode/mic 仍用 LONG 区分短按窗口;音量键已取消长按连调故不再使用 REPEAT 间隔宏。
|
||||
#define C1_KEY_SHORT_TICKS 1
|
||||
#define C1_KEY_LONG_TICKS 50
|
||||
#define C1_KEY_REPEAT_TICKS 5
|
||||
// 改动原因:新增C1模式持久化文件路径,使用LittleFS保存mode按键状态,保证断电重启后可恢复。
|
||||
#define C1_MODE_VALUE_PATH "c1_mode_value"
|
||||
|
||||
@@ -374,16 +373,13 @@ void AudioHwRemote2(streaming chanend c, client interface i2c_master_if i2c, cli
|
||||
unsigned old_dac_vol = 0;
|
||||
unsigned old_adc_vol = 0;
|
||||
unsigned old_dac_mode = 0;
|
||||
// 改动原因:按DS1按键状态机思路保存每个按键的持续时间,用于区分短按和长按连续动作。
|
||||
// 改动原因:按DS1按键状态机思路保存每个按键按下时长;mode/mic 仍用短/长按窗口区分,音量键仅用于释放时短按去抖(不支持长按连调)。
|
||||
unsigned mode_press_ticks = 0;
|
||||
unsigned vol_down_press_ticks = 0;
|
||||
unsigned mic_mute_press_ticks = 0;
|
||||
unsigned vol_up_press_ticks = 0;
|
||||
// 改动原因:mic mute红灯通过interface下发到tile1,仅在状态变化时发送,减少无意义跨tile调用。
|
||||
unsigned last_mute_switch_for_led = 0xFFFFFFFF;
|
||||
// 改动原因:长按音量键已经连续触发后,释放时不能再执行一次短按动作。
|
||||
unsigned vol_down_long_action = 0;
|
||||
unsigned vol_up_long_action = 0;
|
||||
tmr :> time; /* Input time */
|
||||
time += TIMER_PERIOD; /* Add time */
|
||||
se_tmr :> se_time;
|
||||
@@ -529,7 +525,7 @@ void AudioHwRemote2(streaming chanend c, client interface i2c_master_if i2c, cli
|
||||
GET_SHARED_GLOBAL(new_dac_mode, g_new_dac_mode);
|
||||
|
||||
// --- C1实体按键逻辑处理 ---
|
||||
// 改动原因:参考DS1按键处理模型,在主定时循环中读取端口、按低电平有效判断按下,并用计数器区分短按/长按。
|
||||
// 改动原因:参考DS1按键处理模型,在主定时循环中读取端口、按低电平有效判断按下;mode/mic 用计数器区分短按窗口,音量键仅在释放时步进一档(无长按连调)。
|
||||
{
|
||||
unsigned button_state;
|
||||
unsigned mode_pressed;
|
||||
@@ -554,8 +550,6 @@ void AudioHwRemote2(streaming chanend c, client interface i2c_master_if i2c, cli
|
||||
vol_down_press_ticks = 0;
|
||||
mic_mute_press_ticks = 0;
|
||||
vol_up_press_ticks = 0;
|
||||
vol_down_long_action = 0;
|
||||
vol_up_long_action = 0;
|
||||
}
|
||||
else if (vol_down_pressed)
|
||||
{
|
||||
@@ -564,32 +558,6 @@ void AudioHwRemote2(streaming chanend c, client interface i2c_master_if i2c, cli
|
||||
mode_press_ticks = 0;
|
||||
mic_mute_press_ticks = 0;
|
||||
vol_up_press_ticks = 0;
|
||||
vol_up_long_action = 0;
|
||||
// 改动原因:音量-长按沿用DS1连续调节体验,达到阈值后每100ms递减一次寄存器音量。
|
||||
if ((vol_down_press_ticks >= C1_KEY_LONG_TICKS) && ((vol_down_press_ticks % C1_KEY_REPEAT_TICKS) == 0))
|
||||
{
|
||||
unsigned current_dac_vol;
|
||||
GET_SHARED_GLOBAL(current_dac_vol, g_dac_vol);
|
||||
// 改动原因:当音量在最小可听值0x4B时再次按减音量,直接进入mute(0x00);满足“最小再按一下直接静音”需求。
|
||||
if (current_dac_vol == C1_DAC_VOL_MIN)
|
||||
{
|
||||
current_dac_vol = C1_DAC_MUTE;
|
||||
SET_SHARED_GLOBAL(g_dac_vol, current_dac_vol);
|
||||
vol_down_long_action = 1;
|
||||
debug_printf("C1 key volume down long to mute: %d\n", current_dac_vol);
|
||||
}
|
||||
// 改动原因:按键每次减2(1dB);并在接近最小值时钳位到0x4B,避免落入无定义区间。
|
||||
else if (current_dac_vol > C1_DAC_VOL_MIN)
|
||||
{
|
||||
if (current_dac_vol <= (C1_DAC_VOL_MIN + C1_DAC_VOL_STEP))
|
||||
current_dac_vol = C1_DAC_VOL_MIN;
|
||||
else
|
||||
current_dac_vol -= C1_DAC_VOL_STEP;
|
||||
SET_SHARED_GLOBAL(g_dac_vol, current_dac_vol);
|
||||
vol_down_long_action = 1;
|
||||
debug_printf("C1 key volume down long: %d\n", current_dac_vol);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (mic_mute_pressed)
|
||||
{
|
||||
@@ -598,8 +566,6 @@ void AudioHwRemote2(streaming chanend c, client interface i2c_master_if i2c, cli
|
||||
mode_press_ticks = 0;
|
||||
vol_down_press_ticks = 0;
|
||||
vol_up_press_ticks = 0;
|
||||
vol_down_long_action = 0;
|
||||
vol_up_long_action = 0;
|
||||
}
|
||||
else if (vol_up_pressed)
|
||||
{
|
||||
@@ -608,32 +574,6 @@ void AudioHwRemote2(streaming chanend c, client interface i2c_master_if i2c, cli
|
||||
mode_press_ticks = 0;
|
||||
vol_down_press_ticks = 0;
|
||||
mic_mute_press_ticks = 0;
|
||||
vol_down_long_action = 0;
|
||||
// 改动原因:音量+长按沿用DS1连续调节体验,达到阈值后每100ms递增一次寄存器音量。
|
||||
if ((vol_up_press_ticks >= C1_KEY_LONG_TICKS) && ((vol_up_press_ticks % C1_KEY_REPEAT_TICKS) == 0))
|
||||
{
|
||||
unsigned current_dac_vol;
|
||||
GET_SHARED_GLOBAL(current_dac_vol, g_dac_vol);
|
||||
// 改动原因:从mute恢复时先跳到最小可听值0x4B,再按步进2上调,避免出现0x02/0x04等非法过渡值。
|
||||
if (current_dac_vol < C1_DAC_VOL_MIN)
|
||||
{
|
||||
current_dac_vol = C1_DAC_VOL_MIN;
|
||||
SET_SHARED_GLOBAL(g_dac_vol, current_dac_vol);
|
||||
vol_up_long_action = 1;
|
||||
debug_printf("C1 key volume up long from mute: %d\n", current_dac_vol);
|
||||
}
|
||||
// 改动原因:按键每次加2(1dB);在接近最大值时钳位到0xCF,避免超过允许范围。
|
||||
else if (current_dac_vol < C1_DAC_VOL_MAX)
|
||||
{
|
||||
if (current_dac_vol >= (C1_DAC_VOL_MAX - C1_DAC_VOL_STEP))
|
||||
current_dac_vol = C1_DAC_VOL_MAX;
|
||||
else
|
||||
current_dac_vol += C1_DAC_VOL_STEP;
|
||||
SET_SHARED_GLOBAL(g_dac_vol, current_dac_vol);
|
||||
vol_up_long_action = 1;
|
||||
debug_printf("C1 key volume up long: %d\n", current_dac_vol);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -654,12 +594,12 @@ void AudioHwRemote2(streaming chanend c, client interface i2c_master_if i2c, cli
|
||||
while(1);
|
||||
}
|
||||
|
||||
// 改动原因:音量短按只调节一步;若同一次按压已进入长按连续调节,则释放时不再重复调节。
|
||||
if ((vol_down_press_ticks >= C1_KEY_SHORT_TICKS) && (vol_down_press_ticks < C1_KEY_LONG_TICKS) && (vol_down_long_action == 0))
|
||||
// 改动原因:音量键仅短按——释放时若已满足去抖时长则步进一档,与按住时长无关(已取消长按连调)。
|
||||
if (vol_down_press_ticks >= C1_KEY_SHORT_TICKS)
|
||||
{
|
||||
unsigned current_dac_vol;
|
||||
GET_SHARED_GLOBAL(current_dac_vol, g_dac_vol);
|
||||
// 改动原因:短按也执行“最小值再按一次直达mute(0x00)”规则,与长按路径保持一致行为。
|
||||
// 改动原因:短按执行“最小值再按一次直达mute(0x00)”规则。
|
||||
if (current_dac_vol == C1_DAC_VOL_MIN)
|
||||
{
|
||||
current_dac_vol = C1_DAC_MUTE;
|
||||
@@ -702,8 +642,8 @@ void AudioHwRemote2(streaming chanend c, client interface i2c_master_if i2c, cli
|
||||
debug_printf("C1 key mic mute toggle: %d\n", current_mute_switch);
|
||||
}
|
||||
|
||||
// 改动原因:音量短按只调节一步;若同一次按压已进入长按连续调节,则释放时不再重复调节。
|
||||
if ((vol_up_press_ticks >= C1_KEY_SHORT_TICKS) && (vol_up_press_ticks < C1_KEY_LONG_TICKS) && (vol_up_long_action == 0))
|
||||
// 改动原因:音量键仅短按——释放时若已满足去抖时长则步进一档(已取消长按连调)。
|
||||
if (vol_up_press_ticks >= C1_KEY_SHORT_TICKS)
|
||||
{
|
||||
unsigned current_dac_vol;
|
||||
GET_SHARED_GLOBAL(current_dac_vol, g_dac_vol);
|
||||
@@ -732,8 +672,6 @@ void AudioHwRemote2(streaming chanend c, client interface i2c_master_if i2c, cli
|
||||
vol_down_press_ticks = 0;
|
||||
mic_mute_press_ticks = 0;
|
||||
vol_up_press_ticks = 0;
|
||||
vol_down_long_action = 0;
|
||||
vol_up_long_action = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user