虚函数不能作为事件处理函数,取地址时只会得到偏移量而不是函数地址,导致触发事件时跑飞
This commit is contained in:
parent
a259dafbca
commit
29202abaa7
|
@ -22,7 +22,7 @@ void Button::Set(Pin key, Pin led, Pin relay)
|
||||||
void Button::Set(Pin key, Pin led, bool ledInvert, Pin relay, bool relayInvert)
|
void Button::Set(Pin key, Pin led, bool ledInvert, Pin relay, bool relayInvert)
|
||||||
{
|
{
|
||||||
Key.Set(key);
|
Key.Set(key);
|
||||||
Key.Press.Bind(&Button::OnPress, this);
|
Key.Press.Bind(&Button::OnKeyPress, this);
|
||||||
Key.UsePress();
|
Key.UsePress();
|
||||||
Key.Open();
|
Key.Open();
|
||||||
|
|
||||||
|
@ -49,6 +49,11 @@ void Button::OnPress(InputPort& port, bool down)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Button::OnKeyPress(Button& btn, InputPort& port, bool down)
|
||||||
|
{
|
||||||
|
btn.OnPress(port, down);
|
||||||
|
}
|
||||||
|
|
||||||
bool Button::GetValue() { return _Value; }
|
bool Button::GetValue() { return _Value; }
|
||||||
|
|
||||||
int Button::OnWrite(byte data)
|
int Button::OnWrite(byte data)
|
||||||
|
|
|
@ -36,10 +36,11 @@ public:
|
||||||
|
|
||||||
String ToString() const;
|
String ToString() const;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
bool _Value; // 状态
|
bool _Value; // 状态
|
||||||
|
|
||||||
virtual void OnPress(InputPort& port, bool down);
|
virtual void OnPress(InputPort& port, bool down);
|
||||||
|
static void OnKeyPress(Button& btn, InputPort& port, bool down);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue