Exemplo n.º 1
0
/**
 * @return {@code true} if a value was selected. {@code false} on timeout.
 */
bool blinkLoop(
	void (*changed)(),	// called to update the value
	void (*show)(),		// called to show the current value
	void (*hide)(),	// called to blank out the current value
	void (*pushed)())	// handle selection
{	
	uint16_t lastChangeTime = ticks.seconds();
	uint8_t blinkTimer = 0;
	
	while(ticks.timeSince(lastChangeTime) < MENU_TIMEOUT){ // time out at 10 seconds
		if(rotaryEncoder.changed()){
			lastChangeTime = ticks.seconds();
			blinkTimer = 0;
			changed();
		}
		if (blinkTimer==0)
			show();
		else if (blinkTimer==128)
			hide();
			
		if (rotaryEncoder.pushed()) {
			rotaryEncoder.resetPushed();
			show();
			pushed();
			return true;
		}
		
		blinkTimer++;
		wait.millis(3); // delay for blinking		
	}
	return false;
}
Exemplo n.º 2
0
/**
 * point of entry
 */
int main(void) {

    // init IO and timers
    init();

    // turn on interrupts
    sei();

    // main loop
    while(1){

        // mode off and wake up timeout is empty
        if(mode == MODE_OFF && wakeup == 0){
            // sleep mcu
            sleep();
        }

        // check pushed button
        if(isPushed(BUTTON)){
            // trigger mode change
            trigger();
            // until button is not released
            while(pushed(BUTTON));
        }
    }

    return 0;
}
Exemplo n.º 3
0
void Control::mainc(){
	int buttonInfo[3];
	while(true){
		int status = rawData & 0x0FFF; // this will remove all the address bits
		int address = (rawData >> 16 ); //Shifting the adresses into address
		if(status){ //if a change is made in the status variable, we check which position is set to 1.
			int k = 0;
			for (int i = 0; i < 10; ++i)
			{
				k = status >> i;
				if(k&1){
					controlOutPort->burst_read(1, buttonInfo, address, 3, false);
					if(buttonInfo[2] != 0){ //Status != 0, its pushed.
						pushed(i);
						break;
					}else{
						cout << "Button " << i << " released" << endl << endl;
						break;
					}
				}
			}
		}
		rawData = 0; // resetting register
		status = 0;
		address = 0;
		wait(1000*ns);
	}

}
Exemplo n.º 4
0
bool exist(vector<vector<char> > &board, string word)
{
    /*
    从board中搜索word
    */
    H = board.size();
    W = board[0].size();
    word_size = word.size();
    vector<vector<bool> > pushed(H, vector<bool>(W, false));

    for (int i = 0; i < H; i += 1)
    {
        for (int j = 0; j < W; j += 1)
        {
            if (find(i, j, board, word, pushed))
            {
                return true;
            }
        }
    }

    return false;

    return false;
}
Exemplo n.º 5
0
void inline Switch::calcClick()
{ _singleClick = false;
  _doubleClick = false;
  if(pushed())
  { singleClickStarted = true;
    _doubleClick = (ms - pushedTime) < doubleClickPeriod; // pushedTime of previous push
    pushedTime = ms;
  }
  _singleClick = singleClickStarted && !_doubleClick && ((ms - pushedTime) > doubleClickPeriod); // pushedTime of previous push
  if(_singleClick || _doubleClick) singleClickStarted = false;
} 
Exemplo n.º 6
0
/**
 * check mode
 */
