Example #1
0
void
Sampler::fillBuffer(short *s, unsigned int len)
{
	if(!usecount) return;
	SRC_TYPE srcType = src;
	if(needResample) {
		needFloat = true;
		if(len > resBufferLen) {
			SetResBufferSize(len);
		}
		unsigned int rLen = resampler->res_push_check(len);
		if(rLen > bufferLen) {
			SetBufferSize(rLen);
		}
		switch(src){
			case SRC_MONOSHORT:
				srcType = SRC_MONOFLOAT;
				ShortToFloat(s, resampleBuffer, len);
				len = resampler->res_push_interleaved(floatBuffer, resampleBuffer, len);
				return _fillBuffer(floatBuffer, len, SRC_MONOFLOAT);
			case SRC_STEREOSHORT:
				srcType = SRC_STEREOFLOAT;
				ShortToFloat((short *)s, resampleBuffer, len*2);
				len = resampler->res_push_interleaved(floatBuffer, resampleBuffer, len);
				return _fillBuffer(floatBuffer, len, SRC_STEREOFLOAT);
			default:
				return;
		}
	}
	_fillBuffer(s, len, srcType);
}
Example #2
0
void TileLayerComponentManager::_render(EntityRef entity, float interp, const OrthographicCamera& camera) {
	if ( !entity.isEnabled() )
		return;

	TileLayerComponent* comp = get(entity);
	if(comp && comp->isEnabled()
	&& comp->tileMap() && comp->tileMap()->tileSet() && comp->tileMap()->tileSet().get()
	&& comp->tileMap()->tileSet()->get()->isValid()) {
		TileMapSP tileMap = comp->tileMap();
		unsigned  layer   = comp->layerIndex();

		// FIXME: Find a way to get rid of this - we should not upload stuff here.
		TextureAspectSP texAspect = tileMap->tileSet()->asset()->aspect<TextureAspect>();
		if(!texAspect || !texAspect->get()) {
			texAspect = _spriteRenderer->createTexture(tileMap->tileSet()->asset());
			_spriteRenderer->renderer()->uploadPendingTextures();
		}
		TextureSP tex = texAspect->get();

		// FIXME: wt should be applied as a shader parameter
		Matrix4 wt = lerp(interp,
						  comp->_entity()->prevWorldTransform.matrix(),
						  comp->_entity()->worldTransform.matrix());

		if(comp->_bufferDirty) {
			float tileWidth  = float(tex->width())  / float(tileMap->tileSetHTiles());
			float tileHeight = float(tex->height()) / float(tileMap->tileSetVTiles());
			_fillBuffer(*comp->_buffer, tileMap, layer, tileWidth, tileHeight, wt);
			comp->_bufferDirty = false;
		}
		unsigned count = comp->_buffer->indexSize();

		if(count) {
			_states.buffer       = comp->_buffer.get();
			_states.texture      = tex;
			_states.textureFlags = comp->textureFlags();
			_states.blendingMode = comp->blendingMode();

			Vector4i tileInfo(tileMap->tileSetHTiles(), tileMap->tileSetVTiles(),
			                  tex->width(), tex->height());
			const ShaderParameter* params = _spriteRenderer->addShaderParameters(
			            _spriteRenderer->shader(), camera.transform(), 0, tileInfo);

			float depth = 1.f - normalize(wt(2, 3), camera.viewBox().min()(2),
			                                        camera.viewBox().max()(2));
			_renderPass->addDrawCall(_states, params, depth, 0, count);
		}
	}

	EntityRef child = entity.firstChild();
	while(child.isValid()) {
		render(child, interp, camera);
		child = child.nextSibling();
	}
}
Example #3
0
void 
Sampler::fillBuffer(float *s, unsigned int len)
{
	if(!usecount) return;
	_fillBuffer(s, len, src);
}
Example #4
0
extern int main( void )
{
    volatile uint32_t delay;
    uint8_t i;
    uint8_t SNo[16];
    Async async;
    /* Disable watchdog */
    WDT_Disable( WDT ) ;

    /* Enable I and D cache */
    SCB_EnableICache();
    SCB_EnableDCache();
    
    CallBackFired = 0;
    
    /* Output example information */
    printf("-- TWI EEPROM Example %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
    
    TimeTick_Configure();
    
    /* Configure TWI pins. */
    PIO_Configure(pins, PIO_LISTSIZE(pins));
    PMC_EnablePeripheral(BOARD_ID_TWI_EEPROM);
    /* Configure TWI */
    
    twi_dma.pTwid = malloc(sizeof(Twid));
    twi_dma.pTwiDma = malloc(sizeof(sXdmad));
    
    TWI_ConfigureMaster(BOARD_BASE_TWI_EEPROM, TWCK, BOARD_MCK);
    TWID_Initialize(&twid, BOARD_BASE_TWI_EEPROM);
    TWID_DmaInitialize(&twi_dma, BOARD_BASE_TWI_EEPROM, 0);

    TWID_Read(&twid, AT24MAC_SERIAL_NUM_ADD, 0x80, 1, SNo, PAGE_SIZE, 0);

    /* Erase all page */
    memset(pData, 0, PAGE_SIZE);
    for(i=0; i< EEPROM_PAGES; i++)
    {
        printf("-I- Filling page #%d with zeroes ...\r\n", i);
        TWID_Write(&twid, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, 0);
        /* Wait at least 10 ms */
        Wait(10);
    }
    printf("\r\n");

    _fillBuffer(pData);

    /* Synchronous operation */
    for(i=0; i< EEPROM_PAGES; i++)
    {
        printf("\n\r-I- Filling page #%d with checkerboard pattern ...\r", i);
        TWID_DmaWrite(&twi_dma, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, 0);
        /* Wait at least 10 ms */
        Wait(10);
    }
    printf("\r\n");


    /* Read back data */
    memset(pData, 0, PAGE_SIZE);
    for(i=0; i< EEPROM_PAGES; i++)
    {
        printf("-I- Reading page #%d... ", i);
        TWID_DmaRead(&twi_dma, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, 0);
        /* Wait at least 10 ms */
        Wait(10);
        _checkReadBuffer(pData);
    }
     printf("\r\n");

    /* Configure TWI interrupts */
    NVIC_ClearPendingIRQ(TWIHS0_IRQn);
    NVIC_EnableIRQ(TWIHS0_IRQn);

    /* Asynchronous operation */
    printf("-I- Read/write on page #0 (IRQ mode)\n\r");

    /* Write checkerboard pattern in first page */
    _fillBuffer(pData);
    memset(&async, 0, sizeof(async));
    async.callback = (void *) TestCallback;

    for(i=0; i< EEPROM_PAGES; i++)
    {
        printf("-I- Filling page #%d with checkerboard pattern ...\r", i);
        TWID_Write(&twid, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, &async);
        while (!ASYNC_IsFinished(&async));
        /* Wait at least 10 ms */
        Wait(10);
    }
    printf("\r\n");


    /* Read back data */
    memset(pData, 0, PAGE_SIZE);
    memset(&async, 0, sizeof(async));
    async.callback = (void *) TestCallback;
    for(i=0; i< EEPROM_PAGES; i++)
    {
        printf("-I- Reading page # %d...\r", i);
        TWID_Read(&twid, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, &async);
        while ( !ASYNC_IsFinished( &async ) ) ;
        /* Wait at least 10 ms */
        Wait(10);
        _checkReadBuffer(pData);
    }
    printf("\r\n Callback Fired %d times", CallBackFired);

    return 0 ;
}
size_t AsyncAbstractResponse::_ack(AsyncWebServerRequest *request, size_t len, uint32_t time){
  if(!_sourceValid()){
    _state = RESPONSE_FAILED;
    request->client()->close();
    return 0;
  }
  _ackedLength += len;
  size_t space = request->client()->space();
  if(_state == RESPONSE_CONTENT){
    size_t outLen;
    size_t readLen = 0;

    if(_chunked || !_sendContentLength){
      outLen = space;
    } else {
      size_t remaining = _contentLength - _sentLength;
      outLen = (remaining > space)?space:remaining;
    }
    uint8_t *buf = (uint8_t *)malloc(outLen);

    if(_chunked){
      readLen = _fillBuffer(buf, outLen - 8);
      char pre[6];
      sprintf(pre, "%x\r\n", readLen);
      size_t preLen = strlen(pre);
      memmove(buf+preLen, buf, preLen);
      for(size_t i=0; i<preLen; i++)
        buf[i] = pre[i];
      outLen = preLen + readLen;
      buf[outLen++] = '\r';
      buf[outLen++] = '\n';
    } else {
      outLen = _fillBuffer(buf, outLen);
    }

    if(outLen)
      outLen = request->client()->write((const char*)buf, outLen);
    _sentLength += outLen;
    free(buf);

    if((_chunked && readLen == 0) || (!_sendContentLength && outLen == 0) || _sentLength == _contentLength){
      _state = RESPONSE_WAIT_ACK;
    }
    return outLen;

  } else if(_state == RESPONSE_HEADERS){
    size_t outLen = _head.length();
    if(space >= outLen){
      request->client()->write(_head.c_str(), outLen);
      _head = String();
      _state = RESPONSE_CONTENT;
      return outLen;
    } else {
      String out = _head.substring(0, space);
      _head = _head.substring(space);
      request->client()->write(out.c_str(), out.length());
      return out.length();
    }
  } else if(_state == RESPONSE_WAIT_ACK){
    if(!_sendContentLength || _ackedLength >= (_headLength+_contentLength)){
      _state = RESPONSE_END;
      if(!_chunked && !_sendContentLength)
        request->client()->close();
    }
  }
  return 0;
}