コード例 #1
0
ファイル: AppleLM8x.cpp プロジェクト: AzerTyQsdF/osx
// AppleLM87::getReading
IOReturn AppleLM8x::getReading(UInt32 subAddress, SInt32 *value)
{
    IOReturn status;
    UInt8 data;
    
    if (systemIsRestarting == TRUE)
        return kIOReturnOffline;

    status = openI2C(kLM8xBus);
    if(status != kIOReturnSuccess)
    {
        DLOG("AppleLM8x::getReading(0x%x) failed to open I2C bus.\n", kLM8xAddr<<1);
        return status;
    }

    status = readI2C((UInt8)subAddress, (UInt8 *) &data, 1);
    if(status != kIOReturnSuccess)
    {
        DLOG("AppleLM8x::getReading(0x%x) readI2C failed.\n", kLM8xAddr<<1);
        closeI2C();
        return status;
    }
	
	closeI2C();

	*value = (SInt32)data;

	return kIOReturnSuccess;
}
コード例 #2
0
ファイル: AppleLM8x.cpp プロジェクト: AzerTyQsdF/osx
IOReturn AppleLM8x::restoreRegisters()
{
    IOReturn status;

    DLOG("AppleLM8x::restoreRegisters(0x%x) entered.\n", kLM8xAddr<<1);

    status = openI2C(kLM8xBus);
    if(status != kIOReturnSuccess)
    {
        DLOG("AppleLM8x::restoreRegisters(0x%x) failed to open I2C bus.\n", kLM8xAddr<<1);
        return status;
    }

    status = writeI2C((UInt8)kChannelModeRegister, (UInt8 *)&savedRegisters.ChannelMode, 1);
    if(status != kIOReturnSuccess)
    {
        DLOG("AppleLM8x::restoreRegisters(0x%x) writeI2C failed.\n", kLM8xAddr<<1);
        closeI2C();
        return status;
    }

    status = writeI2C((UInt8)kConfReg2, (UInt8 *)&savedRegisters.Configuration2, 1);
    if(status != kIOReturnSuccess)
    {
        DLOG("AppleLM8x::restoreRegisters(0x%x) writeI2C failed.\n", kLM8xAddr<<1);
        closeI2C();
        return status;
    }

	// restore Configuration Register 1 last, since it starts polling
    status = writeI2C((UInt8)kConfReg1, (UInt8 *)&savedRegisters.Configuration1, 1);
    if(status != kIOReturnSuccess)
    {
        DLOG("AppleLM8x::restoreRegisters(0x%x) writeI2C failed.\n", kLM8xAddr<<1);
        closeI2C();
        return status;
    }
	
    closeI2C();

    return status;
}
コード例 #3
0
ファイル: AppleLM8x.cpp プロジェクト: AzerTyQsdF/osx
IOReturn AppleLM8x::saveRegisters()
{
    IOReturn status;

    DLOG("AppleLM8x::saveRegisters(0x%x) entered.\n", kLM8xAddr<<1);

    status = openI2C(kLM8xBus);
    if(status != kIOReturnSuccess)
    {
        DLOG("AppleLM8x::saveRegisters(0x%x) failed to open I2C bus.\n", kLM8xAddr<<1);
        return status;
    }

    status = readI2C((UInt8)kChannelModeRegister, (UInt8 *)&savedRegisters.ChannelMode, 1);
    if(status != kIOReturnSuccess)
    {
        DLOG("AppleLM8x::saveRegisters(0x%x) readI2C failed.\n", kLM8xAddr<<1);
        closeI2C();
        return status;
    }

    status = readI2C((UInt8)kConfReg1, (UInt8 *)&savedRegisters.Configuration1, 1);
    if(status != kIOReturnSuccess)
    {
        DLOG("AppleLM8x::saveRegisters(0x%x) readI2C failed.\n", kLM8xAddr<<1);
        closeI2C();
        return status;
    }

    status = readI2C((UInt8)kConfReg2, (UInt8 *)&savedRegisters.Configuration2, 1);
    if(status != kIOReturnSuccess)
    {
        DLOG("AppleLM8x::saveRegisters(0x%x) readI2C failed.\n", kLM8xAddr<<1);
        closeI2C();
        return status;
    }

    closeI2C();

    return status;
}
コード例 #4
0
ファイル: AppleLM8x.cpp プロジェクト: AzerTyQsdF/osx
IOReturn AppleLM8x::initHW(IOService *provider)
{
    IOReturn status;
    UInt8 cfgReg = 0;
    UInt8 attempts = 0;

    DLOG("AppleLM8x::initHW(0x%x) entered.\n", kLM8xAddr<<1);

    status = openI2C(kLM8xBus);
    if(status != kIOReturnSuccess)
    {
        DLOG("AppleLM8x::initHW(0x%x) failed to open I2C bus.\n", kLM8xAddr<<1);
        return status;
    }
 
	// Attempt to start LM87 by setting bit 0 in Configuration Register 1.  If we detect the RESET
	// bit, then make a second attempt.
	for ( ; attempts < 2; attempts++ )
	{
		// Read Configuration Register 1
		status = readI2C((UInt8)kConfReg1, (UInt8 *) &cfgReg, 1);
		if(status != kIOReturnSuccess)
		{
			DLOG("AppleLM8x::initHW(0x%x) readI2C failed.\n", kLM8xAddr<<1);
			break;
		}

		DLOG("AppleLM8x::readI2C(0x%x) retrieved data = 0x%x\n", kLM8xAddr<<1, cfgReg);    

		// If we detect RESET, wait at least 45ms for it to clear.
		if ( cfgReg & kConfRegRESET )
		{
			IOSleep(50);
			status = kIOReturnError;
		}

		if(status != kIOReturnSuccess)
		{
			IOLog("AppleLM8x::initHW(0x%x) readI2C detected RESET bit.\n", kLM8xAddr<<1);
		}

		// Start monitoring operations
		cfgReg = 0x1;

		// Failure of this write operation is fatal
		status = writeI2C((UInt8)kConfReg1, (UInt8 *)&cfgReg, 1);

		// Read Configuration Register 1
		status = readI2C((UInt8)kConfReg1, (UInt8 *) &cfgReg, 1);
		if(status != kIOReturnSuccess)
		{
			DLOG("AppleLM8x::initHW(0x%x) readI2C failed.\n", kLM8xAddr<<1);
			break;
		}
	
		if ( cfgReg == kConfRegStart )
		{
			break;
		}
		else
		{
			IOLog("AppleLM8x::readI2C(0x%x) retrieved configuration register 1 = 0x%x\n", kLM8xAddr<<1, cfgReg);    
		}
	}

    closeI2C();

    return status;
}
コード例 #5
0
void SmartMote::work(){
    while(1){
        /*  se l'ora corrente è di scansione                                    */
        if(!(RTCC.hours() % 6) && (RTCC.minutes() >= 0x00 && RTCC.minutes() <= 0x05)){
            AString data;
            AString message;
            AString answer;
            /*  abilito il core timer (la prima volta è già abilitato)          */
            System::wakeCoreTimer();
            /*  accendo il led verde                                            */
            turnOnGreen();
            /*  accendo la seriale                                              */
            openUART();
            /*  accendo l'i2c                                                   */
            openI2C();
            /*  prendo le misure                                                */
            data += mac();
            data += luminosity();
            data += ambientTempAndHum();
            data += groundTemp();
            data += groundHum();
            data += battey();
            /*  compongo la stringa                                             */
            message += _PHP_CHUNK1;
            /*  inserisco l'hostname                                            */
            message += getHost();
            /*  inserisco la seconda parte di richiesta http                    */
            message += _PHP_CHUNK2;
            /*  inserisco la lunghezza dei dati                                 */
            message += AString(static_cast<sint32>(data.size()));
            /*  inserisco la terza parte di richiesta http                      */
            message += _PHP_CHUNK3;
            /*  inserisco i dati                                                */
            message += data;

            /*  se fallisce l'inizializzazione dell'esp                         */
            if(!m_net.initialize()){
                /*  notifico l'errore                                           */
                error();
            }
            /*  se fallisce l'avvio del dhcp                                    */
            if(!m_net.setDhcp(true)){
                /*  notifico l'errore                                           */
                error();
            }
            /*  se fallisce la connessione alla rete                            */
            if(!m_net.joinAP(getSSID(), getKey())){
                /*  notifico l'errore                                           */
                error();
            }
            /*  se fallisce la connessione al server                            */
            if(!m_net.connectToHost(getHost(), 80)){
                /*  notifico l'errore                                           */
                error();
            }
            /*  invio i dati                                                    */
            m_net.send(message);
            /*  aspetto l'ok                                                    */
            m_net.waitForData(answer);
            /*  notifico l'ok o lerrore dell'invio                              */
            wasSuccess(answer);
            /*  lascio l'ap                                                     */
            m_net.leaveAP();
            /*  libero la memoria occupata dalle stringhe                       */
            message.clear();
            data.clear();
            answer.clear();
        }
        /*  calcolo del tempo di sleep per il wifi                              */
        m_net.sleep(getSleepTime());
        /*  punto la prossima sveglia                                           */
        setNextAlarm();
        /*  spengo il led verde                                                 */
        turnOffGreen();
        /*  spengo l'uart                                                       */
        closeUART();
        /*  chiudo l'i2c                                                        */
        closeI2C();
        /*  spengo il core timer                                                */
        System::stopCoreTimer();
        /*  vado a dormire                                                      */
        System::sleep();
            
    }
}
コード例 #6
0
ファイル: testbench_bmp.c プロジェクト: KyleAshley/quadcopter
void main(void) {
  /* put your own code here */

 // BMP
  float altSum;
  float avgAlt;
  float old;
  float alt;
  int i;


   CLKSEL = 0;
   SYNR = 2;
   REFDV = 0;
   while (!(CRGFLG & 0x08));
   CLKSEL = 0x80;                 // Bus = 24Mhz

   MCCTL = 0x4C;                  // PRE = 16 FLMC = 1

   EnableInterrupts;

   // INITIALIZE LCD
   DDRK = 0xFF;
   COMWRTFIRST(0x33);   //reset sequence provided by data sheet
   COMWRT(0x32);       //reset sequence provided by data sheet
   COMWRT(0x28);       //Function set to four bit data length ,2 line, 5 x 7 dot format
   COMWRT(0x06);       //entry mode set, increment, no shift
   COMWRT(0x0E);       //Display set, disp on, cursor on, blink off
   COMWRT(0x01);       //Clear display
   COMWRT(0x80);       //set start posistion, home position
   LCDDelayDATA(TCHAR); // wait for LCD setup

  //********************************************************//
  // I2C Stuff
  //********************************************************//
  openI2C(BR);
  LCDDelayDATA(TCHAR);

  b_setup();
  LCDDelayDATA(TCHAR);

  for(;;)
  {
      b_setControlMode(TEMP_MODE);
      b_updateTempC();

      altSum = 0;
      for(i = 0; i < 5; i++)
      {
        b_setControlMode(PRESSURE_MODE_0);
        b_updatePressure();
        b_updateAltitude();
        //alt = lpFilter(alt, old, 0.5);
        altSum+= b_altitude;
      }

      avgAlt = altSum/5.0;
      //old = avgAlt;

      DATWRTFIRST('T');
      outputDouble((double)b_tempC);

      COMWRTFIRST(0xC0);
      LCDDelayDATA(TCHAR);

      DATWRTFIRST('A');
      outputDouble((double)b_altitude);

      LCDDelayDATA(TCHAR * 6);
      COMWRTFIRST(0x01);
      LCDDelayDATA(TCHAR);

   }
   while(1);
  }
