Ejemplo n.º 1
0
/**
* Worker thread does work
*/
double Worker::doWork()
{
    QVector<double> v, emo_vector;
    double sum = 0;
    QString title = getSongTitle(); // gets the song title

    while(songTitle->compare(title)  == 0) {
        double currentEmotion = getMood(); // gets to current mood value
        v.push_back(currentEmotion);
        if(v.size() ==  10) {
            for(int i = 0; i < v.size(); i++) {
                sum += v.at(i);
            }
            emo_vector.push_back(sum/v.size());
        }
        sleep(1);
    }

    sum = 0;
    // song finishes, compute the average
    for(int i = 0; i < emo_vector.size(); i++) {
        sum += emo_vector.at(i);
    }
    emotion = double(sum/emo_vector.size());

    // need to return the calculated value
    return emotion;
    }
Ejemplo n.º 2
0
void drawTimeline(void){
	uint8_t iter_higher_than_end = 0;
	uint8_t menuPage = 0;
	uint8_t totalPages = 0;
	char tempString[3];
	char timeBuf[18];
	char buf[18];

	printTime();
	printStringOnLine(1,"    Timeline      ", 1,NONE);

	uint8_t index = 0;
	
	start = getMemMapStartIndex();
	end = getMemMapEndIndex();
	iter = start;
	
	if(iter > end)
		iter_higher_than_end = 1;
		
	uint8_t currentMenuLength = getUnencrpytedRecordCount();
	
	for (uint8_t i = 0; i < cellsPerFrame; i++){
		char hourString[3] = {"0"};
		char minuteString[3] = {"0"};
		char yearString[3] = {"0"};
		char monthString[3] = {"0"};
		char dateString[3] = {"0"};
		
		if (currentMenuLength == 0){
			printTimeLineIsEmpty();
			break;
		}
		
		totalPages = ((currentMenuLength-1)/cellsPerFrame);
		menuPage = (selectionInMenu/cellsPerFrame);	
		index = ((menuPage)*cellsPerFrame)+i;
		
		iter = (index + start) % maxRecNum;

		selectedDate = getDate(getMemMapElement(iter));
		itoa(selectedDate, tempString, 10);
		if (selectedDate < 10)
			strcat(dateString, tempString);
		else{
			strcpy(dateString, tempString);
		}
		
		selectedMonth = getMonth(getMemMapElement(iter));
		itoa(selectedMonth, tempString, 10);
		if (selectedMonth < 10)
			strcat(monthString, tempString);
		else{
			strcpy(monthString, tempString);
		}

		selectedYear = getYear(getMemMapElement(iter));
		itoa(selectedYear, tempString, 10);
		if (selectedYear < 10)
			strcat(yearString, tempString);
		else{
			strcpy(yearString, tempString);
		}

		selectedHour = getHour(getMemMapElement(iter));
		itoa(selectedHour, tempString, 10);
		if (selectedHour < 10)
			strcat(hourString, tempString);
		else{
			strcpy(hourString, tempString);
		}
	
		selectedMinute = getMinute(getMemMapElement(iter));
		itoa(selectedMinute, tempString, 10);
		if (selectedMinute < 10)
			strcat(minuteString, tempString);
		else{
			strcpy(minuteString, tempString);
		}
		
		//USART_Sendbyte(totalPages);
		//USART_Sendbyte(menuPage);
		//USART_Sendbyte(index);
		//USART_Sendbyte(iter);
		//USART_Sendbyte(start);
		//USART_Sendbyte(end);
		
		//USART_Sendbyte(iter_higher_than_end);
		if(iter <= end || (i == 0 && currentMenuLength >= maxRecNum) || (iter_higher_than_end == 1)){
			if (iter <= end)
				iter_higher_than_end = 0;
			snprintf(timeBuf, sizeof(timeBuf), "%s%s%s%s%s%s%s%s%s%s", dateString, "/", monthString, "/", yearString, " - ", hourString, ":", minuteString, "  "); 
			snprintf(buf, sizeof(buf), "%s%s%s%s", activityArray[getActivity(getMemMapElement(iter))], "-", moodArray[getMood(getMemMapElement(iter))], "                  "); 	
			timeBuf[17] = ' ';
			buf[17] = ' ';
	
			drawMenuBands(menuPage,totalPages,TOPBAND);			
				
			//Draw Menu Contents
			if (i == selectionInFrame){
				printStringOnLine(i*2+yOffset,timeBuf, 1,NOBOXMENU);
				printTimelineStringOnLine(i*2+yOffset+1,buf, 1,faceArray[getMood(getMemMapElement(iter))]);
			}			
			else if (index < currentMenuLength){
				printStringOnLine(i*2+yOffset,timeBuf, 0,NOBOXMENU);
				printTimelineStringOnLine(i*2+yOffset+1,buf, 0,faceArray[getMood(getMemMapElement(iter))]);
			}
		}	
		else{
			printStringOnLine(i*2+yOffset,"                  ", 0,NOBOXMENU);
			printStringOnLine(i*2+yOffset+1,"                  ", 0,NOBOXMENU);
		}				
		drawMenuBands(menuPage,totalPages,BOTTOMBAND);			
	}		
	
}
Ejemplo n.º 3
0
//advance to next menu screen with current selection
void incrementMenuID(){
	clearLCD();
	previousMenuID = currentMenuID;
	//Coming From...
	//[Sleep]
	if (currentMenuID == 0 || currentMenuID == 1)
		currentMenuID = 10;
	
	//[Main Menu]
	else if (currentMenuID == 10){
		if(researchPeriod == 0){
			if (selectionInMenu == 0)
				currentMenuID = 20;
			else if (selectionInMenu == 1)
				currentMenuID = 30;
			else if (selectionInMenu == 2){
				currentMenuID = 40;
			}			
			else if (selectionInMenu == 3)
				currentMenuID = 70;
			else if (selectionInMenu == 4)
				currentMenuID = 0;
			else if (selectionInMenu == 5)
				currentMenuID = 80;
		}	
		else{
			if(selectionInMenu == 3 || selectionInMenu == 4 || selectionInMenu == 5){
				if (selectionInMenu == 3)
					currentMenuID = 70;
				else if(selectionInMenu == 4)
					currentMenuID = 0;
				else if(selectionInMenu == 5)
					currentMenuID = 80;
			}					
			else
				currentMenuID = 11;	
		}						
	}
	//[Log - Choose Activity]
	else if (currentMenuID == 20){
		selectedActivity = selectionInMenu;
		selectedYear = getTimeYear();
		selectedMonth = getTimeMonth();
		selectedDate = getTimeDate();
		selectedDay = getTimeDay();
		selectedHour = getTimeHour();
		selectedMinute = getTimeMinute();
		selectedSecond = getTimeSecond();
		currentMenuID++;
	}	
	//[Log - Choose Mood]	
	else if (currentMenuID == 21){
		selectedMood = selectionInMenu;
		currentMenuID++;		
	}
	//[Log - Confirm]
	else if (currentMenuID == 22){	

		insertRecord(selectedYear,selectedMonth,selectedDate, selectedDay, selectedHour,selectedMinute,selectedSecond,selectedActivity,selectedMood);
		currentMenuID = 10;	
	}
	//[View Timeline]
	else if (currentMenuID == 30){
		currentMenuID = 10;
	}
	
	//[Edit,Add,Remove]
	else if (currentMenuID == 40){
		uint8_t numberOfRecords = getUnencrpytedRecordCount();
		if (selectionInMenu == 0){
			if(numberOfRecords == 0){
				selectedYear = getTimeYear();
				selectedMonth = getTimeMonth();
				selectedDate = getTimeDate();
				selectedDay = getTimeDay();
				currentMenuID = 42;
			}	
			else{
				currentMenuID = 41;
			}							
		}
		else{				
			if(numberOfRecords == 0)
				currentMenuID = 43;
			else{
				if (selectionInMenu == 1)
				currentMenuID = 50;
				else if (selectionInMenu == 2)
				currentMenuID = 60;
			}				
		}				
	}
	
	//[Add]
	else if (currentMenuID == 41){
		uint8_t numberOfRecords = getUnencrpytedRecordCount();
		if(numberOfRecords != 0){
			iter = getMemMapStartIndex();
			selectedRecord = (selectionInMenu + iter) % maxRecNum;
			address = getMemMapElement(selectedRecord);
		}
		else{		
			selectedMinute = getTimeMinute();
			selectedSecond = getTimeSecond();
		}		
		selectedYear = getTimeYear();
		selectedMonth = getTimeMonth();
		selectedDate = getTimeDate();
		selectedDay = getTimeDay();
		selectedHour = getTimeHour();
		firstPass = 0;
		currentMenuID = 42;
	}
	
	//[Add - choose time]
	else if (currentMenuID == 42){
		if(timeSelection == HOUR)
			timeSelection = MINUTE;
		else
			currentMenuID = 44;	
	}
	
	//[Edit - NO RECORDS]
	else if (currentMenuID == 43){
		currentMenuID = 10;
	}

	//[Add - choose Activity]
	else if (currentMenuID == 44){
		selectedActivity = selectionInMenu;
		currentMenuID = 45;
	}
	
	//[Add - choose Mood]
	else if (currentMenuID == 45){
		selectedMood = selectionInMenu;
		currentMenuID = 46;
	}
	
	//[Add - Confirm]
	else if (currentMenuID == 46){
		
		insertRecord(selectedYear,selectedMonth,selectedDate, selectedDay, selectedHour,selectedMinute,0,selectedActivity,selectedMood);
		
		currentMenuID = 10;
	}
	
	//[Edit - choose time]
	else if (currentMenuID == 50){
		start = getMemMapStartIndex();
		selectedIndex = (selectionInMenu + start) % maxRecNum;
		address = getMemMapElement(selectedIndex);
		activityInRecord = getActivity(address);
		moodInRecord = getMood(address);
		selectedHour = getHour(address);
		selectedMinute = getMinute(address);
		currentMenuID = 51;
	}
	
	//[Edit - Mood or Act]
	else if (currentMenuID == 51){
		if (selectionInMenu == 0){
			firstPass = 0;
			currentMenuID = 52;
		}			
		else if (selectionInMenu == 1)
			currentMenuID = 56;
	}

	//[Edit - Act - Choose Time]
	else if (currentMenuID == 52){
		if(timeSelection == HOUR)
			timeSelection = MINUTE;
		else
		currentMenuID = 54;
	}

	//[Edit - Act - Choose Act]
	else if (currentMenuID == 54){
		selectedActivity = selectionInMenu;
		selectedMood = moodInRecord;
		currentMenuID = 55;
	}

	//[Edit - Act - Confirm]
	else if (currentMenuID == 55){
		setHourByAddress(address,selectedHour);
		setMinuteByAddress(address,selectedMinute);
		setActivityByAddress(address,selectedActivity);		
		currentMenuID = 10;
	}

	//[Edit - Mood - Choose Mood]
	else if (currentMenuID == 56){
		selectedMood = selectionInMenu;
		selectedActivity = activityInRecord;
		currentMenuID = 57;
	}

	//[Edit - Mood - Confirm]
	else if (currentMenuID == 57){
		setMoodByAddress(address,selectedMood);
		currentMenuID = 10;
	}
	
	//[Remove - choose record]
	else if (currentMenuID == 60){
		iter = getMemMapStartIndex();
		selectedRecord = (selectionInMenu + iter) % maxRecNum;
		address = getMemMapElement(selectedRecord);
		selectedActivity = getActivity(address);
		selectedMood = getMood(address);
		selectedHour = getHour(address);
		selectedMinute = getMinute(address);
		currentMenuID = 61;
	}

	//[Remove - confirm]
	else if (currentMenuID == 61){
		deleteRecord(selectedRecord);
		currentMenuID = 10;
	}

	//[Settings]
	else if (currentMenuID == 70){
		if(selectionInMenu == 0){
			firstPass = 0;
			currentMenuID = 71;	
		}			
		else if(selectionInMenu == 1)
			currentMenuID = 72;
		else if(selectionInMenu == 2)
			currentMenuID = 73;
	}
	
	//[Settings - modify Time]
	else if (currentMenuID == 71){
		if(timeSelection == HOUR)
			timeSelection = MINUTE;
		else if (timeSelection == MINUTE)
			timeSelection = DAY;
		else if (timeSelection == DAY)
			timeSelection = MONTH;
		else if (timeSelection == MONTH)
			timeSelection = YEAR;
		else{
			currentMenuID = 70;
			modifiedTimeFlag = 1;
		}			
	}

	//[Settings - Invert Screen]
	else if (currentMenuID == 72){
		invertColours = getInvertColourSetting();
		setInvertColourSetting(!invertColours);
		invertColours = !invertColours;
	}
	
	//[Settings - Reset]
	else if (currentMenuID == 73){
		currentMenuID = 74;
	}
	
	//[Settings - Reset]
	else if (currentMenuID == 74){
		resetRecords();
		currentMenuID = 70;
	}	
			
	//[Upload]
	else if (currentMenuID == 80){
		//currentMenuID = 10;
	}
	
	selectionInFrame = 0;
	selectionInMenu = 0;
}	
Ejemplo n.º 4
0
void drawModifyTimeslot(uint8_t screenType){
//Copy the list of used elements from datahandler.cpp (from memory)
//go through usedElements list to see which memory cells have valid data
//make a note of the index values that contain valid data
//now we know what indexes to look at when we want to print data to the screen.
	uint8_t iter_higher_than_end = 0;
	char tempString[3];
	
	uint8_t menuPage = 0;
	uint8_t totalPages = 0;
	
	char timeBuf[18];
	char buf[18];
	memset(buf, 0, sizeof(buf));
	memset(timeBuf, 0, sizeof(timeBuf));
	printTime();
	if(screenType == ADD){
		printStringOnLine(1,"   Add Timeslot   ", 1,NONE);
		printStringOnLine(6,"Choose nearby time", 1,NOBOXMENU);	
		printStringOnLine(7,"to one being added", 1,NOBOXMENU);	
	}
	else if(screenType == EDIT){
		printStringOnLine(1,"   Edit Timeslot  ", 1,NONE);
		printStringOnLine(6,"Choose a timeslot ", 1,NOBOXMENU);	
		printStringOnLine(7,"to edit           ", 1,NOBOXMENU);			
	}
	else if(screenType == REMOVE){
		printStringOnLine(1," Remove Timeslot  ", 1,NONE);
		printStringOnLine(6,"Choose a timeslot ", 1,NOBOXMENU);	
		printStringOnLine(7,"to remove         ", 1,NOBOXMENU);					
	}	
	
	
	uint8_t index = 0;
		
	start = getMemMapStartIndex();
	end = getMemMapEndIndex();
	iter = start;
	
	if(iter > end)
		iter_higher_than_end = 1;
		
	uint8_t currentMenuLength = getUnencrpytedRecordCount();
		
	for (uint8_t i = 0; i < cellsPerFrame; i++){
	char hourString[3] = {"0"};
	char minuteString[3] = {"0"};

	if (currentMenuLength == 0){
		printTimeLineIsEmpty();
		break;
	}

	totalPages = ((currentMenuLength-1)/cellsPerFrame);
	menuPage = (selectionInMenu/cellsPerFrame);
	index = ((menuPage)*cellsPerFrame)+i;

	iter = (index + start) % maxRecNum;
		
	selectedHour = getHour(getMemMapElement(iter));
	itoa(selectedHour, tempString, 10);
	if (selectedHour < 10)
		strcat(hourString, tempString);
	else{
		strcpy(hourString, tempString);
	}
	
	selectedMinute = getMinute(getMemMapElement(iter));
	itoa(selectedMinute, tempString, 10);
	if (selectedMinute < 10)
		strcat(minuteString, tempString);
	else{
		strcpy(minuteString, tempString);
	}

		if(iter <= end || (i == 0 && currentMenuLength >= maxRecNum) || (iter_higher_than_end == 1)){
		if (iter <= end)
			iter_higher_than_end = 0;
		snprintf(buf, sizeof(buf), "%s%s%s%s", hourString, ":", minuteString, "|"); 
		snprintf(buf, sizeof(buf), "%s%s%s%s%s", buf, activityArray[getActivity(getMemMapElement(iter))], "-", moodArray[getMood(getMemMapElement(iter))], "                  "); 	
		timeBuf[17] = ' ';
		buf[17] = ' ';
	
		drawMenuBands(menuPage,totalPages,TOPBAND);			
				
		//Draw Menu Contents
		if (i == selectionInFrame){
			printStringOnLine(i+yOffset,buf, 1,NOBOXMENU);
		}			
		else if (index < currentMenuLength){
			printStringOnLine(i+yOffset,buf, 0,NOBOXMENU);
		}
	}					
	else
		printStringOnLine(i+yOffset,"                  ", 0,NOBOXMENU);
		
	drawMenuBands(menuPage,totalPages,BOTTOMBANDMODIFY);
					
	}		
}
Ejemplo n.º 5
0
void Panda::pandaAddTaskPoints(int points){
	int newmood = getMood();
	newmood += points;
	setMood(newmood);
}