示例#1
0
文件: main.c 项目: 3Nigma/AVI
int main(void) {
  AtomicCommand pcCom;
  uint8_t optCamId = 0;
  uint8_t camRetVal = 0;
  uint8_t comholder[MAX_COMMAND_PAYLOAD];
  uint8_t respholder[MAX_COMMAND_PAYLOAD];
  uint8_t *compt = NULL;
  uint8_t *resppt = NULL;
  uint8_t respLength = 0;

  pcCom.data = comholder;

  /* initialize system modules */
  //initMotors();
  uart_init();
  initCams();

  /* set nRES on RFM12 HIGH */
  DDRB |= _BV(PB2);
  PORTB &= ~_BV(PB2);
  _delay_ms(10);
  PORTB |= _BV(PB2);
  _delay_ms(100);

  initRF();
  sei();

  /* set STATUS port to output */ 
  DDRA |= 0xFF;
  PORTA = 0x00;

  /*
  _delay_ms(2000);
  setMotorDirection(ALL_MOTORS, FORWARD);
  setMotorSpeed(ALL_MOTORS, 50);
  _delay_ms(1000);
  stopAllMotors();

  while(1){
    PORTA = 0b10101010;
    _delay_ms(500);
    PORTA = 0b01010101;
    _delay_ms(500);
  }*/
	
  pwrDownCam(CAM0);
  pwrDownCam(CAM1);
  /* force cams LED on */
  //forceAwakeCam(CAM0);
  //forceAwakeCam(CAM1);
	
  uart_putstr("All system initialized, AviCar online!");

  while(1) {
  rf12_rxdata(&pcCom);

  compt = pcCom.data;
  resppt = respholder;
  respLength = 0;
  while(compt != (pcCom.data + pcCom.length)) {
    switch(compt[0] & CAR_SUB_COMM_MASK) {
    case CAR_CAMS_SUB: /* resolve a cam command */
      switch(compt[0] & CAR_CAMS_ID_MASK) {
      case CAR_CAMS_ID_TOP:
        optCamId = CAM1;
        break;
      case CAR_CAMS_ID_MID:
        optCamId = CAM0;
        break;
      case CAR_CAMS_ID_ALL:
        break;
      default:
        /* it shouldn't reach this point */
        break;
      }
      switch(compt[0] & CAR_CAMS_FUNC_MASK) {
      case CARS_CAMS_FUNC_SOFTRESET:
        softResetCam(optCamId);
        resppt[0] = 0x01;
        respLength += 1;
        resppt += 1;
        compt += 1;
        break;
      case CARS_CAMS_FUNC_PWRDOWN:
       pwrDownCam(optCamId);
       resppt[0] = 0x01;
       respLength += 1;
       resppt += 1;
       compt += 1;
       break;
      case CARS_CAMS_FUNC_FORCEON:
        forceAwakeCam(optCamId);
        resppt[0] = 0x01;
        respLength += 1;
        resppt += 1;
        compt += 1;
        break;
      case CARS_CAMS_FUNC_GETMAXPIXEL:
        camRetVal = getMaxPixel(optCamId);
        resppt[0] = camRetVal;
        respLength += 1;
        resppt += 1;
        compt += 1;
        break;
      case CARS_CAMS_FUNC_GETMINPIXEL:
        camRetVal = getMinPixel(optCamId);
        resppt[0] = camRetVal;
        respLength += 1;
        resppt += 1;
        compt += 1;
        break;
      case CARS_CAMS_FUNC_GETSQUAL:
        camRetVal = getSqual(optCamId);
        resppt[0] = camRetVal;
        resppt += 1;
        compt += 1;
        break;
      case CARS_CAMS_FUNC_GETPIXELSUM:
        camRetVal = getPixelSum(optCamId);
        resppt[0] = camRetVal;
        respLength += 1;
        resppt += 1;
        compt += 1;
        break;
      case CARS_CAMS_FUNC_GETXMOVEMENT:
        camRetVal = getXMovement(optCamId);
        resppt[0] = camRetVal;
        respLength += 1;
        resppt += 1;
        compt += 1;
        break;
      case CARS_CAMS_FUNC_GETYMOVEMENT:
        camRetVal = getYMovement(optCamId);
        resppt[0] = camRetVal;
        respLength += 1;
        resppt += 1;
        compt += 1;
        break;
      case CARS_CAMS_FUNC_SETCAMSTEP:
        setPixelStep(optCamId, compt[1]);
        resppt[0] = 0x01;
        respLength += 1;
        resppt += 1;
        compt += 2;
        break;
      case CARS_CAMS_FUNC_GETPIXELS:
        requirePixels(optCamId);
        resppt = getPixelBuffer(optCamId);
        respLength += CAM_PIX_BYTECNT;
        compt += 1;
        break;
      default:
        /* it shouldn't reach this point */
        break;
      }
      break;
    case CAR_MOTS_SUB:
      break;
    default:
      break;
    }
  }

  /* reply to demander */
  pcCom.data = respholder;
  pcCom.length = respLength;
  rf12_txdata(&pcCom);
  }
}
示例#2
0
 void DarwinGlTexture::iUpdateTextureSurface( const GlTextureUpdateType& utype )
 {
     if ( utype == GlTextureUpdateType::PixelBuffer )
     {
         SoftwarePixelBuffer softpixu = getPixelBuffer();
         
         if ( softpixu.isInvalid() )
         {
             return;
         }
         
         SoftwarePixelBufferHolder softpix = softpixu.lock();
         
         if ( iGlTexture )
         {
             bind();
             
             // Here we assume the Texture has already been created and the Surface is correct.
             // We just call glTexSubImage depending on the TextureType.
             
             GLenum target = GlTextureTargetFromTextureType(getType());
             GLint level = 0;
             GLint xoffset = 0;                                              // Unsupported
             GLint yoffset = 0;                                              // Unsupported
             GLint zoffset = 0;                                              // Unsupported
             GLsizei width = getSurface().width;
             GLsizei height = getSurface().height;
             GLsizei depth = 0;                                              // Unsupported
             GLenum format = GlTextureComponents(softpix->getPixelFormat());
             GLenum type = GlTextureFormat(softpix->getPixelFormat());
             const GLvoid* pixels = (const GLvoid*) softpix->getData();
             
             TextureType textype = getType();
             
             if ( textype == TextureType::OneDimension )
             {
                 glTexSubImage1D(target, level, xoffset, width, format, type, pixels);
             }
             
             if ( textype == TextureType::TwoDimension )
             {
                 glTexSubImage2D(target, level, xoffset, yoffset, width, height, format, type, pixels);
             }
             
             if ( textype == TextureType::ThreeDimension )
             {
                 glTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels);
             }
             
             if ( textype == TextureType::CubeMap )
             {
                 // Here we have 6 different textures. But we will not do it for now.
                 // UNSUPPORTED
             }
             
         }
         
         else
         {
             // If 'iGlTexture' is invalid , we must create the Texture object.
             // We must also check for TextureType , and Surface .
             
             if ( getType() == TextureType::Null )
                 return;
             Surface surf = getSurface();
             if ( surf.width <= 0 || surf.height <= 0 )
                 return;
             
             glGenTextures(1, &iGlTexture);
             bind();
             
             GLenum target = GlTextureTargetFromTextureType(getType());
             GLint level = 0;
             GLsizei width = getSurface().width;
             GLsizei height = getSurface().height;
             GLsizei depth = 0;                                              // Unsupported
             GLenum format = GlTextureComponents(softpix->getPixelFormat());
             GLenum type = GlTextureFormat(softpix->getPixelFormat());
             const GLvoid* pixels = (const GLvoid*) softpix->getData();
             
             TextureType textype = getType();
             
             if ( textype == TextureType::OneDimension )
             {
                 glTexImage1D(target, level, GL_RGBA, width, 0, format, type, pixels);
             }
             
             if ( textype == TextureType::TwoDimension )
             {
                 glTexImage2D(target, level, GL_RGBA, width, height, 0, format, type, pixels);
             }
             
             if ( textype == TextureType::ThreeDimension )
             {
                 glTexImage3D(target, level, GL_RGBA, width, height, depth, 0, format, type, pixels);
             }
             
             if ( textype == TextureType::CubeMap )
             {
                 // Here we have 6 different textures. But we will not do it for now.
                 // UNSUPPORTED
             }
         }
     }
     
     if ( utype == GlTextureUpdateType::Surface )
     {
         // If we are updating the Surface , but the GlTexture is valid , we should destroy it and
         // make a new one. Normally , you should not use Texture::setSurface if data is already set.
         
         if ( iGlTexture )
         {
             // Destroy the Texture , and launch the Update with SoftwarePixelBuffer .
             glDeleteTextures(1, &iGlTexture);
             iGlTexture = 0;
         }
         
         SoftwarePixelBuffer pixbufu = getPixelBuffer();
         
         if ( pixbufu.isInvalid() )
         {
             // Create a new empty pixel buffer .
             SoftwarePixelBufferHolder pixbuf = SoftwarePixelBufferHolder ( new SoftwarePixelBufferPrivate(getName()+"/0softbuf") );
             pixbuf->setPixelFormat(HardwarePixelFormat::RGBAFloat);
             pixbuf->setData(nullptr, getSurface().width * getSurface().height * sizeof(float));
             setPixelBuffer(pixbuf);
         }
         
         else
         {
             iUpdateTextureSurface(GlTextureUpdateType::PixelBuffer);
         }
     }
     
     if ( utype == GlTextureUpdateType::Type )
     {
         // If TextureType has changed , we should reload the Texture.
         if ( iGlTexture )
         {
             glDeleteTextures(1, &iGlTexture);
             iGlTexture = 0;
         }
         
         iUpdateTextureSurface(GlTextureUpdateType::PixelBuffer);
     }
 }