/*
  Name:    PhotometerEDU.ino
  Author:  Roman Schönfeld & Daniel Hausherr
*/

/***********************************************************************************************
  This work is licensed under a Creative Commons Attribution 4.0 International (CC BY 4.0) License.

  You are free to:

  Share — copy and redistribute the material in any medium or format
  Adapt — remix, transform, and build upon the material
  for any purpose, even commercially.

  The licensor cannot revoke these freedoms as long as you follow the license terms.

  Under the following terms:

  Attribution — You must give appropriate credit, provide a link to the license, and indicate if
  changes were made. You may do so in any reasonable manner, but not in any way that suggests
  the licensor endorses you or your use.

  No additional restrictions — You may not apply legal terms or technological measures that
  legally restrict others from doing anything the license permits.

  Credits:
  Laboratory for Physics and Illumination Technologies,
  University of Applied Sciences Southern Westfalia
  Germany

  Make Light! Support by the BMBF in the development of this device is gratefully acknowledged
***************************************************************************************************/
#include <Wire.h>
#include <TFT.h>

#include "Sauron.h"
#include "Display.h"
#include "Interface.h"

static bool _start = false; // false = Ausgabe der Version über die serielle Schnittstelle
static char *_version = "Version: Photometer_Education_2.0.1", *_version_date = "Date: 19.06.2018";


void setup() {

  Serial.begin(115200);

  pinMode(_Y_MOVE, INPUT);
  pinMode(_READY_PIN, INPUT);

  // Display Hintergrundbeleuchtung Pin
  pinMode(_BL, OUTPUT);
  // Display Reset Pin
  pinMode(_RES, OUTPUT);

  // Display Helligkeit Anfangswert
  analogWrite(_BL, _TFT_BRIGHTNESS);

  digitalWrite(_RES, _NRESET);

  // Initialisiere I2C Bus
  init_device();
  // Initialisiere Display
  init_tft();
  // Initialisiere Menustruktur
  init_menu();
}

void loop() {
  
  if (_start) {
    compute_value_nano(NULL);    

    clear_area_tft(0, 0, 160, 128, BLACK);
    set_text_size_tft(2);
    set_cursor_tft(64, 10);
    print_text_tft((char*)"Fehler", WHITE);
    set_text_size_tft(1);
    
    while(true) delay(1);
  }
  else {
    Serial.println(_version);
    Serial.println(_version_date);
    _start = true;
  }
}
