#include "stdafx.h"
#include "USB_Com.h"

#ifndef SLOT_CTRL_H
#define SLOT_CTRL_H

#define SEMAFOR_OFF 0
#define SEMAFOR_MANUAL 1
#define SEMAFOR_AUTOFRAC 2
#define SEMAFOR_AUTOREAL 3
#define GREEN 0
#define YELLOW 1
#define RED 2
#define ORANGE 3

#define GREEN1 0x09
#define YELLOW1 0x0a
#define RED1 0x0c
#define ORANGE1 0x0e

#define GREEN2 0x90
#define YELLOW2 0x50
#define RED2 0x30
#define ORANGE2 0x70

#define GREEN_BITS(a) ((0<<((a)*2+1))|(0<<(a)*2))
#define YELLOW_BITS(a) ((0<<((a)*2+1))|(1<<(a)*2))
#define RED_BITS(a) ((1<<((a)*2+1))|(0<<(a)*2))
#define ORANGE_BITS(a) ((1<<((a)*2+1))|(1<<(a)*2))

typedef struct SEMAFOR{
	UINT8 state;
	unsigned int active;
	unsigned int delay;
	unsigned char stage;
	unsigned long time;
	unsigned int targetTime;
	unsigned int sec_color[4];
}semafor;

typedef struct SEMAFORS{
	unsigned char mode;
	unsigned char pocet;
	unsigned int linkedforauto[3][6];
	semafor semafor[6];	
}semafors;

typedef struct DPOT{
	unsigned char aktivni;
	unsigned char pocet;
	char value[3];	
}digpot;
#endif

void semafor_init(semafors *init);
int semafor_add(semafors *choice);
int semafor_mode(semafors *choice, unsigned char mode);
int semafor_remove(semafors *choice, unsigned int No);
int semafor_state(semafor *choice, UINT8 state);
int semafor_cycle(semafors *choice);
int semafor_times(semafor *choice, unsigned int g , unsigned int y , unsigned int r, unsigned int o, unsigned int delay);
int delay2stage(semafors*choice);
UINT8 *semaforMsg1(semafors *all);
UINT8 *semaforMsg2(semafors *all);
char *semafordata(semafors *all);


void dpot_init(digpot *init);
int dpot_changeone(digpot *syst, int dpotNo, int value);
int dpot_changeall(digpot *stav, int value1, int value2, int value3);
int dpot_stop(digpot *stav);
UINT8 dpot_speed2pos(int value, bool safe);
UINT8 *oneDpotMsg(UINT8 dpotNo, UINT8 speed);
UINT8 *twoDpotMsg(UINT8 speed1, UINT8 speed2);
char *dpotData(digpot *data);
