ui.c 1.67 KB
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <stdbool.h>
#include <termios.h>
#include "ui.h"
#include "bus.h"
#include "usb.h"

#define	TIME_LENGTH			24
#define	HEADER_TEXT_LENGTH	24
#define	LOG_LINES			35
#define	LOG_LENGTH			82
#define	IPS					2
#define	SCREEN_TIME			1000000/IPS
#define	SC_HOME				0
#define	SC_MAIN				1
#define	SPACES				"                                                                                                                                                                                                                                                                  "
char			started[TIME_LENGTH];
char			uid[HEADER_TEXT_LENGTH];
char			cmd[LOG_LENGTH];
pid_t			mainPid;
bool			heat = false;
bool			pump = false;
unsigned int	temp = 1;
unsigned int	debit = 1;
struct			termios old={0};
bool			uiStop = false;
int				actScreen = SC_HOME;

void stopUI()
{
	uiStop = true;
}

void setHeat(bool s)
{
	heat = s;
}

void setPump(bool s)
{
	pump = s;
}

void setTemp(unsigned int t)
{
	temp = t;
}

void setDebit(unsigned int d)
{
	debit = d;
}

void processScreen()
{
	if(actScreen == SC_HOME)
	{
		if(uid[0] == '\0')
			return;
		else
		{
			actScreen = SC_MAIN;
			displayPicture("img/main.boz");
		}
	}
}

void* drawUI(void* we)
{
	while(!uiStop)
	{
		processScreen();
		usleep(SCREEN_TIME);
	}

	return NULL;
}

void setTagName(char* tag)
{
	//time_t now = time(NULL);
	strcpy(uid, tag);
	//strftime(uidDate, HEADER_TEXT_LENGTH, "%F-%T:%d", localtime(&now));
}

void initUILog()
{
	cmd[0]='\0';
	started[0]='\0';
	mainPid = getpid();
	uid[0]='\0';
	initUSB();
}

void setStartTime(char* sT)
{
	strcpy(started, sT);
}