Пример #1
0
int __attribute__((noreturn)) main(void) {
    uint16_t idlePolls = 0;

    /* initialize  */
    wdt_disable();      /* main app may have enabled watchdog */
    tiny85FlashInit();
    bootLoaderInit();
    
    
    if (bootLoaderCondition()) {
        initForUsbConnectivity();
        do {
            usbPoll();
            _delay_us(100);
            idlePolls++;
            
            if (events) idlePolls = 0;
            
            // these next two freeze the chip for ~ 4.5ms, breaking usb protocol
            // and usually both of these will activate in the same loop, so host
            // needs to wait > 9ms before next usb request
            if (isEvent(EVENT_ERASE_APPLICATION)) eraseApplication();
            if (isEvent(EVENT_WRITE_PAGE)) tiny85FlashWrites();
            
            if (isEvent(EVENT_FINISH)) { // || AUTO_EXIT_CONDITION()) {
                tiny85FinishWriting();
                
#               if BOOTLOADER_CAN_EXIT
                    _delay_ms(10); // removing delay causes USB errors
                    break;
#               endif
            }
// #           if BOOTLOADER_CAN_EXIT
//                 // exit if requested by the programming app, or if we timeout waiting for the pc with a valid app
//                 if (isEvent(EVENT_EXIT_BOOTLOADER) || AUTO_EXIT_CONDITION()) {
//                     //_delay_ms(10);
//                     break;
//                 }
// #           endif
            
            clearEvents();
            
        } while(bootLoaderCondition());  /* main event loop */
    }
    
    leaveBootloader();
}
Пример #2
0
bool F::receivedEvent ()
{
  for (Json::Value message : recvMessages) {
    if (isEvent (message) ) {
      return true;
    }
  }

  return false;
}
 void SoundEmitter::deleteSound()
 {
   InformationMessage("Sound", "SoundEmitter::deleteSound : enter") ;
   if (!isEvent())
   {
     alGetSourcei(getSource(), AL_SAMPLE_OFFSET, &m_posInBuffer) ;
     stopSound() ;
   }
   m_auxEffectSlot = 0;
   InformationMessage("Sound", "SoundEmitter::deleteSound : leaving") ;
 }
Пример #4
0
int 
MidiFile::readTrack() {
	enum {START, META, ENDING} state;
	
	uchar trkHdr[4];
	
	uchar trkSz[4];
	for (int i = 0; i < 4; i++) {
		trkHdr[i] = getNextChar(_target);
	}	trkHdr[4] = '\0';

	fprintf(stderr, "%s\n", trkHdr);
	assert(strcmp((char*)trkHdr, "MTrk") == 0);
	ulong size = 0;
	for (int i = 0; i < 4; i++) {
		trkSz[i] = getNextChar(_target);
		// fprintf(stderr, "%x\n", trkSz[i]);
		// size += trkSz[i];
	}

	size = getAsLong(trkSz);
	fprintf(stderr, "(alleged) track length: %lu\n", size);
	// fprintf(stderr, "%ld\n", atol((char*)trkSz));
	uchar c = 0;
	short prevNote = 0;

	int count = 0;
	// while ((c = getNextChar(midi)) != EOF) {
	for (int i = 0; ; i++) {
		c = getNextChar(_target);
		int tmp = isEvent(c, _curTrack);
		if ((c & 0x0F) == 0x8) {
			// fprintf(stderr, "%c\n", '-');
		} else if ((c & 0x0F) == 0x9) { //note on
			if (prevNote > c) {
				_contour.push_back('U');
			} else if (prevNote < c && count > 0) {
				_contour.push_back('D');
			} else {
				_contour.push_back('R');
			}
			count++;
			prevNote = c;
			// int tmp = getNextChar(midi);
			// fprintf(stderr, "note: %i\n", tmp);
			// fprintf(stderr, "%c\n", '+');
		}

		if (tmp) break;
	}
	fprintf(stderr, "note on events: %i\n", count);
	return 0;
}
Пример #5
0
Json::Value F::getFirstEvent ()
{
  for (auto it = recvMessages.begin(); it != recvMessages.end(); it++) {
    Json::Value message = *it;

    if (isEvent (message) ) {
      recvMessages.erase (it);
      return message;
    }
  }

  throw KurentoException (UNEXPECTED_ERROR, "Resonse not found");
}
        void SoundEmitter::handleSourceState()
        {
          bool should_be_active = isActive() ;

          if (!m_reader && should_be_active)
          {
            InformationMessage("Sound", "SoundEmitter::initSound real") ;
            m_reader = getManager()->createReader(getSoundFileName(),
                                                  isEvent(),
                                                  m_posInFile,
                                                  m_posInBuffer) ;

            alSourcei(getSource(),AL_SOURCE_RELATIVE,AL_FALSE) ;
          }

          if (should_be_active)
          {
            ALint state;
            alGetSourcei(getSource(),AL_SOURCE_STATE,&state) ;
            if (state == AL_STOPPED || state == AL_INITIAL)
            {
              startSound(m_viewpoint) ;
            }
          }

          if (m_reader && !should_be_active)
          {
            ALint state;
            alGetSourcei(getSource(),AL_SOURCE_STATE,&state) ;
            if (state == AL_PLAYING)
            {
              stopSound() ;
              m_reader = NULL ;
            }
          }
        }
Пример #7
0
int main(void) {
    /* initialize  */
    #ifdef RESTORE_OSCCAL
        uint8_t osccal_default = OSCCAL;
    #endif
    #if (!SET_CLOCK_PRESCALER) && LOW_POWER_MODE
        uint8_t prescaler_default = CLKPR;
    #endif

    wdt_disable();      /* main app may have enabled watchdog */
    tiny85FlashInit();
    bootLoaderInit();


    if (bootLoaderStartCondition()) {
        #if LOW_POWER_MODE
            // turn off clock prescalling - chip must run at full speed for usb
            // if you might run chip at lower voltages, detect that in bootLoaderStartCondition
            CLKPR = 1 << CLKPCE;
            CLKPR = 0;
        #endif

        initForUsbConnectivity();
        do {
            usbPoll();
            _delay_us(100);
            idlePolls++;

            // these next two freeze the chip for ~ 4.5ms, breaking usb protocol
            // and usually both of these will activate in the same loop, so host
            // needs to wait > 9ms before next usb request
            if (isEvent(EVENT_ERASE_APPLICATION)) eraseApplication();
            if (isEvent(EVENT_WRITE_PAGE)) tiny85FlashWrites();

#           if BOOTLOADER_CAN_EXIT
                if (isEvent(EVENT_EXECUTE)) { // when host requests device run uploaded program
                    break;
                }
#           endif

            clearEvents();

        } while(bootLoaderCondition());  /* main event loop runs so long as bootLoaderCondition remains truthy */
    }

    // set clock prescaler to desired clock speed (changing from clkdiv8, or no division, depending on fuses)
    #if LOW_POWER_MODE
        #ifdef SET_CLOCK_PRESCALER
            CLKPR = 1 << CLKPCE;
            CLKPR = SET_CLOCK_PRESCALER;
        #else
            CLKPR = 1 << CLKPCE;
            CLKPR = prescaler_default;
        #endif
    #endif

    // slowly bring down OSCCAL to it's original value before launching in to user program
    #ifdef RESTORE_OSCCAL
        while (OSCCAL > osccal_default) { OSCCAL -= 1; }
    #endif
    leaveBootloader();
}