// The following ifdef block is the standard way of creating macros which make exporting 
// from a DLL simpler. All files within this DLL are compiled with the HMITRAPI_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see 
// HMITRAPI_API functions as being imported from a DLL, whereas this DLL sees symbols
// defined with this macro as being exported.

#ifdef __cplusplus
extern "C"
#endif
{

#ifdef HMITRAPI_EXPORTS
#define HMITRAPI_API __declspec(dllexport)
#else
#define HMITRAPI_API __declspec(dllimport)
#endif

#define HMIAPI_INTERNAL

#define HMISTATUS_INVALID_REQUEST 1
#define HMISTATUS_NOREGISTERWRITTEN 2
#define HMISTATUS_COPY_E2P_FAILED 3
#define HMISTATUS_RANGE_ERRROR 4
#define HMISTATUS_MAX 4

#ifdef HMIAPI_INTERNAL
/* 1:1 Relation between Error number above and this string */
//static const char *hmistatus_errors[] =
LPCWSTR hmistatus_errors[] =
{
	L"NULL",
	L"Invalid request",
	L"No register written",
	L"Copy to E2P failed",
	L"Range error"
};
#endif

#define HMIERR_FILEOPEN -1
#define HMIERR_OPENAGAIN -2
#define HMIERR_EINVAL -3
#define HMIERR_SERIAL_WRITE -4
#define HMIERR_INTERNAL -5
#define HMIERR_RSPTIMEOUT -6
#define HMIERR_RSPRDTIMEOUT -7
#define HMIERR_BUFOVERFLOW -8
#define HMIERR_RSPERROR -9
#define HMIERR_SEMINITERROR -10
#define HMIERR_NORETVAL -11
#define HMIERR_MAXNO -12
#define HMIERR_PARAM -13
#define HMIERR_GETAMB -14
#define HMIERR_GETBACKL -15
#define HMIERR_BLRANGE -16

#ifdef HMIAPI_INTERNAL
/* 1:1 Relation between Error number above and this string */

LPCWSTR comm_errors[]=
{
	L"NULL",
	L"FAILED: Opening file",
	L"FAILED: File is already opened",
	L"Invalid parameter",
	L"FAILED: Writing to serial port",
	L"Internal error",
	L"Response Timeout",
	L"Read Response Timeout",
	L"Buffer overflow",
	L"Faulty response frame",
	L"Failed initializing semaphore",
	L"No Return Value from HMI controller",
	L"MAX",
	L"Parameter out of range",
	L"Error getting ambient value",
	L"Error getting backlight value",
	L"Error with backlight range, day-value below of night-value"
};
#endif

LPCWSTR ComPort = L"COM7";

// This class is exported from the HmitrApi.dll
class HMITRAPI_API CHmitrApi {
public:
	CHmitrApi(void);
	// TODO: add your methods here.
	
};

extern HMITRAPI_API int nHmitrApi;

HMITRAPI_API int fnHmitrApi(void);


	HMITRAPI_API int hmiapi_open(LPCWSTR ComPort);
	HMITRAPI_API void hmiapi_close(void);

	HMITRAPI_API int hmi_amblight_read(int which, int *pretval);
	HMITRAPI_API int hmi_amblight_write(int which, unsigned char value);

	HMITRAPI_API int hmi_backlight_read(int which, int *pretval);
	HMITRAPI_API int hmi_backlight_write(int which, unsigned char value);
	
	HMITRAPI_API int hmi_ambtemp_read(int *pretval);

	HMITRAPI_API int hmi_inc_brightness( int inc_step);
	HMITRAPI_API int hmi_dec_brightness( int dec_step);

	HMITRAPI_API int hmi_reset2default();

	HMITRAPI_API int hmi_blonoff_read( int *pretval);
	HMITRAPI_API int hmi_blonoff_write( unsigned char value);
	HMITRAPI_API int hmi_blonoff_default_write( unsigned char value);

	HMITRAPI_API int hmi_boardident_read( int which, int *pretval);

	HMITRAPI_API int hmi_wdtim_write( unsigned short value);
	HMITRAPI_API int hmi_wdtim_read( int *pretval);
	HMITRAPI_API int hmi_wdconf_write( unsigned char value);
	HMITRAPI_API int hmi_wdconf_read( int *pretval);
	HMITRAPI_API int hmi_wd_trigger();

	HMITRAPI_API int hmi_led_write( unsigned char ledno, unsigned char ledmode);
	HMITRAPI_API int hmi_led_read( unsigned char ledno, int *pretval);

	HMITRAPI_API int hmi_buzzeralarm_write( unsigned char value);
	HMITRAPI_API int hmi_buzzeralarm_read( int *pretval);
	HMITRAPI_API int hmi_buzzerclick_write( unsigned char value);
	HMITRAPI_API int hmi_buzzerclick_read( int *pretval);

#ifdef __cplusplus
}
#endif
