#include "views.h"

boolean view_1(Adafruit_SSD1306 &display, void *pData)
{
  char time_str[150] = "", power_str[15] = "", sdCard[10] = "";
  View1Packet *p = (View1Packet *) pData;

  switch(p->powerInfo.powerType)
  {
    case USB:
	  sprintf(power_str,"USB");
      break;
    default:
      sprintf(power_str,"BATT(%u%%)", p->powerInfo.level);
  }

  if(p->sdCardSize != 0.0)
    sprintf(sdCard,"%.2fGB",p->sdCardSize);
  else
    sprintf(sdCard,"NO CARD");
    
  sprintf(time_str,"RTC:time--> %d:%d:%d\ndate--> %d/%d/%d\nFree RAM : %d\nSdCard : %s\nPower : %s\nViews : %u\n", p->dateTime.hour(), p->dateTime.minute(), p->dateTime.second(), p->dateTime.day(), p->dateTime.month(), p->dateTime.year(),ESP.getFreeHeap(),sdCard,power_str, p->nbViews);
  display.println(time_str);
  display.setCursor(0,56);
  display.println("GLOBAL INFO");
  
  return true;
}

boolean view_2(Adafruit_SSD1306 &display, void *pData)
{
  char conn_str[150];

  ViewAPPacket *p = (ViewAPPacket *) pData;
  
  sprintf(conn_str,"Ip addr : %u.%u.%u.%u\nMac addr : \n%s\nConns : %u\nSSID : %s\n" ,p->ipAddr[0], p->ipAddr[1], p->ipAddr[2], p->ipAddr[3], p->macAddr.c_str(), p->nbOfCon, p->ssid.c_str());
  display.println(conn_str);
  
  display.setCursor(0,56);
  display.println("AP INFO");

  return true;
}

boolean view_3(Adafruit_SSD1306 &display, void *pData)
{
  char conn_str[150];

  ViewSTAPacket *p = (ViewSTAPacket *) pData;
  
  sprintf(conn_str,"Ip addr : %u.%u.%u.%u\nMac addr : \n%s\nSignal : %d dB\n", p->ipAddr[0], p->ipAddr[1], p->ipAddr[2], p->ipAddr[3], p->macAddr.c_str(), p->sigStrength);
  display.println(conn_str);
  
  display.setCursor(0,56);
  display.println("STA INFO");

  return true;
}

boolean memInfo(Adafruit_SSD1306 &display, void *pData)
{
  char dispBuffer[150];
  uint32_t freeMem;
  uint16_t biggestContigMemBlock;
  uint8_t frag;
  ESP.getHeapStats(&freeMem, &biggestContigMemBlock, &frag);
  sprintf(dispBuffer, "Free RAM : %u\nHeap frag : %u\nMax block : %u\nCPU Freq : %u MHz\n", freeMem, frag, biggestContigMemBlock, ESP.getCpuFreqMHz());
  display.println(dispBuffer);
  
  display.setCursor(0,56);
  display.println("SYS INFO");
  return true;
}

boolean dummy(Adafruit_SSD1306 &display, void *pData)
{
  return false;
}