コード例 #7
0
ファイル: main_hardware.c プロジェクト: SebRobot/Projet_2A
int main(){
//    unsigned int us_start, t0, t1, t2, t3;
//    float x, y, theta;
//    float x2, y2, theta2;
//    float x3, y3, theta3;
//    float beta;
//    point pt;
//    int i=0;
//    float check;

	// For IMU
/*	double tab_acc[3] = {0.0, 0.0, 0.0},
		   tab_gyro[3] = {0.0, 0.0, 0.0},
		   tab_magn[3] = {0.0, 0.0, 0.0};
	int i;
*/


    pthread_t pthread_prop,
              pthread_gpio,
              pthread_led,
              pthread_com;
              



    //gpio init
		initGPIO(GREEN_LED);
		initGPIO(ORANGE_LED);
		initGPIO(WRNG_RED_LED);
		initGPIO(RED_LED_BIC);
		initGPIO(GREEN_LED_BIC);
		initGPIO(BP_STOP);


    idFicI2C = openI2C(FILE_I2C);
    setI2C(ADDR_MD25, idFicI2C);
    
    //Create a thread for prop
    if(pthread_create(&pthread_prop, NULL, threadProp, NULL)!=0){
         printf("ERROR; return code from pthread_create()\n");
         getchar();
         exit(-1);
        }

    //Create a thread control gpio
    if(pthread_create(&pthread_gpio, NULL, threadGpio, NULL)!=0){
         printf("ERROR; return code from pthread_create()\n");
         getchar();
         exit(-1);
        }
        
    //Create a thread control gpio
    if(pthread_create(&pthread_led, NULL, threadLed, NULL)!=0){
         printf("ERROR; return code from pthread_create()\n");
         getchar();
         exit(-1);
        }

    //Create a thread for  com
    if(pthread_create(&pthread_com, NULL, thread_Com, NULL)!=0){ //&sargThreadSttRover
         printf("ERROR; return code from pthread_create()\n");
         getchar();
         exit(-1);
    }
        


//	mpu_init();

	while(1){

	/*	mpu_read(tab_acc, tab_gyro, tab_magn);
		printf("\n");
		for(i=0; i<3; i++) printf("tab_acc[%d] = %.2lf\n", i, tab_acc[i]);
		printf("\n");
		for(i=0; i<3; i++) printf("tab_gyro[%d] = %.2lf\n", i, tab_gyro[i]);
		printf("\n");
		for(i=0; i<3; i++) printf("tab_magn[%d] = %.2lf\n", i,  tab_magn[i]);
		printf("\n\n");

		printf("Distance = %d\n\n", sonar_get_distance_cm());
	*/	
		// Update Info Rover
		float x, y, theta;
		int  dist;
		#ifdef I2C_OK
		pos3(&x, &y, &theta);
		volt = getBatVolt();
		pthread_mutex_lock(&mtx_distSonar);
		distSonar = sonar_get_distance_cm();
		dist = distSonar;
		pthread_mutex_unlock(&mtx_distSonar);
		printf("distSonar = %d\n", dist);
		#else
		x = 0, y = 0, theta = 0;
		bat = 15;
		dist = 1000;
		#endif
		
		//printf("x = %.2f; y  %.2f; theta = %.2f; bat = %.2f; dist = %d\n", x, y , theta, bat, dist);
		updateInfoRover(&argThreadSttRover, &x, &y, &theta, &volt, &dist);
/*		printf("argThreadSttRover.sinf.bat = %d\n"
		       "argThreadSttRover.sinf.son = %.2f\n"
		       "argThreadSttRover.sinf.pos.x = %.2f\n"
		       "argThreadSttRover.sinf.pos.y = %.2f\n"
		       "argThreadSttRover.sinf.ang = %.2f\n\n", (int32_t)argThreadSttRover.sinf.bat, argThreadSttRover.sinf.son, argThreadSttRover.sinf.pos.x, argThreadSttRover.sinf.pos.y, argThreadSttRover.sinf.ang);    
*/
	}





//old test
/* //trajectoire
    while(1){
        usleep(10000);
        nd1 = dist(1);
        nd2 = dist(2);
        pos3(&x3, &y3, &theta3);

        beta=trajCorr(x3, y3, theta3, 500, 500);
        printf("%.2f, %.2f, %.2f°, beta=%f\n", x3, y3, theta3, beta*180./M_PI);
        move(100, beta*180./M_PI);
        if(((fabs(x3-500.)<10.) && (fabs(y3-500.)<10.)))
            {
            move(0,0);
            printf("fin\n");
            return 1;
            }
        }
*/




/*
        while(1){
        usleep(10000);
    us_start = micros();
        nd1 = dist(1);
    t0 = micros() - us_start;
        nd2 = dist(2);

    us_start = micros();
        pos(&x, &y, &theta);
    t1 = micros() - us_start;

    us_start = micros();
        pos2(&x2, &y2, &theta2);
    t2 = micros() - us_start;

    us_start = micros();
        pos3(&x3, &y3, &theta3);
    t3 = micros() - us_start;

    //printf("%u,%u,%u,%u\n", t0, t1, t2, t3);

    printf("%.2f, %.2f, %.2f°, %.2f, %.2f, %.2f°, %.2f, %.2f, %.2f°\n", x, y, theta*180./M_PI, x2, y2, theta2*180./M_PI, x3, y3, theta3*180./M_PI);

    }
   // move(1000,0,idFicI2C);



    sleep(1);




    move(0,0,idFicI2C);
    sleep(1);
    printf("d=%f\n",dist(0));
*/

/*   close(idFicI2C);
    printf("Fermeture du bus i2c\n");
*/
    return 0;
    }