过零检测独立

This commit is contained in:
nnhy 2015-10-28 03:45:33 +00:00
parent 5039c21a0e
commit f338b55ceb
3 changed files with 35 additions and 21 deletions

View File

@ -181,12 +181,8 @@ bool Button_GrayLevel::SetACZeroPin(Pin aczero)
return false; return false;
} }
void ACZeroReset(void *param) void Button_GrayLevel::Init(byte tim, byte count, Button_GrayLevel* btns, EventHandler onpress
{ , ButtonPin* pins, byte* level, byte* state)
if(!Button_GrayLevel::ACZero) Sys.Reset();
}
void Button_GrayLevel::Init(byte tim, byte count, Button_GrayLevel* btns, EventHandler onpress, Pin* pins, byte* level, byte* state)
{ {
debug_printf("\r\n初始化开关按钮 \r\n"); debug_printf("\r\n初始化开关按钮 \r\n");
@ -202,7 +198,7 @@ void Button_GrayLevel::Init(byte tim, byte count, Button_GrayLevel* btns, EventH
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++)
{ {
Leds[i].Set(pins[i]); Leds[i].Set(pins[i].Led);
Leds[i].AFConfig(GPIO_AF_1); Leds[i].AFConfig(GPIO_AF_1);
Leds[i].Open(); Leds[i].Open();
} }
@ -224,11 +220,9 @@ void Button_GrayLevel::Init(byte tim, byte count, Button_GrayLevel* btns, EventH
} }
// 配置 Button 主体 // 配置 Button 主体
Pin* pkeys = &pins[count];
Pin* prelays = &pins[count << 1];
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++)
{ {
btns[i].Set(pkeys[i], prelays[i], false); btns[i].Set(pins[i].Key, pins[i].Relay, pins[i].Invert);
} }
#if DEBUG #if DEBUG
@ -243,21 +237,27 @@ void Button_GrayLevel::Init(byte tim, byte count, Button_GrayLevel* btns, EventH
#endif #endif
btns[i].Register(onpress); btns[i].Register(onpress);
// 灰度 LED 绑定到 Button
btns[i].Set(&LedPWM, pins[i].PwmIndex);
// 如果是热启动,恢复开关状态数据 // 如果是热启动,恢复开关状态数据
if(state[i]) btns[i].SetValue(true); if(state[i]) btns[i].SetValue(true);
} }
}
// 灰度 LED 绑定到 Button void ACZeroReset(void *param)
for(int i = 0; i < count; i++) {
{ if(!Button_GrayLevel::ACZero) Sys.Reset();
btns[i].Set(&LedPWM, i); }
}
void Button_GrayLevel::InitZero(Pin zero, int us)
{
if(zero == P0) return;
debug_printf("\r\n过零检测引脚PB12探测\r\n"); debug_printf("\r\n过零检测引脚PB12探测\r\n");
Button_GrayLevel::SetACZeroAdjTime(2300); Button_GrayLevel::SetACZeroAdjTime(us);
Pin* zero = &pins[count * 3]; if(Button_GrayLevel::SetACZeroPin(zero))
if(Button_GrayLevel::SetACZeroPin(zero[0]))
debug_printf("已连接交流电!\r\n"); debug_printf("已连接交流电!\r\n");
else else
debug_printf("未连接交流电或没有使用过零检测电路\r\n"); debug_printf("未连接交流电或没有使用过零检测电路\r\n");

View File

@ -6,6 +6,15 @@
#include "Timer.h" #include "Timer.h"
#include "Message\DataStore.h" #include "Message\DataStore.h"
struct ButtonPin
{
Pin Led;
Pin Key;
Pin Relay;
bool Invert;
byte PwmIndex;
};
// 面板按钮 // 面板按钮
// 这里必须使用_packed关键字生成对齐的代码否则_Value只占一个字节导致后面的成员进行内存操作时错乱 // 这里必须使用_packed关键字生成对齐的代码否则_Value只占一个字节导致后面的成员进行内存操作时错乱
//__packed class Button //__packed class Button
@ -54,7 +63,8 @@ public:
virtual int OnWrite(byte data); virtual int OnWrite(byte data);
virtual byte OnRead(); virtual byte OnRead();
static void Init(byte tim, byte count, Button_GrayLevel* btns, EventHandler onpress, Pin* pins, byte* level, byte* state); static void Init(byte tim, byte count, Button_GrayLevel* btns, EventHandler onpress, ButtonPin* pins, byte* level, byte* state);
static void InitZero(Pin zero, int us = 2300);
static bool UpdateLevel(byte* level, Button_GrayLevel* btns, byte count); static bool UpdateLevel(byte* level, Button_GrayLevel* btns, byte count);
// 过零检测 // 过零检测
private: private:

View File

@ -81,6 +81,10 @@ TinyClient* CreateTinyClient(ITransport* port)
{ {
static TinyController ctrl; static TinyController ctrl;
ctrl.Port = port; ctrl.Port = port;
// 只有2401需要打开重发机制
if(strcmp(port->ToString(), "R24")) ctrl.Timeout = -1;
static TinyClient tc(&ctrl); static TinyClient tc(&ctrl);
tc.Cfg = TinyConfig::Current; tc.Cfg = TinyConfig::Current;