void trigger(void) {

    switch(mode){

        case MODE_START:
            if(isPushed(BREAK)){
                mode = MODE_OFF;
                OFF(ACC);
                OFF(IG);
                OFF(STARTER);
                // avoid falling to the MODE_OFF
                return;
            }
        break;

        // rotate key from IG to Starter or off
        case MODE_IG:
            if(isPushed(BREAK)){
                ON(ACC);
                ON(IG);
                ON(STARTER);
                while(pushed(BUTTON));
                OFF(STARTER);

                // TODO: check tachometer sensor the next mode
                mode = MODE_START;
            } else {
                mode = MODE_OFF;
                OFF(ACC);
                OFF(IG);
                OFF(STARTER);
                return;
            }

        break;

        // rotate key from ACC to IG
        case MODE_ACC:
            mode = MODE_IG;
            ON(ACC);
            ON(IG);
        break;

        // rotate key from off to ACC
        case MODE_OFF:
            mode = MODE_ACC;
            ON(ACC);
            OFF(IG);
        break;

    }
}
Exemplo n.º 7
0
// --------------------------------------------------------------------------------
// void DumpToFileL( TPtrC8 aBuffer )
// --------------------------------------------------------------------------------
void DumpToFileL( TPtrC8 aBuffer )
	{
	RFs fileSession;
	TInt pushed(0);
	if( fileSession.Connect() == KErrNone )
		{
		CleanupClosePushL(fileSession);
		pushed++;
		RFile file;
#ifdef __WINS__
		if( file.Open(fileSession, KNSmlDebugOutputName(), EFileShareAny|EFileWrite) == KErrNone )
#else
		HBufC* outputName = HBufC::NewLC( KNSmlDebugOutputName().Length()+1 );
		pushed++;
		TPtr namePtr = outputName->Des();
		TDriveInfo driveInfo;
		for ( TUint driveNumber = EDriveA; driveNumber <= EDriveZ; driveNumber++ ) 
			{
			fileSession.Drive( driveInfo, driveNumber );
			if ( KDriveAttRemovable & driveInfo.iDriveAtt ) 
				{
				// this is MMC
				namePtr.Insert( 0, KNSmlDebugDriveLetters().Mid( driveNumber, 1 ));
				namePtr.Insert( 1, KNSmlDebugOutputName() );
				break;
				}
			}
		if( file.Open(fileSession, *outputName, EFileShareAny|EFileWrite) == KErrNone )
#endif

			{
			CleanupClosePushL(file);
			TInt pos(0);
			file.Seek(ESeekEnd, pos);
			RMutex mutex;
			NSmlGrabMutexLC(mutex, KNSmlDebugMutexName());
			TInt result = file.Write(aBuffer);
			TInt result2 = file.Flush();
			mutex.Signal();
			CleanupStack::PopAndDestroy(2); // file, mutex
			User::LeaveIfError(result);
			User::LeaveIfError(result2);
			}
		CleanupStack::PopAndDestroy( pushed ); // fileSession and (for target) outputName
		}
	}
Exemplo n.º 8
0
void doNSmlDebugInitL()
	{
	TInt pushed(0);
	RFs fileSession;
	User::LeaveIfError(fileSession.Connect());
	CleanupClosePushL(fileSession);
	pushed++;

	TDriveInfo driveInfo;
	for ( TUint driveNumber = EDriveA; driveNumber <= EDriveZ; driveNumber++ ) 
		{
		fileSession.Drive( driveInfo, driveNumber );
		if ( KDriveAttRemovable & driveInfo.iDriveAtt ) 
			{
			RFile file;
			HBufC* outputName = HBufC::NewLC( KNSmlDebugOutputName().Length()+1 );
			pushed++;
			TPtr namePtr = outputName->Des();
			namePtr.Insert( 0, KNSmlDebugDriveLetters().Mid( driveNumber, 1 ));
			namePtr.Insert( 1, KNSmlDebugOutputName() );
			
			HBufC* outputDumpName = HBufC::NewLC( KNSmlDebugDumpName().Length()+1 );
			pushed++;
			TPtr nameDumpPtr = outputDumpName->Des();
			nameDumpPtr.Insert( 0, KNSmlDebugDriveLetters().Mid( driveNumber, 1 ));
			nameDumpPtr.Insert( 1, KNSmlDebugDumpName() );
			
			fileSession.Delete(*outputName);
			fileSession.Delete(*outputDumpName);	

#if !defined(__SML_DEVELOPER_DEBUG__)
				{
				User::LeaveIfError(file.Create(fileSession, *outputName, EFileShareAny));
				file.Close();
				}
#endif
				{
				User::LeaveIfError(file.Create(fileSession, *outputDumpName, EFileShareAny));
				file.Close();
				break;
				}
			}
		}
	CleanupStack::PopAndDestroy( pushed ); // fileSession
	}
void TestQueue_MPSC(unsigned iterations, unsigned threadCount, unsigned queueSize) {

  BlockingQueue<int> bq(queueSize);

  ParallelProcessor processor(threadCount);
  std::atomic<unsigned> counter(0);
  std::atomic<int64_t> pushed(0);

  processor.spawn([&]{
    int64_t sum = 0;

    for(;;) {
      unsigned value = counter.fetch_add(1);
      if (value >= iterations)
        break;

      bq.push(value);
      sum += value;
    }

    pushed += sum;
    // std::cout << "Sum: " << sum << std::endl;
  });

  int64_t expectedSum = 0;

  for (unsigned i = 0; i < iterations; ++i) {
    int value;
    ASSERT_TRUE(bq.pop(value));
    expectedSum += i;
  }

  ASSERT_EQ(0, bq.size());

  processor.join();

  ASSERT_EQ(expectedSum, pushed);
}
Exemplo n.º 10
0
bool Switch::poll()
{ _longPress = _doubleClick = false;
  bool newlevel = digitalRead(pin);

  if(!longPressLatch)
  { _longPress = on() && ((long)(millis() - pushedTime) > longPressDelay); // true just one time between polls
    longPressLatch = _longPress; // will be reset at next switch
  }

  if((newlevel != level) & (millis() - _switchedTime >= debounceDelay))
  { _switchedTime = millis();
    level = newlevel;
    _switched = 1;
    longPressLatch = false;

    if(pushed())
    { _doubleClick = (long)(millis() - pushedTime) < doubleClickDelay;
      pushedTime = millis();
    }
    return _switched;
  }
  return _switched = 0;
}
Exemplo n.º 11
0
/**
 * Check button is pushed
 */
