鉴于性能过剩,输入口不再支持设置上升沿下降沿触发,修改为默认同时支持上升下降触发,由用户层代码判断上下。
This commit is contained in:
parent
802b9bc153
commit
c139a67dff
|
@ -54,7 +54,7 @@ void Button_GrayLevel::Set(Pin key, Pin relay, bool relayInvert)
|
|||
Key.Set(key);
|
||||
|
||||
// 中断过滤模式
|
||||
Key.Mode = InputPort::Both;
|
||||
//Key.Mode = InputPort::Both;
|
||||
|
||||
Key.ShakeTime = 20;
|
||||
//Key.Register(OnPress, this);
|
||||
|
|
|
@ -331,43 +331,35 @@ void InputPort::OnPress(bool down)
|
|||
*/
|
||||
|
||||
// 状态机。上一次和这一次状态相同时,认为出错,抛弃
|
||||
if(down && _Value == Rising) return;
|
||||
if(!down && _Value != Rising) return;
|
||||
//if(down && _Value == Rising) return;
|
||||
//if(!down && _Value != Rising) return;
|
||||
|
||||
UInt64 now = Sys.Ms();
|
||||
// 这一次触发离上一次太近,算作抖动忽略掉
|
||||
if(_Last > 0 && ShakeTime > 0 && now - _Last < ShakeTime) return;
|
||||
//if(_Last > 0 && ShakeTime > 0 && ((Int64)now - (Int64)_Last) < ShakeTime) return;
|
||||
_Last = now;
|
||||
|
||||
// 允许两个值并存
|
||||
_Value = down ? Rising : Falling;
|
||||
|
||||
if(down)
|
||||
_Start = now;
|
||||
else
|
||||
{
|
||||
PressTime = now - _Start;
|
||||
}
|
||||
PressTime = now - _Start;
|
||||
|
||||
if(down)
|
||||
/*if(down)
|
||||
{
|
||||
if((Mode & Rising) == 0) return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if((Mode & Falling) == 0) return;
|
||||
}
|
||||
}*/
|
||||
|
||||
if(HardEvent || !_IRQ)
|
||||
{
|
||||
//if(Handler) Handler(this, down, Param);
|
||||
Press(*this, down);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 允许两个值并存
|
||||
//_Value |= down ? Rising : Falling;
|
||||
Sys.SetTask(_task, true, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void InputPort::InputTask(void* param)
|
||||
|
@ -376,7 +368,7 @@ void InputPort::InputTask(void* param)
|
|||
byte v = port->_Value;
|
||||
if(!v) return;
|
||||
|
||||
v &= port->Mode;
|
||||
//v &= port->Mode;
|
||||
if(v & Rising) port->Press(*port, true);
|
||||
if(v & Falling) port->Press(*port, false);
|
||||
}
|
||||
|
@ -401,8 +393,8 @@ void InputPort::OnOpen(void* param)
|
|||
debug_printf(" 上升沿");
|
||||
else if(Pull == DOWN)
|
||||
debug_printf(" 下降沿");
|
||||
if(Mode & Rising) debug_printf(" 按下");
|
||||
if(Mode & Falling) debug_printf(" 弹起");
|
||||
//if(Mode & Rising) debug_printf(" 按下");
|
||||
//if(Mode & Falling) debug_printf(" 弹起");
|
||||
|
||||
bool fg = false;
|
||||
#endif
|
||||
|
|
|
@ -149,12 +149,12 @@ public:
|
|||
// 读取委托
|
||||
typedef void (*IOReadHandler)(InputPort* port, bool down, void* param);
|
||||
|
||||
ushort ShakeTime = 0; // 抖动时间。毫秒
|
||||
ushort PressTime = 0; // 长按时间。毫秒
|
||||
ushort ShakeTime = 0; // 设置 抖动时间。毫秒
|
||||
ushort PressTime = 0; // 获取 长按时间。毫秒
|
||||
byte Invert = 2; // 是否倒置输入输出。默认2表示自动检测
|
||||
bool Floating = true; // 是否浮空输入
|
||||
PuPd Pull = UP; // 上拉下拉电阻
|
||||
Trigger Mode = Both; // 触发模式,上升沿下降沿
|
||||
//Trigger Mode = Both; // 触发模式,上升沿下降沿
|
||||
bool HardEvent = false;// 是否使用硬件事件。默认false
|
||||
|
||||
Delegate2<InputPort&, bool> Press; // 按下事件
|
||||
|
|
|
@ -14,7 +14,7 @@ bool IC74HC165MOR::Open()
|
|||
if(Opened)return true;
|
||||
|
||||
_PL.HardEvent = true; // 硬中断
|
||||
_PL.Mode = InputPort::Rising; // 上升沿
|
||||
//_PL.Mode = InputPort::Rising; // 上升沿
|
||||
//_PL.Register([](InputPort* port, bool down, void* param){ ((IC74HC165MOR*)param)->Trigger();},this);
|
||||
_PL.Press.Bind(&IC74HC165MOR::OnTrigger, this);
|
||||
_PL.UsePress();
|
||||
|
@ -23,7 +23,7 @@ bool IC74HC165MOR::Open()
|
|||
if(!_sckHighSpeed)
|
||||
{
|
||||
_PL.HardEvent = true; // 硬中断
|
||||
_SCK.Mode = InputPort::Rising; // 上升沿
|
||||
//_SCK.Mode = InputPort::Rising; // 上升沿
|
||||
//_SCK.Register([](InputPort* port, bool down, void* param){ ((IC74HC165MOR*)param)->ReaBit();},this);
|
||||
_SCK.Press.Bind(&IC74HC165MOR::OnReaBit, this);
|
||||
_SCK.UsePress();
|
||||
|
|
|
@ -246,7 +246,7 @@ void NRF24L01::Init(Spi* spi, Pin ce, Pin irq, Pin power)
|
|||
//Irq->ShakeTime = 2;
|
||||
Irq.Floating = false;
|
||||
Irq.Pull = InputPort::UP;
|
||||
Irq.Mode = InputPort::Rising;
|
||||
//Irq.Mode = InputPort::Rising;
|
||||
Irq.HardEvent = true;
|
||||
Irq.Init(irq, true);
|
||||
//if(!Irq.Register(OnIRQ, this)) Irq.HardEvent = false;
|
||||
|
|
|
@ -366,7 +366,7 @@ void W5500::Init(Spi* spi, Pin irq, Pin rst)
|
|||
//Irq.ShakeTime = 0;
|
||||
Irq.Floating = false;
|
||||
Irq.Pull = InputPort::UP;
|
||||
Irq.Mode = InputPort::Rising;
|
||||
//Irq.Mode = InputPort::Rising;
|
||||
Irq.HardEvent = true;
|
||||
//Irq.Set(irq);
|
||||
Irq.Init(irq, true);
|
||||
|
@ -758,7 +758,7 @@ ISocket* W5500::CreateSocket(NetType type)
|
|||
debug_printf("没有空余的Socket可用了 !\r\n");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
HardSocket* socket = nullptr;
|
||||
switch(type)
|
||||
{
|
||||
|
@ -770,13 +770,13 @@ ISocket* W5500::CreateSocket(NetType type)
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if(socket)
|
||||
{
|
||||
socket->Index = Sockets.Count();
|
||||
Sockets.Add(socket);
|
||||
}
|
||||
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
|
|
|
@ -325,7 +325,7 @@ bool IsOnlyExOfInt(const InputPort* pt, int idx)
|
|||
return true;
|
||||
}
|
||||
|
||||
InputPort::Trigger GetTrigger(InputPort::Trigger mode, bool invert)
|
||||
/*InputPort::Trigger GetTrigger(InputPort::Trigger mode, bool invert)
|
||||
{
|
||||
if(invert && mode != InputPort::Both)
|
||||
{
|
||||
|
@ -337,7 +337,7 @@ InputPort::Trigger GetTrigger(InputPort::Trigger mode, bool invert)
|
|||
}
|
||||
|
||||
return mode;
|
||||
}
|
||||
}*/
|
||||
|
||||
void InputPort::ClosePin()
|
||||
{
|
||||
|
@ -348,7 +348,7 @@ void InputPort::ClosePin()
|
|||
{
|
||||
st->Port = nullptr;
|
||||
|
||||
SetEXIT(idx, false, GetTrigger(Mode, Invert));
|
||||
SetEXIT(idx, false, InputPort::Both);
|
||||
if(!IsOnlyExOfInt(this, idx))return;
|
||||
Interrupt.Deactivate(PORT_IRQns[idx]);
|
||||
}
|
||||
|
@ -397,7 +397,7 @@ bool InputPort::OnRegister()
|
|||
GPIO_EXTILineConfig(gi, idx);
|
||||
#endif
|
||||
|
||||
SetEXIT(idx, true, GetTrigger(Mode, Invert));
|
||||
SetEXIT(idx, true, InputPort::Both);
|
||||
|
||||
// 打开并设置EXTI中断为低优先级
|
||||
Interrupt.SetPriority(PORT_IRQns[idx], 1);
|
||||
|
|
|
@ -363,7 +363,7 @@ bool IsOnlyExOfInt(const InputPort* pt, int idx)
|
|||
return true;
|
||||
}
|
||||
|
||||
InputPort::Trigger GetTrigger(InputPort::Trigger mode, bool invert)
|
||||
/*InputPort::Trigger GetTrigger(InputPort::Trigger mode, bool invert)
|
||||
{
|
||||
if(invert && mode != InputPort::Both)
|
||||
{
|
||||
|
@ -375,7 +375,7 @@ InputPort::Trigger GetTrigger(InputPort::Trigger mode, bool invert)
|
|||
}
|
||||
|
||||
return mode;
|
||||
}
|
||||
}*/
|
||||
|
||||
void InputPort::ClosePin()
|
||||
{
|
||||
|
@ -386,7 +386,7 @@ void InputPort::ClosePin()
|
|||
{
|
||||
st->Port = nullptr;
|
||||
|
||||
SetEXIT(idx, false, GetTrigger(Mode, Invert));
|
||||
SetEXIT(idx, false, InputPort::Both);
|
||||
if(!IsOnlyExOfInt(this, idx))return;
|
||||
Interrupt.Deactivate(PORT_IRQns[idx]);
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ bool InputPort::OnRegister()
|
|||
GPIO_EXTILineConfig(gi, idx);
|
||||
#endif
|
||||
|
||||
SetEXIT(idx, true, GetTrigger(Mode, Invert));
|
||||
SetEXIT(idx, true, InputPort::Both);
|
||||
|
||||
// 打开并设置EXTI中断为低优先级
|
||||
Interrupt.SetPriority(PORT_IRQns[idx], 1);
|
||||
|
|
Loading…
Reference in New Issue