예제 #1
0
// Read device ID
unsigned char MagVerifyDeviceId(void)
{
	unsigned char id;	
	MagOpen();	
	MagAddressRead(MAG_ADDR_WHO_AM_I);
	id = MagReadLast();
	MagClose();
    magPresent = (id == MAG_DEVICE_ID) ? 1 : 0;
	return magPresent;
}
예제 #2
0
// Shutdown the device to standby mode (standby mode, interrupts disabled)
void MagStandby(void)
{
	MagOpen();
	MagAddressWrite(MAG_ADDR_CTRL_REG1);
	MagWrite(0b01100000);/* 10Hz OSR 16, 137uA, continuous normal sampling ON
	b7-5	:	DR[2:0]	Data rate selection. Default value: 000.
	b4-3	:	OS [1:0] This register configures the over sampling ratio or measurement integration time. Default value: 00.
	b2		:	FR Fast Read selection. Default value: 0: The full 16-bit values are read. 1: Fast Read, 8-bit values read from the MSB registers.
	b1		:	TM Trigger immediate measurement. 0: Normal operation based on AC condition. 1: Trigger measurement.
	b0		:	AC	0: STANDBY mode. 1: ACTIVE mode. */
	/*MAG_ADDR_CTRL_REG2*/	
	MagClose();
}
예제 #3
0
// Debug dump registers
void MagDebugDumpRegisters(void)
{
	static unsigned char i,regs[10];
	MagOpen();	
	MagAddressRead(MAG_ADDR_WHO_AM_I); /*otherwise it will wrap arround the result regs*/
	for (i=0;i<10;i++)
	{
		regs[i] = MagReadContinue();	
	}
	MagReadLast();
	MagClose();
	Nop();
	Nop();
	Nop();
	Nop();
 	return;
}
예제 #4
0
파일: main.c 프로젝트: x-lugoo/pos
// 显示空闲时用户界面
// show an idle UI
void ShowIdleMainUI(uchar *pbForceUpdate, uchar bShowGallery, int iGallery_Image_Num)
{
	static	uchar	szLastTime[5+1] = {"00000"};
	uchar	szCurTime[16+1];

	GetEngTime(szCurTime);
	if( *pbForceUpdate || memcmp(szLastTime, &szCurTime[11], 4)!=0 )	// Reset magstripe reader every 10 minutes
	{
		MagClose();
		MagOpen();
		MagReset();
	}

	if(bShowGallery){
	    ShowGallery(iGallery_Image_Num);
	}

	if( *pbForceUpdate || memcmp(szLastTime, &szCurTime[11], 5)!=0)
	{
		// refresh UI
		sprintf((char *)szLastTime, "%.5s", &szCurTime[11]); 

		// Gui_ClearScr(); // removed by Kim_LinHB 2014-08-13 v1.01.0003 bug512
		// Modified by Kim_LinHB 2014-8-11 v1.01.0003
        //Gui_ShowMsgBox(szCurTime, gl_stTitleAttr, NULL, gl_stCenterAttr, GUI_BUTTON_NONE, 0,NULL);
        Gui_UpdateTitle(szCurTime, gl_stTitleAttr);
		//Gui_DrawText(szCurTime, gl_stTitleAttr, 0, 5);
        if(*pbForceUpdate){
            if(!bShowGallery)
            {
                Gui_UpdateKey(XUI_KEYFUNC, _T("FUNC"), NULL, NULL);
                Gui_UpdateKey(XUI_KEYMENU, _T("MENU"), NULL, NULL);
                Gui_SetVirtualButton(1, 1);
                DispSwipeCard(TRUE);
            }
            else
                Gui_SetVirtualButton(0,0);
        }
		*pbForceUpdate = FALSE;
	}
#ifdef _WIN32
	DelayMs(100);
#endif
}
예제 #5
0
// MagStartup
void MagStartup(unsigned char samplingRate)
{
	MagOpen();
	MagAddressWrite(MAG_ADDR_OFF_X_MSB);	/* Offset regs*/
	MagWrite(0b00000000);	/*	MAG_ADDR_OFF_X_MSB */
	MagWrite(0b00000000);	/*	MAG_ADDR_OFF_X_LSB */
	MagWrite(0b00000000);	/*	MAG_ADDR_OFF_Y_MSB */
	MagWrite(0b00000000);	/*	MAG_ADDR_OFF_Y_LSB */
	MagWrite(0b00000000);	/*	MAG_ADDR_OFF_Z_MSB */
	MagWrite(0b00000000);	/*	MAG_ADDR_OFF_Z_LSB */
	MagReopen();
	MagAddressWrite(MAG_ADDR_CTRL_REG1);
	/*MAG_ADDR_CTRL_REG1*/
	{
		unsigned char ctrl_reg1 = 0;
		switch (samplingRate)
		{
			/*keeping the minimum possible oversample ratio - lowest power - continuous normal sampling ON */
			case (80)	:	{ctrl_reg1 = 0b00000001;magRate = 80;	break;} /*900uA*/
			case (40)	:	{ctrl_reg1 = 0b00100001;magRate = 40;	break;} /*550uA*/
			case (20)	:	{ctrl_reg1 = 0b01000001;magRate = 20;	break;} /*275uA*/
			case (10)	:	{ctrl_reg1 = 0b01100001;magRate = 10;	break;} /*137uA*/
			case (5)	:	{ctrl_reg1 = 0b10000001;magRate = 5;	break;} /*68uA*/
			case (2)	:	{ctrl_reg1 = 0b10100001;magRate = 2;	break;} /*34.4uA*/
			case (1)	:	{ctrl_reg1 = 0b11000001;magRate = 1;	break;} /*17.2uA*/
			default 	:	{ctrl_reg1 = 0b01100001;magRate = 10;	break;}/* 10Hz OSR 16, 137uA */
		}
		MagWrite(ctrl_reg1); /*
		b7-5	:	DR[2:0]	Data rate selection. Default value: 000.
		b4-3	:	OS [1:0] This register configures the over sampling ratio or measurement integration time. Default value: 00.
		b2		:	FR Fast Read selection. Default value: 0: The full 16-bit values are read. 1: Fast Read, 8-bit values read from the MSB registers.
		b1		:	TM Trigger immediate measurement. 0: Normal operation based on AC condition. 1: Trigger measurement.
		b0		:	AC	0: STANDBY mode. 1: ACTIVE mode. */
	}
	/*MAG_ADDR_CTRL_REG2*/
	MagWrite(0b00000000); /*
	b7		: 	AUTO_MRST_EN Automatic Magnetic Sensor Reset. 0: Automatic Magnetic sensor resets off. 1: Automatic Magnetic sensor resets on.
	b5		:	RAW 0: Normal mode: data values are corrected by the user offset register values. 1: Raw mode: data values are not corrected by the user offset register values.
	b4		:	Mag_RST 0: Reset cycle not active. 1: Reset cycle initiate or Reset cycle busy/active.*/
	MagClose(); 
	return;
}
예제 #6
0
/*Note: The samples are 2's compliment and 16bit*/
void MagSingleSample(mag_t *value)
{
	MagOpen();	
	MagAddressRead(MAG_ADDR_OUT_X_MSB);
	if (value == NULL)
	{
		MagReadContinue();MagReadContinue();MagReadContinue();
		MagReadContinue();MagReadContinue();MagReadLast();
	}
	else
	{
	value->xh = MagReadContinue();
	value->xl = MagReadContinue();
	value->yh = MagReadContinue();
	value->yl = MagReadContinue();
	value->zh = MagReadContinue();
	value->zl = MagReadLast();
	}
	MagClose();
	return;
}