TaskManager<MAX_TASKS>::TaskManager(void) {
    Aversive::init();
    _current = 0;

    ClientThread::instance().setSyncFunction([&](long long t){
        _current = t;
        processTasks();
      });
  }
Beispiel #2
0
/*** NOTIFICATIONS *****************************************************************/
void lcd_notifications(void)
{
	tag = 0;
	
	ButtonStruct btnHome  = TouchInit(5);
	ButtonStruct btnClear = TouchInit(6);
	
	draw_notifications_screen(&btnHome, &btnClear);
	
	while(1)
	{	
		/* Process Tasks */
		processTasks();
		
		/* Redraw in every sec */
		if(FLAG_datetime)
		{ 
			draw_notifications_screen(&btnHome, &btnClear);
			FLAG_datetime = 0;
		}
		
		tag = HOST_MEM_RD32(REG_TOUCH_TAG);
		switch(tag)
		{
			case 5:
				if(!btnHome.pressed)
				{
					btnHome.pressed = 1;
					draw_notifications_screen(&btnHome, &btnClear);
				}
			break;
			
			case 6:
				if(!btnClear.pressed)
				{
					btnClear.pressed = 1;
					draw_notifications_screen(&btnHome, &btnClear);
				}
			break;
			
			default:
				if(btnHome.pressed || btnClear.pressed)
				{
					if(buttonIsClicked(&btnHome, tag))  { return; }
					if(buttonIsClicked(&btnClear, tag)) { clearNotif(); }
					
					btnHome.pressed = 0;
					btnClear.pressed = 0;
					
					draw_notifications_screen(&btnHome, &btnClear);
				}
			break;
		}
		
	} /* while */
}
Beispiel #3
0
void EventLoop::Impl::loopOnce(uint32_t max_wait_ms)
{
    processTasks();
    unsigned long wait_ms = max_wait_ms;
    timer_mgr_->checkExpire(&wait_ms);
    if(wait_ms > max_wait_ms) {
        wait_ms = max_wait_ms;
    }
    poll_->wait((uint32_t)wait_ms);
}
Beispiel #4
0
/*** STATUS ************************************************************************/
void lcd_status(void)
{
	tag = 0;
	ButtonStruct btnHome = TouchInit(5);
	
	draw_status_screen(&btnHome);
	
	while(1)
	{	
		/* Process Tasks */
		processTasks();
		
		/* Get PeriphConnection Status */
		if(FLAG_getPeriphConnection)
		{
			getPeriphConnection(&PeriphConnection);
			draw_status_screen(&btnHome);
			FLAG_getPeriphConnection = 0;
		}
		
		tag = HOST_MEM_RD32(REG_TOUCH_TAG);
		switch(tag)
		{
			case 5:
				if(!btnHome.pressed)
				{
					btnHome.pressed = 1;
					draw_status_screen(&btnHome);
				}
			break;
			
			default:
				if(btnHome.pressed)
				{
					if(buttonIsClicked(&btnHome, tag)) { return; }
					btnHome.pressed = 0;
					
					draw_status_screen(&btnHome);
				}
			break;
		}
		
	} /* while */
}
Beispiel #5
0
void EventLoop::Impl::loop(uint32_t max_wait_ms)
{
    while (!stop_loop_) {
        loopOnce(max_wait_ms);
    }
    processTasks();
    
    while (pending_objects_) {
        auto obj = pending_objects_;
        pending_objects_ = pending_objects_->next_;
        obj->onLoopExit();
    }
    {
        LockGuard g(obs_mutex_);
        ObserverCallback cb;
        while (obs_queue_.dequeue(cb)) {
            cb(LoopActivity::EXIT);
        }
    }
    KUMA_INFOXTRACE("loop, stopped");
}
Beispiel #6
0
 void ResourceProcessor::run(bool async)
 {
     if (!async)
         processTasks();
     else
     {
         m_taskThread = move(unique_ptr<thread, function<void(thread*)>>(new thread(
             // task
             [this]()
         {
             this->processTasks();
         }),
             // deleter
             [&](thread* ptr) {
                 {
                     lock_guard<mutex> lock(m_taskMutex);
                     m_taskAlive = false;
                 }
                 ptr->join();
                 delete ptr;
         }));
     }
 }