uint8_t isPushed(uint8_t bit){
    return pushed(bit) && wait() && pushed(bit);
}
Exemplo n.º 12
0
void EditMetadataDialog::wireUpTheme()
{
    artist_edit = getUIRemoteEditType("artist_edit");
    if (artist_edit)
    {
        artist_edit->createEdit(this);
        connect(artist_edit, SIGNAL(loosingFocus()), this, SLOT(editLostFocus()));
    }

    compilation_artist_edit = getUIRemoteEditType("compilation_artist_edit");
    if (compilation_artist_edit)
    {
        compilation_artist_edit->createEdit(this);
        connect(compilation_artist_edit, SIGNAL(loosingFocus()), this, SLOT(editLostFocus()));
    }

    album_edit = getUIRemoteEditType("album_edit");
    if (album_edit)
    {
        album_edit->createEdit(this);
        connect(album_edit, SIGNAL(loosingFocus()), this, SLOT(editLostFocus()));
    }

    title_edit = getUIRemoteEditType("title_edit");
    if (title_edit)
    {
        title_edit->createEdit(this);
        connect(title_edit, SIGNAL(loosingFocus()), this, SLOT(editLostFocus()));
    }

    genre_edit = getUIRemoteEditType("genre_edit");
    if (genre_edit)
    {
        genre_edit->createEdit(this);
        connect(genre_edit, SIGNAL(loosingFocus()), this, SLOT(editLostFocus()));
    }

    year_edit = getUIRemoteEditType("year_edit");
    if (year_edit)
    {
        year_edit->createEdit(this);
        connect(year_edit, SIGNAL(loosingFocus()), this, SLOT(editLostFocus()));
    }

    track_edit = getUIRemoteEditType("track_edit");
    if (track_edit)
    {
        track_edit->createEdit(this);
        connect(track_edit, SIGNAL(loosingFocus()), this, SLOT(editLostFocus()));
    }

    lastplay_text = getUITextType("lastplay_text");
    playcount_text = getUITextType("playcount_text");
    filename_text = getUITextType("filename_text");
    rating_image = getUIRepeatedImageType("rating_image");

    compilation_check = getUICheckBoxType("compilation_check");
    if (compilation_check)
    {
        connect(compilation_check, SIGNAL(pushed(bool)), this, SLOT(checkClicked(bool)));
    }

    searchartist_button = getUIPushButtonType("searchartist_button");
    if (searchartist_button)
    {
        connect(searchartist_button, SIGNAL(pushed()), this, SLOT(searchArtist()));
    }

    searchcompilation_artist_button = getUIPushButtonType("searchcompilation_artist_button");
    if (searchcompilation_artist_button)
    {
        connect(searchcompilation_artist_button, SIGNAL(pushed()), this, SLOT(searchCompilationArtist()));
    }

    searchalbum_button = getUIPushButtonType("searchalbum_button");
    if (searchalbum_button)
    {
        connect(searchalbum_button, SIGNAL(pushed()), this, SLOT(searchAlbum()));
    }

    searchgenre_button = getUIPushButtonType("searchgenre_button");
    if (searchgenre_button)
    {
        connect(searchgenre_button, SIGNAL(pushed()), this, SLOT(searchGenre()));
    }

    metadata_button = getUITextButtonType("metadata_button");
    if (metadata_button)
    {
        metadata_button->setText(tr("Track Info."));
        connect(metadata_button, SIGNAL(pushed()), this, SLOT(switchToMetadata()));
    }

    albumart_button = getUITextButtonType("albumart_button");
    if (albumart_button)
    {
        albumart_button->setText(tr("Album Art"));
        connect(albumart_button, SIGNAL(pushed()), this, SLOT(switchToAlbumArt()));
    }

    dbstatistics_button = getUITextButtonType("dbstats_button");
    if (dbstatistics_button)
    {
        dbstatistics_button->setText(tr("Statistics"));
        connect(dbstatistics_button, SIGNAL(pushed()), this, SLOT(switchToDBStats()));
    }

    done_button = getUITextButtonType("done_button");
    if (done_button)
    {
        done_button->setText(tr("Done"));
        connect(done_button, SIGNAL(pushed()), this, SLOT(showSaveMenu()));
    }

    coverart_image = getUIImageType("coverart_image");
    coverart_grid = getUIImageGridType("coverart_grid");
    if (coverart_grid)
    {
        connect(coverart_grid, SIGNAL(itemChanged(ImageGridItem *)),
                this, SLOT(gridItemChanged(ImageGridItem *)));
    }

    imagetype_text = getUITextType("imagetype_text");
    imagefilename_text = getUITextType("imagefilename_text");

    rating_button = getUISelectorType("rating_button");
    if (rating_button)
    {

    }

    buildFocusList();
}
Exemplo n.º 13
0
// --------------------------------------------------------------------------------
// void doNSmlDebugDumpL( void* aData, TInt aLength, TText8* aFile, TInt aLine, const TText8* aMsg )
// --------------------------------------------------------------------------------
void doNSmlDebugDumpL( void* aData, TInt aLength, TText8* aFile, TInt aLine, const TText8* aMsg )
	{
	TInt pushed(0);
	HBufC8* pDateBuffer8 = HBufC8::NewLC(64);
	pushed++;
	TPtr8 dateBuffer8 = pDateBuffer8->Des();
	HBufC8* pTimeBuffer8 = HBufC8::NewLC(64);
	pushed++;
	TPtr8 timeBuffer8 = pTimeBuffer8->Des();
	NSmlGetDateAndTimeL(dateBuffer8, timeBuffer8);
	TPtrC8 data(REINTERPRET_CAST(TUint8*, aData), aLength);
	TPtrC8 fileName(aFile);
	HBufC8* buffer8 = HBufC8::NewLC(KBufferSize);
	pushed++;
	TPtr8 ptrBuffer8 = buffer8->Des();
	TPtrC8 msg(aMsg);
	if( !msg.Length() )
		{
#if !defined(__SML_DEVELOPER_DEBUG__)
		ptrBuffer8.Format(_L8("[%S %S File: %S Line: %d Length: %d]\r\n"), &dateBuffer8, &timeBuffer8, &fileName, aLine, aLength);
#else
		ptrBuffer8.Format(_L8("[%S %S Length: %d]\r\n"), &dateBuffer8, &timeBuffer8, aLength);
#endif
		}
	else
		{
#if !defined(__SML_DEVELOPER_DEBUG__)
		ptrBuffer8.Format(_L8("[%S %S File: %S Line: %d Length: %d] %S\r\n"), &dateBuffer8, &timeBuffer8, &fileName, aLine, aLength, &msg);
#else
		ptrBuffer8.Format(_L8("[%S %S Length: %d] %S\r\n"), &dateBuffer8, &timeBuffer8, aLength, &msg);
#endif
		}
	// Now we're ready to write into file
	RFs fileSession;
	if( fileSession.Connect() == KErrNone )
		{
		CleanupClosePushL(fileSession);
		pushed++;
		RFile file;
#ifdef __WINS__
		if( file.Open(fileSession, KNSmlDebugDumpName(), EFileShareAny|EFileWrite) == KErrNone )
#else
		HBufC* outputDumpName = HBufC::NewLC( KNSmlDebugDumpName().Length()+1 );
		pushed++;
		TPtr nameDumpPtr = outputDumpName->Des();
		TDriveInfo driveInfo;
		for ( TUint driveNumber = EDriveA; driveNumber <= EDriveZ; driveNumber++ ) 
			{
			fileSession.Drive( driveInfo, driveNumber );
			if ( KDriveAttRemovable & driveInfo.iDriveAtt ) 
				{
				// this is MMC
				nameDumpPtr.Insert( 0, KNSmlDebugDriveLetters().Mid( driveNumber, 1 ));
				nameDumpPtr.Insert( 1, KNSmlDebugDumpName() );
				break;
				}
			}
		if( file.Open(fileSession, *outputDumpName, EFileShareAny|EFileWrite) == KErrNone )
#endif

			{
			CleanupClosePushL(file);
			TInt pos(0);
			file.Seek(ESeekEnd, pos);
			RMutex mutex;
			NSmlGrabMutexLC(mutex, KNSmlDebugMutexNameDump());
			TInt result1 = file.Write(ptrBuffer8);
			TInt result2 = file.Write(data);
			TInt result3 = file.Write(_L8("\r\n\r\n"));
			TInt result4 = file.Flush();
			mutex.Signal();
			CleanupStack::PopAndDestroy(2); // file, mutex
			User::LeaveIfError(result1);
			User::LeaveIfError(result2);
			User::LeaveIfError(result3);
			User::LeaveIfError(result4);
			}
		}
	CleanupStack::PopAndDestroy( pushed ); // buffer8, pDateBuffer8, pTimeBuffer8
	}