Example #1
0
//电池电量检测和告警
void BatteryHandler(void)
{
	static u32 batcnt;
	
	//电池检测分频器
	if(SysTimerClk<batcnt)	return;
	batcnt=SysTimerClk+BAT_TST_CYCLE;
	
	//取得电压
	BatVol=(((u32)AdcGetValue(ADC_BAT))*VOLTAGE_NUMERATOR/100+VOLTAGE_OFFSET)/10;
	PageMainDrawMask|=PMD_BAT;
	
	//在这里处理电池电压告警
	if(BatVol/10<TxSys.BatWarn)
	{
		static u8 BatLowMusicCnt;	
		if(BatLowCnt>BAT_LOW_CNT)//过滤电池电压抖动
		{
			BatLowMusicCnt++;
			if(BatLowMusicCnt>10)
			{
				BeepMusic(MusicBatLow);//告警
				BatLowMusicCnt=0;
			}
		}
		else BatLowCnt++;
	}
	else BatLowCnt=0;
}
Example #2
0
u32 TxLoad(u8 id)
{
	char msg[16];

	//利用CYRF产生动态ID,每次上电仅产生一次
	if(TxRndId==0)
	{
		srand(AdcGetValue(0)+AdcGetValue(1)+AdcGetValue(2)+AdcGetValue(3)+AdcGetValue(4));

		CYRF_Reset();
		CYRF_GetMfgData(CYRF_MfgId);
		TxRndId = ((u32) ( rand() ^ CYRF_MfgId[0] ^ CYRF_MfgId[3]) << 16)
				 | ((u32)( rand() ^ CYRF_MfgId[1] ^ CYRF_MfgId[4]) << 8)
				 | ((u32)( rand() ^ CYRF_MfgId[2] ^ CYRF_MfgId[5]) << 0);
		TxRndId = TxRndId % 1000000;
	}

	if(id>=TX_MOD_NUM)
	{
		PageAlertModel("发射模块内部错误!",0);
		return 0;
	}

	if(id!=TxPrevId)
	{
		strcpy(msg,PageOptionProtocol[id]);
		TxModule[TxPrevId].Close();
		if(TxModule[id].Open())
		{
			strcat(msg,"加载成功!");
			PageAlertModel(id?msg:"RF已关闭!",500);
			TxPrevId=id;
			return 1;
		}
		else
		{
			strcat(msg,"加载失败!");
			PageAlertModel(id?msg:"RF关闭失败!",0);
			TxPrevId=0;
			return 0;
		}
	}

	return 2;
}
Example #3
0
void StickHandler(void)
{
	u8 i;
	
	//取得原始数据
	StickRaw[0]=ADC_TRV*2-AdcGetValue(0);
	StickRaw[1]=AdcGetValue(1);
	StickRaw[2]=ADC_TRV*2-AdcGetValue(2);
	StickRaw[3]=AdcGetValue(3);
	
	//校准
	for(i=0;i<STK_NUM;i++)
	{
		s32 v=StickRaw[i]-TxSys.StkCali[i][1];
		
		//死区调整
		if(v<0)
		{
			if(v<-TxSys.StkDa)	v+=TxSys.StkDa;
			else				v=0;
		}  
		else
		{
			if(v>TxSys.StkDa)	v-=TxSys.StkDa;
			else				v=0;
		}  
		
		v*=STK_TRV;		
		StickCal[i]= v/(TxSys.StkCali[i][v>0?2:0]-TxSys.StkDa);
		
		//通道映射
		u8 idx=StickMap[TxSys.StkType][i];
		StickValue[idx]=StickCal[i];
		StickTrim[idx]=Model.Trim[i]*TRIM_STEP;
	}
}
Example #4
0
/*函数名称:HwAdcGetValue
**函数参数:
**函数功能:ADC读取汇总
**函数返回:
**修 改 人:
**修改日期:
*/
static void HwAdcGetValue(adccfg_t *padc_cfg)
{
	padc_cfg->value = AdcGetValue(padc_cfg->channel);
}