Beispiel #7
0
/*** ALERT *************************************************************************/
void lcd_alert(SensorStruct* sensor)
{
	tag = 0;
	ButtonStruct btnOk = TouchInit(1);
	draw_alert_screen(sensor, &btnOk);
	
	while(1)
	{
		/* Process Tasks */
		processTasks();
		
		/* Redraw if new alert comes during display */
		if(!(sensor->alert & 0x01))
		{
			draw_alert_screen(sensor, &btnOk);
			setAlertStateBit(sensor);
		}
		
		tag = HOST_MEM_RD32(REG_TOUCH_TAG);
		
		//button pressed
		if(tag == 1 && !btnOk.pressed)
		{
			btnOk.pressed = 1;
			draw_alert_screen(sensor, &btnOk);
		}
		
		//button released
		if(tag != 1 && btnOk.pressed)
		{
			if(buttonIsClicked(&btnOk, tag)) { return; }
			btnOk.pressed = 0;
			draw_alert_screen(sensor, &btnOk);
		}
	}
}
int main(int argc, char *argv[]){
	
	//initiates our list that stores schedule
	List *list = createList();
	FILE *fr;
	char buffer[1024];
	char* token;
	uint32_t clock, exectime, reptime;
	//opens the file passed in as argument
	fr = fopen(argv[1], "rt");
	
	//error checking for file
	if(!fr){
		perror("Error");
		return(-1);		
	}	
	
	//loops through all lines in the file
	while(fgets(buffer, 1025, fr) != NULL){
		token = strtok(buffer, " \n");
		//adding a non-repeating task
		if(strcmp(token, "ADD") == 0){
			exectime = atoi(strtok(NULL, " "));
			//only add the task if it is after the current time
			if(exectime > clock){
				token = strtok(NULL, "\n");
				//creates node for word
				Node *item = createNode(token, exectime, 0);
				//inserts the node into list
				list = insert(list, item);
			}
		}
		//adding a repeating task
		else if(strcmp(token, "ADDREP") == 0){
			exectime = atoi(strtok(NULL, " "));
			reptime = atoi(strtok(NULL, " "));
			//if the execute time is before clock, add repeat time until it isnt
			while(exectime < clock) exectime += reptime;
			token = strtok(NULL, "\n");
			Node *item = createNode(token, exectime, reptime);
			list = insert(list, item);
		}
		//time update
		else if(strcmp(token, "TIME") == 0){
			token = strtok(NULL, " ");
			clock = atoi(token);
			//processes all tasks with new time
			list = processTasks(list, clock);
		}
		//deleting a task
		else if(strcmp(token, "DEL") == 0){
			token = strtok(NULL, "\n");
			//deletes node with the name
			list = deleteNode(list, token);
		}
		//lists all tasks
		else if(strcmp(token, "LIST") == 0) printList(list, clock);
		//clears list
		else if(strcmp(token, "CLEAR") == 0) clearList(list);
	}

	return 0;
	
}
Beispiel #9
0
void CANWorker::runWorker() {
	processTasks();
}
Beispiel #10
0
/*** MAIN **************************************************************************/
uint8_t lcd_main(void)
{
	tag = 0;
	
	/* init buttons */
	ButtonStruct btnStartStop 		= TouchInit(1);
	ButtonStruct btnStatus 			= TouchInit(2);
	ButtonStruct btnNotifications 	= TouchInit(3);
	ButtonStruct btnSettings 		= TouchInit(4);
	ButtonStruct btnSetDate 		= TouchInit(5);
	
	/* write background into memory */
	store_main_default();
	
	/* first start: display buttons & others */
	draw_main_screen(&btnStartStop, &btnStatus, &btnNotifications, &btnSettings, &btnSetDate);
	
	while(1)
	{
		/* Process Tasks */
		processTasks();
		
		/* Display Alerts */
		if(EnableAlerts)
		{
			/* Check Sensor1 for Alerts to display */
			if(isAlert(&Sensor1) && !FLAG_dispAlert)
			{
				FLAG_beepAlert = 1;
				FLAG_dispAlert = 1;
				setAlertStateBit(&Sensor1);
				lcd_alert(&Sensor1);
				Sensor1.alertTimer = ALERT_TIME;
				FLAG_dispAlert = 0;
			}
			
			/* Check Sensor2 for Alerts to display */
			if(isAlert(&Sensor2) && !FLAG_dispAlert)
			{
				FLAG_beepAlert = 1;
				FLAG_dispAlert = 1;
				setAlertStateBit(&Sensor2);
				lcd_alert(&Sensor2);
				Sensor2.alertTimer = ALERT_TIME;
				FLAG_dispAlert = 0;
			}
			
			/* Check Sensor3 for Alerts to display */
			if(isAlert(&Sensor3) && !FLAG_dispAlert)
			{
				FLAG_beepAlert = 1;
				FLAG_dispAlert = 1;
				setAlertStateBit(&Sensor3);
				lcd_alert(&Sensor3);
				Sensor3.alertTimer = ALERT_TIME;
				FLAG_dispAlert = 0;
			}
		}
		
		/* Draw date & time if needed AND redraw screen in every sec */
		if(FLAG_datetime)
		{ 
			draw_main_screen(&btnStartStop, &btnStatus, &btnNotifications, &btnSettings, &btnSetDate);
			FLAG_datetime = 0;
		}
		
		/* Check Touch TAG */
		tag = HOST_MEM_RD32(REG_TOUCH_TAG);
		
		switch(tag)
		{
			case 1:		// start/stop button
			if(!btnStartStop.pressed)
				{
					btnStartStop.pressed = 1;
					draw_main_screen(&btnStartStop, &btnStatus, &btnNotifications, &btnSettings, &btnSetDate);
				}
			break;
			
			case 2:		// status button
				if(!btnStatus.pressed)
				{
					btnStatus.pressed = 1;
					draw_main_screen(&btnStartStop, &btnStatus, &btnNotifications, &btnSettings, &btnSetDate);
				}
			break;
			
			case 3:		// notifications button
				if(!btnNotifications.pressed)
				{
					btnNotifications.pressed = 1;
					draw_main_screen(&btnStartStop, &btnStatus, &btnNotifications, &btnSettings, &btnSetDate);
				}
			break;
			
			case 4:		// settings button
				if(!btnSettings.pressed)
				{
					btnSettings.pressed = 1;
					draw_main_screen(&btnStartStop, &btnStatus, &btnNotifications, &btnSettings, &btnSetDate);
				}
			break;
			
			case 5:		// set Date & Time
				if(!btnSetDate.pressed)
				{
					btnSetDate.pressed = 1;
					draw_main_screen(&btnStartStop, &btnStatus, &btnNotifications, &btnSettings, &btnSetDate);
				}
			break;
			
			case 11:	// Select Sensor1 as Favorite
				SensorFav = &Sensor1;
				draw_main_screen(&btnStartStop, &btnStatus, &btnNotifications, &btnSettings, &btnSetDate);
			break;	
			case 12:	// Select Sensor2 as Favorite
				SensorFav = &Sensor2;
				draw_main_screen(&btnStartStop, &btnStatus, &btnNotifications, &btnSettings, &btnSetDate);
			break;
			case 13:	// Select Sensor3 as Favorite
				SensorFav = &Sensor3;
				draw_main_screen(&btnStartStop, &btnStatus, &btnNotifications, &btnSettings, &btnSetDate);
			break;
			
			default:	//only if something is pressed
				if(btnStartStop.pressed || btnStatus.pressed || btnNotifications.pressed || btnSettings.pressed || btnSetDate.pressed)
				{
					if(buttonIsClicked(&btnStartStop, tag))		{ Mode.state ^= ON; }
					if(buttonIsClicked(&btnStatus, tag))		{ return btnStatus.tag; }
					if(buttonIsClicked(&btnNotifications, tag))	{ /*Mode.type ^= 1;*/ return btnNotifications.tag; }
					if(buttonIsClicked(&btnSettings, tag))		{ return btnSettings.tag; }
					if(buttonIsClicked(&btnSetDate, tag))		{ return btnSetDate.tag; }
					
					btnStartStop.pressed = 0;
					btnStatus.pressed = 0;
					btnNotifications.pressed = 0;
					btnSettings.pressed	= 0;
					btnSetDate.pressed = 0;
					
					draw_main_screen(&btnStartStop, &btnStatus, &btnNotifications, &btnSettings, &btnSetDate);
				}
			break;
		} /* switch */
		
	} /* while */
	
}