Esempio n. 1
0
File: acc.cpp Progetto: Kreyl/nute
// =============================== SingleAcc_t =================================
void SingleAcc_t::Init() {
    i2c.Init(GPIO, Scl, Sda);
    IsOperational = false;
    PinSetupIn(GPIO, Irq, pudNone);

    // ==== Setup initial registers ====
    uint8_t BufW[6];
    uint8_t Rslt;
    // Setup High-Pass filter and acceleration scale
    BufW[0] = ACC_REG_XYZ_DATA_CFG;
    BufW[1] = 0x01; // No filter, scale = 4g
    Rslt = i2c.WriteBuf(ACC_ADDR, BufW, 2);
    if(Rslt) {
        IsOperational = false;
        return;
    }
    // Control registers
    BufW[0] = ACC_REG_CONTROL1; // CtrReg[0] is register address
    BufW[1] = 0x21;     // DR=100 => 50Hz data rate; Mode = Active
    BufW[2] = 0x00;     // Normal mode
    BufW[3] = 0x02;     // No IRQ; IRQ output active high
    BufW[4] = 0x00;     // All interrupts disabled
    BufW[5] = 0x04;     // FreeFall IRQ is routed to INT1 pin
    Rslt = i2c.WriteBuf(ACC_ADDR, BufW, 6);
    if(Rslt) {
        IsOperational = false;
        return;
    }
    IsOperational = true;
    ReadAccelerations();
}
Esempio n. 2
0
void Acc_t::Task() {
    if (!IEnabled) return;
    if (!Delay.Elapsed(&CheckTimer, 108)) return;

    if(klGpioIsSetByN(GPIOB, 5)) {  // IRQ occured
        Uart.Printf("Irq\r");
        IClearIrq();
        IsTriggered = true;
        Delay.Reset(&EvtTimer);
    }
#ifdef ACC_ACCELERATIONS_NEEDED
    if(NewData()) Uart.Printf("X: %i; Y: %i; Z: %i\r", Accelerations.xMSB, Accelerations.yMSB, Accelerations.zMSB);
    ReadAccelerations();
#endif
    // Handle event
    if (IsTriggered) {
        if (!IsHandled) {
            EvtTrigger();
            IsHandled = true;
        }
        if (Delay.Elapsed(&EvtTimer, Delay_ms)) {
            // Time to shutdown
            IsTriggered = false;
            IsHandled = false;
            EvtNoTrigger();
        }
    }
}
Esempio n. 3
0
File: pu-test.c Progetto: gke/UAVP
void LinearTest(void)
{
	TxString("\r\nAccelerometer test:\r\n");
	if( _UseLISL )
	{
		ReadAccelerations();
	
		TxString("LR: \t");
		TxVal32(((int32)Ax*1000+512)/1024, 3, 'G');	
		TxNextLine();

		TxString("FB: \t");	
		TxVal32(((int32)Az*1000+512)/1024, 3, 'G');	
		TxNextLine();

		TxString("DU:   \t");	
		TxVal32(((int32)Ay*1000+512)/1024, 3, 'G');	
		TxNextLine();
	}
	else
		TxString("\r\n(Acc. not present)\r\n");
} // LinearTest