重构输入口中断事件,0801上按键测试通过
This commit is contained in:
parent
7e6df902b8
commit
2b556a9410
|
@ -25,7 +25,11 @@ void Button::Set(Pin key, Pin led, Pin relay)
|
|||
void Button::Set(Pin key, Pin led, bool ledInvert, Pin relay, bool relayInvert)
|
||||
{
|
||||
Key.Set(key);
|
||||
Key.Register(OnPress, this);
|
||||
//Key.Register(OnPress, this);
|
||||
//Key.Press = OnPress;
|
||||
Key.Press.Bind(&Button::OnPress, this);
|
||||
Key.UsePress();
|
||||
//Key.Register(Delegate2<InputPort&, bool>(&Button::OnPress, this))
|
||||
Key.Open();
|
||||
|
||||
if(led != P0)
|
||||
|
@ -40,13 +44,13 @@ void Button::Set(Pin key, Pin led, bool ledInvert, Pin relay, bool relayInvert)
|
|||
}
|
||||
}
|
||||
|
||||
void Button::OnPress(InputPort* port, bool down, void* param)
|
||||
/*void Button::OnPress(InputPort* port, bool down, void* param)
|
||||
{
|
||||
Button* btn = (Button*)param;
|
||||
if(btn) btn->OnPress(port->_Pin, down);
|
||||
}
|
||||
}*/
|
||||
|
||||
void Button::OnPress(Pin pin, bool down)
|
||||
void Button::OnPress(InputPort& port, bool down)
|
||||
{
|
||||
// 每次按下弹起,都取反状态
|
||||
if(!down)
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
class Button : public Object, public ByteDataPort
|
||||
{
|
||||
private:
|
||||
static void OnPress(InputPort* port, bool down, void* param);
|
||||
void OnPress(Pin pin, bool down);
|
||||
//static void OnPress(InputPort* port, bool down, void* param);
|
||||
void OnPress(InputPort& port, bool down);
|
||||
|
||||
//EventHandler _Handler;
|
||||
//void* _Param;
|
||||
|
|
|
@ -48,7 +48,9 @@ void Button_GrayLevel::Set(Pin key, Pin relay, bool relayInvert)
|
|||
Key.Mode = InputPort::Both;
|
||||
|
||||
Key.ShakeTime = 40;
|
||||
Key.Register(OnKeyPress, this);
|
||||
//Key.Register(OnPress, this);
|
||||
Key.Press.Bind(&Button_GrayLevel::OnPress, this);
|
||||
Key.UsePress();
|
||||
Key.Open();
|
||||
|
||||
if (relay != P0) Relay.Init(relay, relayInvert).Open();
|
||||
|
@ -92,13 +94,13 @@ void Button_GrayLevel::GrayLevelDown()
|
|||
}
|
||||
}
|
||||
|
||||
void Button_GrayLevel::OnKeyPress(InputPort* port, bool down, void* param)
|
||||
/*void Button_GrayLevel::OnPress(InputPort* port, bool down, void* param)
|
||||
{
|
||||
Button_GrayLevel* btn = (Button_GrayLevel*)param;
|
||||
if (btn) btn->OnKeyPress(port, down);
|
||||
}
|
||||
if (btn) btn->OnPress(port, down);
|
||||
}*/
|
||||
|
||||
void Button_GrayLevel::OnKeyPress(InputPort* port, bool down)
|
||||
void Button_GrayLevel::OnPress(InputPort& port, bool down)
|
||||
{
|
||||
// 每次按下弹起,都取反状态
|
||||
/*if(down)
|
||||
|
@ -111,7 +113,7 @@ void Button_GrayLevel::OnKeyPress(InputPort* port, bool down)
|
|||
{
|
||||
if (_Value && EnableDelayClose)
|
||||
{
|
||||
ushort time = port->PressTime;
|
||||
ushort time = port.PressTime;
|
||||
if (time > 1500)
|
||||
{
|
||||
debug_printf("DelayClose ");
|
||||
|
@ -119,20 +121,20 @@ void Button_GrayLevel::OnKeyPress(InputPort* port, bool down)
|
|||
{
|
||||
debug_printf("60s\r\n");
|
||||
DelayClose2(60 * 1000);
|
||||
port->PressTime = 0; // 保险一下,以免在延时关闭更新状态的时候误判造成重启
|
||||
port.PressTime = 0; // 保险一下,以免在延时关闭更新状态的时候误判造成重启
|
||||
return;
|
||||
}
|
||||
if(time < 3800)
|
||||
{
|
||||
debug_printf("15s\r\n");
|
||||
DelayClose2(15 * 1000);
|
||||
port->PressTime = 0; // 保险一下,以免在延时关闭更新状态的时候误判造成重启
|
||||
port.PressTime = 0; // 保险一下,以免在延时关闭更新状态的时候误判造成重启
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 不启用长按时,长按操作当正常处理
|
||||
if (port->PressTime <= 1500 || !EnableDelayClose)
|
||||
if (port.PressTime <= 1500 || !EnableDelayClose)
|
||||
{
|
||||
SetValue(!_Value);
|
||||
if (_task2)
|
||||
|
|
|
@ -65,8 +65,8 @@ private:
|
|||
bool _Value; // 状态
|
||||
ushort Reserved; // 补足对齐问题
|
||||
|
||||
static void OnKeyPress(InputPort* port, bool down, void* param);
|
||||
void OnKeyPress(InputPort* port, bool down);
|
||||
//static void OnPress(InputPort* port, bool down, void* param);
|
||||
void OnPress(InputPort& port, bool down);
|
||||
|
||||
public:
|
||||
static byte OnGrayLevel; // 开灯时 led 灰度
|
||||
|
|
|
@ -18,7 +18,9 @@ Button_magnetic::Button_magnetic(Pin key, Pin led, Pin relay_pin1, Pin relay_pin
|
|||
Init();
|
||||
|
||||
Key = new InputPort(key);
|
||||
Key->Register(OnPress, this);
|
||||
//Key->Register(OnPress, this);
|
||||
Key->Press.Bind(&Button_magnetic::OnPress, this);
|
||||
Key->UsePress();
|
||||
|
||||
if(led != P0) Led = new OutputPort(led);
|
||||
if(relay_pin1 != P0) Relay_pack1 = new OutputPort(relay_pin1);
|
||||
|
@ -31,7 +33,9 @@ Button_magnetic::Button_magnetic(Pin key, Pin led, bool ledInvert, Pin relay_pin
|
|||
Init();
|
||||
|
||||
Key = new InputPort(key);
|
||||
Key->Register(OnPress, this);
|
||||
//Key->Register(OnPress, this);
|
||||
Key->Press.Bind(&Button_magnetic::OnPress, this);
|
||||
Key->UsePress();
|
||||
|
||||
if(led != P0) Led = new OutputPort(led, ledInvert);
|
||||
if(relay_pin1 != P0) Relay_pack1 = new OutputPort(relay_pin1, relayInvert1);
|
||||
|
@ -59,13 +63,13 @@ Button_magnetic::~Button_magnetic()
|
|||
}
|
||||
|
||||
|
||||
void Button_magnetic::OnPress(InputPort* port, bool down, void* param)
|
||||
/*void Button_magnetic::OnPress(InputPort* port, bool down, void* param)
|
||||
{
|
||||
Button_magnetic * btn = (Button_magnetic*)param;
|
||||
if(btn) btn->OnPress(port->_Pin, down);
|
||||
}
|
||||
}*/
|
||||
|
||||
void Button_magnetic::OnPress(Pin pin, bool down)
|
||||
void Button_magnetic::OnPress(InputPort& port, bool down)
|
||||
{
|
||||
// 每次按下弹起,都取反状态
|
||||
if(!down)
|
||||
|
|
|
@ -17,8 +17,8 @@ class Button_magnetic
|
|||
private:
|
||||
void Init();
|
||||
|
||||
static void OnPress(InputPort* port, bool down, void* param);
|
||||
void OnPress(Pin pin, bool down);
|
||||
//static void OnPress(InputPort* port, bool down, void* param);
|
||||
void OnPress(InputPort& port, bool down);
|
||||
|
||||
//EventHandler _Handler;
|
||||
//void* _Param;
|
||||
|
|
|
@ -20,12 +20,14 @@ void PulsePort::Open()
|
|||
if (!Port) return;
|
||||
|
||||
Port->HardEvent = true;
|
||||
if (!Port->Register([](InputPort* port, bool down, void* param) {((PulsePort*)param)->OnPress(down); }, this))
|
||||
/*if (!Port->Register([](InputPort* port, bool down, void* param) {((PulsePort*)param)->OnPress(down); }, this))
|
||||
{
|
||||
debug_printf("PulsePort 注册失败/r/n");
|
||||
// 注册失败就返回 不要再往下了 没意义
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
Port->Press.Bind(&PulsePort::OnPress, this);
|
||||
Port->UsePress();
|
||||
Port->Open();
|
||||
|
||||
Opened = true;
|
||||
|
@ -40,7 +42,7 @@ void PulsePort::Close()
|
|||
Opened = false;
|
||||
}
|
||||
|
||||
void PulsePort::OnPress(bool down)
|
||||
void PulsePort::OnPress(InputPort& port, bool down)
|
||||
{
|
||||
// 只有弹起来才计算
|
||||
if (down) return;
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
|
||||
private:
|
||||
// 内部中断函数
|
||||
void OnPress(bool down);
|
||||
void OnPress(InputPort& port, bool down);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -20,7 +20,9 @@ Sensor::Sensor(Pin key, Pin led, Pin buzzer)
|
|||
Init();
|
||||
|
||||
Key = new InputPort(key);
|
||||
Key->Register(OnPress, this);
|
||||
//Key->Register(OnPress, this);
|
||||
Key->Press.Bind(&Sensor::OnPress, this);
|
||||
Key->UsePress();
|
||||
|
||||
if(led != P0) Led = new OutputPort(led);
|
||||
if(buzzer != P0) Buzzer = new OutputPort(buzzer);
|
||||
|
@ -31,7 +33,9 @@ Sensor::Sensor(Pin key, Pin led, bool ledInvert, Pin buzzer, bool buzzerInvert)
|
|||
Init();
|
||||
|
||||
Key = new InputPort(key);
|
||||
Key->Register(OnPress, this);
|
||||
//Key->Register(OnPress, this);
|
||||
Key->Press.Bind(&Sensor::OnPress, this);
|
||||
Key->UsePress();
|
||||
|
||||
if(led != P0) Led = new OutputPort(led, ledInvert);
|
||||
if(buzzer != P0) Buzzer = new OutputPort(key, buzzerInvert);
|
||||
|
@ -51,13 +55,13 @@ Sensor::~Sensor()
|
|||
Mag = nullptr;
|
||||
}
|
||||
|
||||
void Sensor::OnPress(InputPort* port, bool down, void* param)
|
||||
/*void Sensor::OnPress(InputPort* port, bool down, void* param)
|
||||
{
|
||||
Sensor* btn = (Sensor*)param;
|
||||
if(btn) btn->OnPress(port->_Pin, down);
|
||||
}
|
||||
}*/
|
||||
|
||||
void Sensor::OnPress(Pin pin, bool down)
|
||||
void Sensor::OnPress(InputPort& port, bool down)
|
||||
{
|
||||
|
||||
if(!down)
|
||||
|
|
|
@ -39,7 +39,7 @@ private:
|
|||
void Init();
|
||||
|
||||
static void OnPress(InputPort* port, bool down, void* param);
|
||||
void OnPress(Pin pin, bool down);
|
||||
void OnPress(InputPort& port, bool down);
|
||||
|
||||
//EventHandler _Handler;
|
||||
//void* _Param;
|
||||
|
|
|
@ -115,17 +115,19 @@ void ButtonOnpress(InputPort* port, bool down, void* param)
|
|||
AP0103::OnPress(port, down);
|
||||
}
|
||||
|
||||
void AP0103::InitButtons(InputPort::IOReadHandler press)
|
||||
void AP0103::InitButtons(const Delegate2<InputPort&, bool>& press)
|
||||
{
|
||||
for (int i = 0; i < ButtonPins.Count(); i++)
|
||||
{
|
||||
auto port = new InputPort(ButtonPins[i]);
|
||||
port->Mode = InputPort::Both;
|
||||
//port->Mode = InputPort::Both;
|
||||
port->Invert = true;
|
||||
if (press)
|
||||
/*if (press)
|
||||
port->Register(press, (void*)i);
|
||||
else
|
||||
port->Register(ButtonOnpress, (void*)i);
|
||||
port->Register(ButtonOnpress, (void*)i);*/
|
||||
port->Press = press;
|
||||
port->UsePress();
|
||||
port->Open();
|
||||
Buttons.Add(port);
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
void Register(int index, IDataPort& dp);
|
||||
|
||||
void InitLeds();
|
||||
void InitButtons(InputPort::IOReadHandler press = nullptr);
|
||||
void InitButtons(const Delegate2<InputPort&, bool>& press);
|
||||
|
||||
// 打开以太网W5500
|
||||
ISocketHost* Create5500();
|
||||
|
|
|
@ -115,17 +115,19 @@ void ButtonOnpress(InputPort* port, bool down, void* param)
|
|||
AP0104::OnPress(port, down);
|
||||
}
|
||||
|
||||
void AP0104::InitButtons(InputPort::IOReadHandler press)
|
||||
void AP0104::InitButtons(const Delegate2<InputPort&, bool>& press)
|
||||
{
|
||||
for (int i = 0; i < ButtonPins.Count(); i++)
|
||||
{
|
||||
auto port = new InputPort(ButtonPins[i]);
|
||||
port->Mode = InputPort::Both;
|
||||
//port->Mode = InputPort::Both;
|
||||
port->Invert = true;
|
||||
if (press)
|
||||
/*if (press)
|
||||
port->Register(press, (void*)i);
|
||||
else
|
||||
port->Register(ButtonOnpress, (void*)i);
|
||||
port->Register(ButtonOnpress, (void*)i);*/
|
||||
port->Press = press;
|
||||
port->UsePress();
|
||||
port->Open();
|
||||
Buttons.Add(port);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
void Register(int index, IDataPort& dp);
|
||||
|
||||
void InitLeds();
|
||||
void InitButtons(InputPort::IOReadHandler press = nullptr);
|
||||
void InitButtons(const Delegate2<InputPort&, bool>& press);
|
||||
|
||||
// 打开以太网W5500
|
||||
ISocketHost* Create5500();
|
||||
|
|
|
@ -110,19 +110,21 @@ void ButtonOnpress(InputPort* port, bool down, void* param)
|
|||
AP0801::Current->OnLongPress(port, down);
|
||||
}
|
||||
|
||||
void AP0801::InitButtons(InputPort::IOReadHandler press)
|
||||
void AP0801::InitButtons(const Delegate2<InputPort&, bool>& press)
|
||||
{
|
||||
for (int i = 0; i < ButtonPins.Count(); i++)
|
||||
{
|
||||
auto btn = new InputPort(ButtonPins[i]);
|
||||
btn->Mode = InputPort::Both;
|
||||
btn->Invert = true;
|
||||
if (press)
|
||||
btn->Register(press, (void*)i);
|
||||
auto port = new InputPort(ButtonPins[i]);
|
||||
//port->Mode = InputPort::Both;
|
||||
port->Invert = true;
|
||||
/*if (press)
|
||||
port->Register(press, (void*)i);
|
||||
else
|
||||
btn->Register(ButtonOnpress, (void*)i);
|
||||
btn->Open();
|
||||
Buttons.Add(btn);
|
||||
port->Register(ButtonOnpress, (void*)i);*/
|
||||
port->Press = press;
|
||||
port->UsePress();
|
||||
port->Open();
|
||||
Buttons.Add(port);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
void Register(uint offset, IDataPort& dp);
|
||||
|
||||
void InitLeds();
|
||||
void InitButtons(InputPort::IOReadHandler press = nullptr);
|
||||
void InitButtons(const Delegate2<InputPort&, bool>& press);
|
||||
// void InitPort();
|
||||
|
||||
// 打开以太网W5500
|
||||
|
|
|
@ -110,17 +110,19 @@ void ButtonOnpress(InputPort* port, bool down, void* param)
|
|||
AP0802::OnLongPress(port, down);
|
||||
}
|
||||
|
||||
void AP0802::InitButtons(InputPort::IOReadHandler press)
|
||||
void AP0802::InitButtons(const Delegate2<InputPort&, bool>& press)
|
||||
{
|
||||
for(int i=0; i<ButtonPins.Count(); i++)
|
||||
{
|
||||
auto port = new InputPort(ButtonPins[i]);
|
||||
port->Mode = InputPort::Both;
|
||||
//port->Mode = InputPort::Both;
|
||||
port->Invert = true;
|
||||
if(press)
|
||||
/*if(press)
|
||||
port->Register(press, (void*)i);
|
||||
else
|
||||
port->Register(ButtonOnpress, (void*)i);
|
||||
port->Register(ButtonOnpress, (void*)i);*/
|
||||
port->Press = press;
|
||||
port->UsePress();
|
||||
port->Open();
|
||||
Buttons.Add(port);
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
void Register(int index, IDataPort& dp);
|
||||
|
||||
void InitLeds();
|
||||
void InitButtons(InputPort::IOReadHandler press = nullptr);
|
||||
void InitButtons(const Delegate2<InputPort&, bool>& press);
|
||||
void InitPort();
|
||||
|
||||
// 打开以太网W5500
|
||||
|
|
|
@ -97,17 +97,19 @@ void ButtonOnpress(InputPort* port, bool down, void* param)
|
|||
IOK0612::OnLongPress(port, down);
|
||||
}
|
||||
|
||||
void IOK0612::InitButtons(InputPort::IOReadHandler press)
|
||||
void IOK0612::InitButtons(const Delegate2<InputPort&, bool>& press)
|
||||
{
|
||||
for (int i = 0; i < ButtonPins.Count(); i++)
|
||||
{
|
||||
auto port = new InputPort(ButtonPins[i]);
|
||||
port->Mode = InputPort::Both;
|
||||
//port->Mode = InputPort::Both;
|
||||
port->Invert = true;
|
||||
if (press)
|
||||
/*if (press)
|
||||
port->Register(press, (void*)i);
|
||||
else
|
||||
port->Register(ButtonOnpress, (void*)i);
|
||||
port->Register(ButtonOnpress, (void*)i);*/
|
||||
port->Press = press;
|
||||
port->UsePress();
|
||||
port->Open();
|
||||
Buttons.Add(port);
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
|
||||
void InitLeds();
|
||||
void FlushLed(); // 刷新led状态输出
|
||||
void InitButtons(InputPort::IOReadHandler press = nullptr);
|
||||
void InitButtons(const Delegate2<InputPort&, bool>& press);
|
||||
|
||||
bool LedStat(bool enable);
|
||||
|
||||
|
|
|
@ -488,19 +488,15 @@ void InputPort::OnClose()
|
|||
return true;
|
||||
}*/
|
||||
|
||||
bool InputPort::Register(const Delegate2<InputPort&, bool>& dlg)
|
||||
bool InputPort::UsePress()
|
||||
{
|
||||
assert(_Pin != P0, "输入注册必须先设置引脚");
|
||||
|
||||
//Handler = handler;
|
||||
//Param = param;
|
||||
|
||||
if(!OnRegister()) return false;
|
||||
|
||||
Press = dlg;
|
||||
//Press = dlg;
|
||||
|
||||
if (!_task && !HardEvent) _task = Sys.AddTask(InputTask, this, -1, -1, "输入中断");
|
||||
//_task = Sys.AddTask(InputTask, this, 3000, 3000, "输入中断");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -166,6 +166,8 @@ public:
|
|||
Trigger Mode = Both; // 触发模式,上升沿下降沿
|
||||
bool HardEvent = false; // 是否使用硬件事件。默认false
|
||||
|
||||
Delegate2<InputPort&, bool> Press;
|
||||
|
||||
InputPort();
|
||||
InputPort(Pin pin, bool floating = true, PuPd pull = UP);
|
||||
virtual ~InputPort();
|
||||
|
@ -176,8 +178,8 @@ public:
|
|||
virtual bool Read() const;
|
||||
|
||||
// 注册事件
|
||||
bool Register(IOReadHandler handler, void* param = nullptr);
|
||||
bool Register(const Delegate2<InputPort&, bool>& dlg);
|
||||
//bool Register(IOReadHandler handler, void* param = nullptr);
|
||||
bool UsePress();
|
||||
void OnPress(bool down);
|
||||
|
||||
operator bool() const { return Read(); }
|
||||
|
@ -195,7 +197,6 @@ private:
|
|||
|
||||
//IOReadHandler Handler = nullptr;
|
||||
//void* Param = nullptr;
|
||||
Delegate2<InputPort&, bool> Press;
|
||||
|
||||
private:
|
||||
void OpenPin(void* param);
|
||||
|
|
|
@ -15,14 +15,18 @@ bool IC74HC165MOR::Open()
|
|||
|
||||
_PL.HardEvent = true; // 硬中断
|
||||
_PL.Mode = InputPort::Rising; // 上升沿
|
||||
_PL.Register([](InputPort* port, bool down, void* param){ ((IC74HC165MOR*)param)->Trigger();},this);
|
||||
//_PL.Register([](InputPort* port, bool down, void* param){ ((IC74HC165MOR*)param)->Trigger();},this);
|
||||
_PL.Press.Bind(&IC74HC165MOR::OnTrigger, this);
|
||||
_PL.UsePress();
|
||||
_PL.Open();
|
||||
|
||||
if(!_sckHighSpeed)
|
||||
{
|
||||
_PL.HardEvent = true; // 硬中断
|
||||
_SCK.Mode = InputPort::Rising; // 上升沿
|
||||
_SCK.Register([](InputPort* port, bool down, void* param){ ((IC74HC165MOR*)param)->ReaBit();},this);
|
||||
//_SCK.Register([](InputPort* port, bool down, void* param){ ((IC74HC165MOR*)param)->ReaBit();},this);
|
||||
_SCK.Press.Bind(&IC74HC165MOR::OnReaBit, this);
|
||||
_SCK.UsePress();
|
||||
}
|
||||
_SCK.Open();
|
||||
_In.Open();
|
||||
|
@ -39,6 +43,16 @@ bool IC74HC165MOR::Close()
|
|||
return true;
|
||||
}
|
||||
|
||||
void IC74HC165MOR::OnTrigger(InputPort& port, bool down)
|
||||
{
|
||||
if(down) Trigger();
|
||||
}
|
||||
|
||||
void IC74HC165MOR::OnReaBit(InputPort& port, bool down)
|
||||
{
|
||||
if(down) ReaBit();
|
||||
}
|
||||
|
||||
void IC74HC165MOR::Trigger()
|
||||
{
|
||||
if(!_sckHighSpeed)
|
||||
|
|
|
@ -18,6 +18,9 @@ private:
|
|||
ByteArray _Bs; // 内部缓冲区
|
||||
byte _irqCount; // 记录pl信号后第几位数据
|
||||
bool _sckHighSpeed;
|
||||
|
||||
void OnTrigger(InputPort& port, bool down);
|
||||
void OnReaBit(InputPort& port, bool down);
|
||||
public:
|
||||
bool Opened;
|
||||
// pl采集,cp时钟,Q7输出, bufsize 是级联个数,highSpeed 是否是高速clk ms以下算高速
|
||||
|
|
|
@ -249,7 +249,9 @@ void NRF24L01::Init(Spi* spi, Pin ce, Pin irq, Pin power)
|
|||
Irq.Mode = InputPort::Rising;
|
||||
Irq.HardEvent = true;
|
||||
Irq.Init(irq, true);
|
||||
if(!Irq.Register(OnIRQ, this)) Irq.HardEvent = false;
|
||||
//if(!Irq.Register(OnIRQ, this)) Irq.HardEvent = false;
|
||||
Irq.Press.Bind(&NRF24L01::OnIRQ, this);
|
||||
Irq.UsePress();
|
||||
}
|
||||
if(power != P0) _Power.Set(power);
|
||||
|
||||
|
@ -938,16 +940,17 @@ void NRF24L01::AddError()
|
|||
}
|
||||
}
|
||||
|
||||
void NRF24L01::OnIRQ(InputPort* port, bool down, void* param)
|
||||
void NRF24L01::OnIRQ(InputPort& port, bool down)
|
||||
{
|
||||
// 必须在down=true才能读取到正确的状态
|
||||
if(!down) return;
|
||||
|
||||
auto nrf = (NRF24L01*)param;
|
||||
if(!nrf) return;
|
||||
//auto nrf = (NRF24L01*)param;
|
||||
//if(!nrf) return;
|
||||
|
||||
// 马上调度任务
|
||||
Sys.SetTask(nrf->_tidRecv, true, 0);
|
||||
//Sys.SetTask(nrf->_tidRecv, true, 0);
|
||||
Sys.SetTask(_tidRecv, true, 0);
|
||||
}
|
||||
|
||||
void NRF24L01::OnIRQ()
|
||||
|
|
|
@ -370,7 +370,9 @@ void W5500::Init(Spi* spi, Pin irq, Pin rst)
|
|||
Irq.HardEvent = true;
|
||||
//Irq.Set(irq);
|
||||
Irq.Init(irq, true);
|
||||
if(!Irq.Register(OnIRQ, this)) Irq.HardEvent = false;
|
||||
//if(!Irq.Register(OnIRQ, this)) Irq.HardEvent = false;
|
||||
Irq.Press.Bind(&W5500::OnIRQ, this);
|
||||
Irq.UsePress();
|
||||
}
|
||||
|
||||
_spi = spi;
|
||||
|
@ -779,14 +781,15 @@ ISocket* W5500::CreateSocket(NetType type)
|
|||
}
|
||||
|
||||
// irq 中断处理部分
|
||||
void W5500::OnIRQ(InputPort* port, bool down, void* param)
|
||||
void W5500::OnIRQ(InputPort& port, bool down)
|
||||
{
|
||||
if(!down) return; // 低电平中断
|
||||
|
||||
auto net = (W5500*)param;
|
||||
//auto net = (W5500*)param;
|
||||
//net->OnIRQ();
|
||||
//net_printf("OnIRQ \r\n");
|
||||
Sys.SetTask(net->TaskID, true, 0);
|
||||
//Sys.SetTask(net->TaskID, true, 0);
|
||||
Sys.SetTask(TaskID, true, 0);
|
||||
}
|
||||
|
||||
void W5500::OnIRQ()
|
||||
|
|
|
@ -89,7 +89,7 @@ private:
|
|||
void OnClose();
|
||||
|
||||
// 中断脚回调
|
||||
static void OnIRQ(InputPort* port, bool down, void* param);
|
||||
void OnIRQ(InputPort& port, bool down);
|
||||
static void IRQTask(void* param);
|
||||
void OnIRQ();
|
||||
};
|
||||
|
|
|
@ -83,7 +83,7 @@ private:
|
|||
static void ReceiveTask(void* param);
|
||||
uint _tidOpen;
|
||||
uint _tidRecv;
|
||||
static void OnIRQ(InputPort* port, bool down, void* param);
|
||||
void OnIRQ(InputPort& port, bool down);
|
||||
void OnIRQ();
|
||||
};
|
||||
|
||||
|
|
|
@ -255,11 +255,12 @@ extern "C"
|
|||
int idx = Sys.MessagePort;
|
||||
if(idx == COM_NONE) return ch;
|
||||
|
||||
if(isInFPutc) return ch;
|
||||
isInFPutc = true;
|
||||
|
||||
USART_TypeDef* g_Uart_Ports[] = UARTS;
|
||||
auto port = g_Uart_Ports[idx];
|
||||
|
||||
if(isInFPutc) return ch;
|
||||
isInFPutc = true;
|
||||
// 检查并打开串口
|
||||
if((port->CR1 & USART_CR1_UE) != USART_CR1_UE)
|
||||
{
|
||||
|
|
|
@ -12,8 +12,8 @@ static void PulseHandler(PulsePort& port)
|
|||
{
|
||||
#if defined(DEBUG)
|
||||
// down true 无遮挡 down false 有遮挡
|
||||
static UInt64 HideStr;
|
||||
static UInt64 UnHideStr;
|
||||
//static UInt64 HideStr;
|
||||
//static UInt64 UnHideStr;
|
||||
// debug_printf("Press P%c%d down=%d", _PIN_NAME(port->_Port->_Pin),down);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue