#include <stdint.h>
#include <stdio.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "inc/hw_memmap.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "utils/uartstdio.h"
#include "drivers/ms_dht11.h"

DHT_TypeDef th;

void ConfigureUART(void);

int main(void) {


   SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);

    ConfigureUART();

    UARTprintf("Let's get started (Freq=%d)!\r\n", SysCtlClockGet());

 dht_init();
   th.celsius_temp= 0;
   th.humidity = 0;
   SysCtlDelay((SysCtlClockGet()/3)*5);

//---Application loop that prints out the read Temp and Humidity values------//



 while(1)
    {
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x00);
        dht_readTH(&th);
       UARTprintf(" T=%d.%d H=%d.%d\r\n", (int)th.celsius_temp, ((int)th.celsius_temp)%10, (int)th.humidity, ((int)th.humidity)%10);
        SysCtlDelay((SysCtlClockGet()*3/3));
       GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1);
        SysCtlDelay((SysCtlClockGet()*3/3));
     }


}
//-----for the display output on Putty-------//
void ConfigureUART(void)
{

    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    GPIOPinConfigure(GPIO_PA0_U0RX);
    GPIOPinConfigure(GPIO_PA1_U0TX);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    UARTStdioConfig(0, 115200, SysCtlClockGet());

}


