コード例 #1
0
ファイル: usb_speaker.c プロジェクト: tyoshid/libopenstm32l1
/* USB (low priority) interrupt */
void usb_lp_isr(void)
{
	u16 mask;
	u16 status;
	int ep_id;
	u16 trans;

	/* Interrupt mask */
	mask = usbdevfs_get_interrupt_mask(USBDEVFS_CORRECT_TRANSFER |
					   USBDEVFS_ERROR | USBDEVFS_RESET |
					   USBDEVFS_SOF);
	if (!mask)
		return;

	/* Interrupt status */
	status = usbdevfs_get_interrupt_status(USBDEVFS_CORRECT_TRANSFER |
					       USBDEVFS_ERROR |
					       USBDEVFS_RESET |
					       USBDEVFS_SOF |
					       USBDEVFS_DIR | USBDEVFS_EP_ID);
	if (!(status & (USBDEVFS_CORRECT_TRANSFER | USBDEVFS_ERROR |
			USBDEVFS_RESET | USBDEVFS_SOF)))
		return;

	/* Start of frame */
	if (mask & status & USBDEVFS_SOF) {
		sof();
		/* Clear interrupt. */
		usbdevfs_clear_interrupt(USBDEVFS_SOF);
	}

	/* Correct transfer */
	if (mask & status & USBDEVFS_CORRECT_TRANSFER) {
		ep_id = status & USBDEVFS_EP_ID;
		trans = usbdevfs_get_ep_status(ep_id, USBDEVFS_RX |
					       USBDEVFS_TX | USBDEVFS_SETUP);

		/* Rx (OUT/SETUP transaction) */
		if ((status & USBDEVFS_DIR) && (trans & USBDEVFS_RX))
			rx_packet(ep_id, trans & USBDEVFS_SETUP);

		/* Tx (IN transaction) */
		if (!(status & USBDEVFS_DIR) && (trans & USBDEVFS_TX))
			tx_packet(ep_id);
	}

	/* Error */
	if (mask & status & USBDEVFS_ERROR) {
		usb_error++;
		/* Clear interrupt. */
		usbdevfs_clear_interrupt(USBDEVFS_ERROR);
	}

	/* USB RESET */
	if (mask & status & USBDEVFS_RESET) {
		usb_reset();
		/* Clear interrupt. */
		usbdevfs_clear_interrupt(USBDEVFS_RESET);
	}
}
コード例 #2
0
ファイル: str.cpp プロジェクト: ftnapps/pkg-sbbs
void sbbs_t::read_sif_dat(char *siffile, char *datfile)
{
	char *buf;
	int file;
	long length;

	if((file=nopen(datfile,O_RDONLY))==-1) {
		errormsg(WHERE,ERR_OPEN,datfile,O_RDONLY);
		return; 
	}
	length=filelength(file);
	if(!length) {
		close(file);
		return; 
	}
	if((buf=(char *)malloc(length))==NULL) {
		close(file);
		errormsg(WHERE,ERR_ALLOC,datfile,length);
		return; 
	}
	read(file,buf,length);
	close(file);
	sof(siffile,buf,length);
	free(buf);
}
コード例 #3
0
ファイル: ltablib.c プロジェクト: guodawei/lua
/*
** Use 'time' and 'clock' as sources of "randomness". Because we don't
** know the types 'clock_t' and 'time_t', we cannot cast them to
** anything without risking overflows. A safe way to use their values
** is to copy them to an array of a known type and use the array values.
*/
static unsigned int l_randomizePivot (void) {
  clock_t c = clock();
  time_t t = time(NULL);
  unsigned int buff[sof(c) + sof(t)];
  unsigned int i, rnd = 0;
  memcpy(buff, &c, sof(c) * sizeof(unsigned int));
  memcpy(buff + sof(c), &t, sof(t) * sizeof(unsigned int));
  for (i = 0; i < sof(buff); i++)
    rnd += buff[i];
  return rnd;
}
コード例 #4
0
ファイル: ivrule.cpp プロジェクト: chalmers-revere/opendlv
 odcore::data::dmcp::ModuleExitCodeMessage::ModuleExitCode Ivrule::body()
{
  while (getModuleStateAndWaitForRemainingTimeInTimeslice() == odcore::data::dmcp::ModuleStateMessage::RUNNING) {
    odcore::data::TimeStamp now;



    if((m_mioValidUntil-now).toMicroseconds() > 0) {
      // Steer to mio
      opendlv::perception::StimulusDirectionOfMovement sdom(now, m_mio.getDirection(),opendlv::model::Direction(0,0));
      odcore::data::Container containerSdom(sdom);
      getConference().send(containerSdom);

      // std::cout << "Sent sdom." << std::endl;


      opendlv::perception::StimulusAngularSizeAlignment sasa(now, m_mio.getDirection(),m_mio.getAngularSize(),m_desiredAngularSize);
      odcore::data::Container containerSasa(sasa);
      getConference().send(containerSasa);

      // std::cout << "Sent sasa."  << std::endl;


      // std::cout 
      //     << " Id: " << m_mio.getObjectId() 
      //     << " Azimuth: " << m_mio.getDirection().getAzimuth() 
      //     << " Distance: " << m_mio.getDistance() 
      //     << " Desired angular size: " << m_desiredAngularSize 
      //     << " Currently: " << m_mio.getAngularSize() 
      //     << std::endl;
    } else {
      opendlv::perception::StimulusGroundSpeed sof(now, m_desiredOpticalFlow, m_speed);
      odcore::data::Container containerSof(sof);
      getConference().send(containerSof);
      // std::cout << "Send sof. Desired OF: " << m_desiredOpticalFlow  << " Current OF: " << m_speed << std::endl;
    }
  }
  return odcore::data::dmcp::ModuleExitCodeMessage::OKAY;
}
コード例 #5
0
void CSDLOpenGLWindow::RenderScene()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glm::mat4 mModelView = cCamera.look();
	glm::mat4 mCurrent = mModelView;

	// First render textured objects

	glEnable(GL_TEXTURE_2D);
	spTextured.UseProgram();
	glBindVertexArray(uiVAOs[0]);

	spTextured.SetUniform("projectionMatrix", GetProjectionMatrix());
	spTextured.SetUniform("modelViewMatrix", mModelView);
	spTextured.SetUniform("vColor", glm::vec4(1, 1, 1, 1));

	// Render ground

	tBlueIce.BindTexture();
	glDrawArrays(GL_TRIANGLES, 36, 6);

	// Render 5 opaque boxes

	tBox.BindTexture();

	for (int i = 0; i < 5; i++)
	{
		float fSign = -1.0f + float(i % 2)*2.0f; // This just returns -1.0f or 1.0f (try to examine this)
		glm::vec3 vPos = glm::vec3(fSign*15.0f, 0.0f, 50.0f - float(i)*25.0f);
		mCurrent = glm::translate(mModelView, vPos);
		mCurrent = glm::scale(mCurrent, glm::vec3(8.0f, 8.0f, 8.0f));
		mCurrent = glm::rotate(mCurrent, fGlobalAngle + float(i)*50.0f* PIover180, glm::vec3(0.0f, 1.0f, 0.0f));
		spTextured.SetUniform("modelViewMatrix", mCurrent);
		glDrawArrays(GL_TRIANGLES, 0, 36);
	}

	// Now switch to only colored rendering

	glDisable(GL_TEXTURE_2D);
	spColored.UseProgram();
	glBindVertexArray(uiVAOs[1]);

	spColored.SetUniform("projectionMatrix", GetProjectionMatrix());
	
	// Render 5 transparent boxes

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDepthMask(0); // Disable writing to depth buffer

	for (int i = 0; i < 5; i++)
	{
		float fSign = 1.0f - float(i % 2)*2.0f; // Same case as before -  -1.0f or 1.0f
		glm::vec3 vPos = glm::vec3(fSign*15.0f, 0.0f, 50.0f - float(i)*25.0f);
		mCurrent = glm::translate(mModelView, vPos);
		mCurrent = glm::scale(mCurrent, glm::vec3(8.0f, 8.0f, 8.0f));
		mCurrent = glm::rotate(mCurrent, fGlobalAngle*0.8f + i*30.0f*PIover180, glm::vec3(1.0f, 0.0f, 0.0f)); // Just a variation of first rotating
		spColored.SetUniform("modelViewMatrix", mCurrent);
		spColored.SetUniform("vColor", vBoxColors[i]);
		glDrawArrays(GL_TRIANGLES, 0, 36);
	}
	glDisable(GL_BLEND);
	glDepthMask(1); // Re-enable writing to depth buffer

	fGlobalAngle += sof(100.0f*PIover180);
	cCamera.Update(this);
}
コード例 #6
0
void CSDLOpenGLWindow::RenderScene()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glEnable(GL_TEXTURE_2D);
	spDirectionalLight.UseProgram();
	glBindVertexArray(uiVAOs[0]);

	// Set light properties

	float fSine = sin(fSunAngle*PIover180);
	glm::vec3 vSunPos(cos(fSunAngle*PIover180) * 70, sin(fSunAngle*PIover180) * 70, 0.0);

	// We'll change color of skies depending on sun's position
	glClearColor(0.0f, std::max(0.0f, 0.9f*fSine), std::max(0.0f, 0.9f*fSine), 1.0f);

	spDirectionalLight.SetUniform("sunLight.vColor", glm::vec3(1.0f, 1.0f, 1.0f));
	spDirectionalLight.SetUniform("sunLight.fAmbientIntensity", 0.25f);
	spDirectionalLight.SetUniform("sunLight.fStrength", 1.0f);
	spDirectionalLight.SetUniform("sunLight.vDirection", -glm::normalize(vSunPos));

	spDirectionalLight.SetUniform("projectionMatrix", GetProjectionMatrix());

	glm::mat4 mView = cCamera.look();
	glm::mat4 mModel(1.0);

	spDirectionalLight.SetUniform("gSampler", 0);

	spDirectionalLight.SetUniform("modelViewMatrix", mView*mModel);
	spDirectionalLight.SetUniform("normalMatrix", glm::transpose(glm::inverse(glm::mat3(mModel))));
	spDirectionalLight.SetUniform("vColor", glm::vec4(1.0f, 1.0f, 1.0f, 1.0f));

	// Render ground

	tTextures[0].BindTexture();
	glDrawArrays(GL_TRIANGLES, 36, 6);

	tTextures[1].BindTexture();

	for (int i = 0; i < 5; i++)
	{
		float fSign = -1.0f + float(i % 2)*2.0f; // This just returns -1.0f or 1.0f (try to examine this)
		glm::vec3 vPos = glm::vec3(fSign*15.0f, 0.0f, 50.0f - float(i)*25.0f);
		mModel = glm::translate(glm::mat4(1.0), vPos);
		mModel = glm::scale(mModel, glm::vec3(8.0f, 8.0f, 8.0f));
		// We need to trasnsform normals properly, it's done by transpose of inverse matrix of rotations and scales
		spDirectionalLight.SetUniform("normalMatrix", glm::transpose(glm::inverse(glm::mat3(mModel))));
		spDirectionalLight.SetUniform("modelViewMatrix", mView*mModel);
		glDrawArrays(GL_TRIANGLES, 0, 36);
	}

	// Render 5 tori (plural of torus :D)

	tTextures[2].BindTexture();

	for (int i = 0; i < 5; i++)
	{
		float fSign = 1.0f - float(i % 2)*2.0f; // This just returns -1.0f or 1.0f (try to examine this)
		glm::vec3 vPos = glm::vec3(fSign*15.0f, 0.0f, 50.0f - float(i)*25.0f);
		mModel = glm::translate(glm::mat4(1.0), vPos);
		mModel = glm::rotate(mModel, fGlobalAngle + i*30.0f, glm::vec3(0.0f, 1.0f, 0.0f));
		spDirectionalLight.SetUniform("normalMatrix", glm::transpose(glm::inverse(glm::mat3(mModel))));
		spDirectionalLight.SetUniform("modelViewMatrix", mView*mModel);
		glDrawArrays(GL_TRIANGLES, 42, iTorusFaces1 * 3);
	}

	tTextures[3].BindTexture();

	// Render "sun" :D

	mModel = glm::translate(glm::mat4(1.0), vSunPos);
	spDirectionalLight.SetUniform("modelViewMatrix", mView*mModel);
	spDirectionalLight.SetUniform("normalMatrix", glm::transpose(glm::inverse(glm::mat3(mModel))));

	// It must shine
	spDirectionalLight.SetUniform("sunLight.fAmbientIntensity", 0.8f);

	glDrawArrays(GL_TRIANGLES, 42 + iTorusFaces1 * 3, iTorusFaces2 * 3);

	fGlobalAngle += sof(100.0f*PIover180);
	cCamera.Update(this);

	if (Keys::Key(SDL_SCANCODE_LEFT))fSunAngle -= sof(45.0f);
	if (Keys::Key(SDL_SCANCODE_RIGHT))fSunAngle += sof(45.0f);
}