silicon_status的讨论用法与怎么贯穿整个代码的?
void change_led_lightness(void)
{
int i;
for (i = 0; i < CAP_PAD_NUM; i++) //改变4个灯????木
{
if(cap_pad[i].led_on)//ledx_change_brightness里面有cap_pad[i].led_on的置0,如果为touch_scan里有置1和置0
{
ledx_change_brightness(i); //到底控制了什么????
}
}
}
这是一个开关的标志,标志着有三种状态
struct cap_pad_t{
int touch;
int led_on;
unsigned int bright_time;
};
void ledx_change_brightness(unsigned int ch)
{
int y; //LED亮度百分比
struct cap_pad_t *cap_pad_ch = &cap_pad[ch];//277.6
if((++cap_pad_ch->bright_time) < (RISE_TIME*2-START_TIME+100))//RISE_TIME=100,这句是什么意思呢????bright_time初始化为100
{
y = calculate_brightness_x2(cap_pad_ch->bright_time, RISE_TIME);//计算出亮度值 只是计算出了y,y用在哪里了????
}
else
{
cap_pad_ch->bright_time = START_TIME;//赋值为22.4
y = LED_INIT_PERCENT_BRIGHT; //默认亮度为5% 默认为是0呀
cap_pad_ch->led_on = 0;//上一级的的判断需要,清零的操作
//&0x58
uint8 silicon_status=0;
#define SILLICON_ALL_SET ((1<<SILLICON_CHANNAL_1) | (1<<SILLICON_CHANNAL_2) | (1<<SILLICON_CHANNAL_3))
enum SILLICON_CHANNEL
{
SILLICON_CHANNAL_1=0,
SILLICON_CHANNAL_2,
SILLICON_CHANNAL_3,
SILLICON_CHANNAL_ALL
};
问题来了在哪里改变的silicon_status????
if((silicon_status&SILLICON_ALL_SET )&&(DEVICE_IS_NEW==new_device_flag))//silicon_status是什么值?这应该是用来存储继电器的状态
{
si446x_change_state(1);//具体什么意思呢????
enter_vlps_xms(100);
}
if ((3==ch)&&(DEVICE_IS_NEW==new_device_flag)) //全亮且是新设备
{
si446x_change_state(1);
enter_vlps_xms(100);
}
if((0x08==led_on_ctl))//这是什么意思????对LED的操作
{
relay_status_off(ch);
led_on_ctl&=~(1<<ch);//led_on_ctl是用来记录LED灯状态
return;
}
if (0!=(led_on_ctl & (1<<ch)))
{
relay_status_off(ch);
led_on_ctl&=~(1<<ch);
}
}
}
问题来了在哪里改变的silicon_status????
static uint8 set_relay_state(uint8 *buff, uint8 w_len)//具体实现的是什么功能
{
if (w_len<3)
{
return 0;
}
if (buff[0]!=slave_id) return 0;
if (buff[1] & 0x08)
{
if (buff[2]&0x08)
{
ctrl_clr_all();
silicon_status|=0x58;//0x58的二进制位0101 1000只是把457位置1
我们只是用了前3位来进行置1的。怎么会出现这种情况?为什么用0x58呢????
}
else
{
ctrl_set_all();
silicon_status=0;
}
return 1;
}
if (buff[1] & 0x01)
if(buff[2]&0x01)
clr_ctrl1_port();
else
set_ctrl1_port();
if (buff[1] & 0x02)
if(buff[2]&0x02)
clr_ctrl2_port();
else
set_ctrl2_port();
if (buff[1] & 0x04)
if(buff[2]&0x04)
clr_ctrl3_port();
else
set_ctrl3_port();
return 1;
}
void relay_status(uint8 i)
{
if (0 == i)
{
//enter_vlps_100ms(); //wake up for EV_WIRQ
ctrl1_nev();
}
else if (1==i)
{
ctrl2_nev();
// enter_vlps_100ms(); //wake up for EV_WIRQ
}
else if (2==i)
{
ctrl3_nev();
//enter_vlps_100ms(); //wake up for EV_WIRQ
}
else
{
if ((silicon_status&0x58))//这就解释了为什么需要58而不是其他的值,其实其他的值也是可以的 我猜测
{
set_ctrl1_port();
set_ctrl2_port();
set_ctrl3_port();
//silicon_status_all&=0;
silicon_status&=0;
// enter_vlps_100ms(); //wake up for EV_WIRQ
}
else
{
enter_vlps_100ms();
enter_vlps_100ms(); // avoid the reset; unclear by lgt
clr_ctrl1_port();
clr_ctrl2_port();
clr_ctrl3_port();
// silicon_status_all=1;
silicon_status|=0x58;
// enter_vlps_100ms(); //wake up for EV_WIRQ
}
}
}
uint8 SI4438_remote_handle(struct SI4438_Frame * pframe)
{
if (memcmp_my(pframe->dev_id,device_id,ADAPTER_ADDRESS_LEN))return 0;
if (memcmp_my(pframe->my_id,slave_device_id,SLAVE_ADDRESS_LEN))return 0;
switch (pframe->ctrl)
{
//{0x8E,0x24,0x8B,0x00,0x65,0x1,0x3,0xa6};
case LIGHT_CTRL_WRITE:if((0==(pframe->data&0x00))&&(0==silicon_status&0X00))//防止连续关灯报文
{
return 0;
}
remote_light_ctrl_on(pframe->data);
pframe->temp=pframe->data;
pframe->ctrl=LIGHT_CTRL_READ_REPS;
notify(EV_REPS);
//pframe->data=silicon_status;
break;
case LIGHT_CTRL_READ:pframe->data = silicon_status&0x07;
pframe->temp=0;
pframe->ctrl = LIGHT_CTRL_GET_READ_REPS;
break;
case GET_DEVICE_VERSION:if(0==silicon_status&SILLICON_ALL_SET)return 0;
pframe->data = DEVICE_VERSIONS;
pframe->temp=0;
pframe->ctrl=GET_DEVICE_VERSION;
notify(EV_REPS);
break;
case GET_DEVICE_TYPE:if(0==silicon_status&SILLICON_ALL_SET)return 0;
pframe->data = RELAY_4_CHAN;
pframe->temp=0;
pframe->ctrl=GET_DEVICE_TYPE;
notify(EV_REPS);
break;
//case GET_DEVICE_RSSI://si446x_get_modem_status(0);
// pframe->data = Si446xCmd.GET_MODEM_STATUS.CURR_RSSI;
// pframe->ctrl=GET_DEVICE_RSSI;
// break;
// case BIND_INFOR_DELETE: adapter_infor_clean();
// return 0;
// case BIND_ADDRESS_REQ:return BIND_ADDRESS_REQ;
default: return 0;// pframe->data=SI4438_ORDER_ERR;
break;
}
//GPIOA_PCOR |= GPIO_PCOR_PTCO(CTRL3_PIN); //时间&次数 计量
//clr_selc();
pframe->sum=sum((uint8 *)pframe,10);
vRadio_StartTx_Variable_Packet(0,(uint8 *)pframe,11);
mymemcpy(g_frame_buffer,(uint8 *)pframe,11);
clr_wdog();
while(read_4438_irq_port());
//set_selc();
// GPIOA_PSOR |= GPIO_PSOR_PTSO(CTRL3_PIN); //时间&次数 计量
return 1;
}
//读取silicon_status木
static uint8 get_relay_state(uint8 *buff, uint8 w_len)
{
if (buff[0]!=slave_id) return 0;
return silicon_status;
}