/***************************************************************************************************************:')

U3Config.h

Main functions for the Labjack U3 handling.

Emilie Jude
Nassima Bouchelit
Fabrice Le Bars
Arunas Mazeika
Stéphane Bazeille
Some functions and parts of functions are from the file u3.c and the examples provided by www.labjack.com

2006-2007

Version 1.0.0

***************************************************************************************************************:)*/

#ifndef _U3CONFIG_H
#define _U3CONFIG_H

// C RunTime Header Files
#include <string.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// Windows Labjack header
#include "LabJackUD.h"

#ifdef OLD_HARDWARE_VERSION
#define TIMER_CLOCK_DIVISOR 8
#define FREQUENCY 24000000
#else
#define TIMER_CLOCK_DIVISOR 16
#define FREQUENCY 48000000
#endif // OLD_HARDWARE_VERSION

// 45,78 Hz of PWM frequency
#define PWM_FREQUENCY (((double)FREQUENCY/(double)TIMER_CLOCK_DIVISOR)/65536.0)
#define TIMER_DUTY_CYCLE2PULSE_WIDTH(timer_duty_cycle) ((1.0-(double)timer_duty_cycle/65536.0)/PWM_FREQUENCY)
#define PULSE_WIDTH2TIMER_DUTY_CYCLE(pulse_width) ((int)(65536.0-((double)pulse_width*PWM_FREQUENCY*65536.0/1000.0)))
// Timer value corresponding to a pulse width of 1,5 ms (motors blocked)
#define PWM_DUTY_CYCLE_DEFAULT (PULSE_WIDTH2TIMER_DUTY_CYCLE(1.5))

int U3Open(LJ_HANDLE* pHandle);
int U3Reset(LJ_HANDLE lngHandle);
int U3ConfigTimers(LJ_HANDLE lngHandle, int timer_clock_divisor, int timer_duty_cycle);
int U3GetTemperature(LJ_HANDLE lngHandle, double* pTemperature);
int U3GetVoltage(LJ_HANDLE lngHandle, long Channel, double* pVoltage);
int U3SetVoltage(LJ_HANDLE lngHandle, long Channel, double voltage);
int U3ModifyDutyCycle(LJ_HANDLE lngHandle, int timer_duty_cycle, int num_timer);
int U3Close(LJ_HANDLE* pHandle);

#endif // _U3CONFIG_H
