/*
 * my_debug.c
 *
 *  Created on: gg/mmm/ccaa
 *      Author: cognome.nome
 *
 * funzioni di esempio da cancellare a progetto finito
 *
 */

//==============================================================================
// Include files

#include "string.h"
#include "stdbool.h"
#include "stdint.h"
#include "stdio.h"

#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"

#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "driverlib/rom.h"

#include "drivers/my_interrupt.h"
#include "drivers/my_GPIO.h"
#include "drivers/my_timer.h"
//#include "drivers/AD7193.h"
#include "drivers/my_LCD.h"

//==============================================================================
// Constants

//==============================================================================
// Types

//==============================================================================
// Static global variables

//==============================================================================
// Static functions

//==============================================================================
// Global variables

//==============================================================================
// Global functions

void Test_GPIO_MOD_1(void)
{
	S_out out;

    memset(&out,0,sizeof(S_out));
    Write_Output_Module(1,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out1  = 1;
    out.out2  = 0;
    out.out3  = 0;
    out.out4  = 0;
    out.out5  = 0;
    out.out6  = 0;
    out.out7  = 0;
    out.out8  = 0;
    out.out9  = 0;
    out.out10 = 0;
    out.out11 = 0;
    out.out12 = 0;
    Write_Output_Module(1,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out1  = 0;
    out.out2  = 1;
    out.out3  = 0;
    out.out4  = 0;
    out.out5  = 0;
    out.out6  = 0;
    out.out7  = 0;
    out.out8  = 0;
    out.out9  = 0;
    out.out10 = 0;
    out.out11 = 0;
    out.out12 = 0;
    Write_Output_Module(1,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out1  = 0;
    out.out2  = 0;
    out.out3  = 1;
    out.out4  = 0;
    out.out5  = 0;
    out.out6  = 0;
    out.out7  = 0;
    out.out8  = 0;
    out.out9  = 0;
    out.out10 = 0;
    out.out11 = 0;
    out.out12 = 0;
    Write_Output_Module(1,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out1  = 0;
    out.out2  = 0;
    out.out3  = 0;
    out.out4  = 1;
    out.out5  = 0;
    out.out6  = 0;
    out.out7  = 0;
    out.out8  = 0;
    out.out9  = 0;
    out.out10 = 0;
    out.out11 = 0;
    out.out12 = 0;
    Write_Output_Module(1,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out1  = 0;
    out.out2  = 0;
    out.out3  = 0;
    out.out4  = 0;
    out.out5  = 1;
    out.out6  = 0;
    out.out7  = 0;
    out.out8  = 0;
    out.out9  = 0;
    out.out10 = 0;
    out.out11 = 0;
    out.out12 = 0;
    Write_Output_Module(1,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out1  = 0;
    out.out2  = 0;
    out.out3  = 0;
    out.out4  = 0;
    out.out5  = 0;
    out.out6  = 1;
    out.out7  = 0;
    out.out8  = 0;
    out.out9  = 0;
    out.out10 = 0;
    out.out11 = 0;
    out.out12 = 0;
    Write_Output_Module(1,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out1  = 0;
    out.out2  = 0;
    out.out3  = 0;
    out.out4  = 0;
    out.out5  = 0;
    out.out6  = 0;
    out.out7  = 1;
    out.out8  = 0;
    out.out9  = 0;
    out.out10 = 0;
    out.out11 = 0;
    out.out12 = 0;
    Write_Output_Module(1,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out1  = 0;
    out.out2  = 0;
    out.out3  = 0;
    out.out4  = 0;
    out.out5  = 0;
    out.out6  = 0;
    out.out7  = 0;
    out.out8  = 1;
    out.out9  = 0;
    out.out10 = 0;
    out.out11 = 0;
    out.out12 = 0;
    Write_Output_Module(1,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out1  = 0;
    out.out2  = 0;
    out.out3  = 0;
    out.out4  = 0;
    out.out5  = 0;
    out.out6  = 0;
    out.out7  = 0;
    out.out8  = 0;
    out.out9  = 1;
    out.out10 = 0;
    out.out11 = 0;
    out.out12 = 0;
    Write_Output_Module(1,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out1  = 0;
    out.out2  = 0;
    out.out3  = 0;
    out.out4  = 0;
    out.out5  = 0;
    out.out6  = 0;
    out.out7  = 0;
    out.out8  = 0;
    out.out9  = 0;
    out.out10 = 1;
    out.out11 = 0;
    out.out12 = 0;
    Write_Output_Module(1,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out1  = 0;
    out.out2  = 0;
    out.out3  = 0;
    out.out4  = 0;
    out.out5  = 0;
    out.out6  = 0;
    out.out7  = 0;
    out.out8  = 0;
    out.out9  = 0;
    out.out10 = 0;
    out.out11 = 1;
    out.out12 = 0;
    Write_Output_Module(1,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out1  = 0;
    out.out2  = 0;
    out.out3  = 0;
    out.out4  = 0;
    out.out5  = 0;
    out.out6  = 0;
    out.out7  = 0;
    out.out8  = 0;
    out.out9  = 0;
    out.out10 = 0;
    out.out11 = 0;
    out.out12 = 1;
    Write_Output_Module(1,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    memset(&out,0,sizeof(S_out));
    Write_Output_Module(1,&out);
    ROM_SysCtlDelay(SEC_DELAY);

}

void Test_GPIO_MOD_2(void)
{
	S_out out;

    memset(&out,0,sizeof(S_out));
    Write_Output_Module(2,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 1;
    Write_Output_Module(2,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 2;
    Write_Output_Module(2,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out  = 4;
    Write_Output_Module(2,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 8;
    Write_Output_Module(2,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 16;
    Write_Output_Module(2,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 32;
    Write_Output_Module(2,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 64;
    Write_Output_Module(2,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 128;
    Write_Output_Module(2,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 256;
    Write_Output_Module(2,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 512;
    Write_Output_Module(2,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 1024;
    Write_Output_Module(2,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 2048;
    Write_Output_Module(2,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    memset(&out,0,sizeof(S_out));
    Write_Output_Module(2,&out);
    ROM_SysCtlDelay(SEC_DELAY);

}

void Test_GPIO_MOD_3(void)
{
	S_out out;

    memset(&out,0,sizeof(S_out));
    Write_Output_Module(3,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 1;
    Write_Output_Module(3,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 2;
    Write_Output_Module(3,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out  = 4;
    Write_Output_Module(3,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 8;
    Write_Output_Module(3,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 16;
    Write_Output_Module(3,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 32;
    Write_Output_Module(3,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 64;
    Write_Output_Module(3,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 128;
    Write_Output_Module(3,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 256;
    Write_Output_Module(3,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 512;
    Write_Output_Module(3,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 1024;
    Write_Output_Module(3,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    out.out = 2048;
    Write_Output_Module(3,&out);
    ROM_SysCtlDelay(SEC_DELAY);

    memset(&out,0,sizeof(S_out));
    Write_Output_Module(3,&out);
    ROM_SysCtlDelay(SEC_DELAY);

}

long WriteSingleToDisplay(void)
{
	if(ChannelValues.SingleEndedValue1Err)
	{
		sprintf(MSG,"%.3f! mV",ChannelValues.SingleEndedValue1_Tensione*1000);
		LCD_WriteLine(3,MSG);
	}
	else
	{
		sprintf(MSG,"%.3f mV",ChannelValues.SingleEndedValue1_Tensione*1000);
		LCD_WriteLine(3,MSG);
		sprintf(MSG,"%.2f Pa",ChannelValues.SingleEndedValue1_Grandezza*100000);
		LCD_WriteLine(4,MSG);
	}

/*
	if(ChannelValues.SingleEndedValue1Err)
		sprintf(MSG,"%.3f! mV",ChannelValues.SingleEndedValue1*1000);
	else
		sprintf(MSG,"%.3f %.3f",ChannelValues.SingleEndedValue1*1000,ChannelValues.SingleEndedValue1_Bar*1000);
	LCD_WriteLine(1,MSG);

	if(ChannelValues.SingleEndedValue2Err)
		sprintf(MSG,"%.3f! mV",ChannelValues.SingleEndedValue2*1000);
	else
		sprintf(MSG,"%.3f% .3f",ChannelValues.SingleEndedValue2*1000,ChannelValues.SingleEndedValue2_Bar*1000);
	LCD_WriteLine(2,MSG);

	if(ChannelValues.SingleEndedValue3Err)
		sprintf(MSG,"%.3f! mV",ChannelValues.SingleEndedValue3*1000);
	else
		sprintf(MSG,"%.3f %.3f",ChannelValues.SingleEndedValue3*1000,ChannelValues.SingleEndedValue3_Bar*1000);
	LCD_WriteLine(3,MSG);

	if(ChannelValues.SingleEndedValue4Err)
		sprintf(MSG,"%.3f! mV",ChannelValues.SingleEndedValue4*1000);
	else
		sprintf(MSG,"%.3f %.3f",ChannelValues.SingleEndedValue4*1000,ChannelValues.SingleEndedValue4_Bar*1000);
	LCD_WriteLine(4,MSG);
*/

	return 0;
}



long WriteDifferentialToDisplay(void)
{

	if(ChannelValues.DifferentialValue1Err)
	{
		sprintf(MSG,"%.3f! mV",ChannelValues.DifferentialValue1_Tensione*1000);
		LCD_WriteLine(3,MSG);
	}
	else
	{
		sprintf(MSG,"%.3f mV",ChannelValues.DifferentialValue1_Tensione*1000);
		LCD_WriteLine(3,MSG);
		sprintf(MSG,"%.2f Pa",ChannelValues.DifferentialValue1_Grandezza*100000);
		LCD_WriteLine(4,MSG);
	}

/*	if(ChannelValues.DifferentialValue1Err)
		sprintf(MSG,"%.3f! mV",ChannelValues.DifferentialValue1*1000);
	else
		sprintf(MSG,"%.3f %.3f",ChannelValues.DifferentialValue1*1000,ChannelValues.DifferentialValue1_Bar*1000);
	LCD_WriteLine(1,MSG);

	if(ChannelValues.DifferentialValue2Err)
		sprintf(MSG,"%.3f! mV",ChannelValues.DifferentialValue2*1000);
	else
		sprintf(MSG,"%.3f %.3f",ChannelValues.DifferentialValue2*1000,ChannelValues.DifferentialValue2_Bar*1000);
	LCD_WriteLine(2,MSG);

	if(ChannelValues.DifferentialValue3Err)
		sprintf(MSG,"%.3f! mV",ChannelValues.DifferentialValue3*1000);
	else
		sprintf(MSG,"%.3f %.3f",ChannelValues.DifferentialValue3*1000,ChannelValues.DifferentialValue3_Bar*1000);
	LCD_WriteLine(3,MSG);

	if(ChannelValues.DifferentialValue4Err)
		sprintf(MSG,"%.3f! mV",ChannelValues.DifferentialValue4*1000);
	else
		sprintf(MSG,"%.3f %.3f",ChannelValues.DifferentialValue4*1000,ChannelValues.DifferentialValue4_Bar*1000);
	LCD_WriteLine(4,MSG);
*/
	return 0;
}
