#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>

#include <Wire.h> // Добавляем необходимые библиотеки
#include "DHT.h"

#define SizeRegisterModules 20

DHT dht(A0, DHT11);

int IDarg = 0;
String ParsedCommand[SizeRegisterModules];

int adding;

void ShowError(String errorMessage){
  Serial.println("Error: \n "+errorMessage);
}

void ShowMessage(String type, String Message){
  Serial.println("["+type+"] "+Message);
}

char getCharCommand(){
  if (Serial.available() > 0) {
    char cmdraw = Serial.read();
    if (cmdraw > 0) return cmdraw;
  }
  return '?';
}

void mainL(String *args){
  /*if(args[0] == "RGB") {
    if(args[1] == "lamp") {
      if(args[2] == "RED") {
        if(args[3] == "ON") {
          digitalWrite(4,HIGH);
        } else {
          digitalWrite(4,LOW);
        }
      }
    }
  }*/
  if(args[0] == "data") {
    if(args[1] == "get") {
      if(args[2] == "temp") {
        float t = dht.readTemperature();
        Serial.print("температура:");
        Serial.println(t);
      }
      if(args[2] == "vlag") {
        float h = dht.readHumidity();
        Serial.print("Влажность:");
        Serial.println(h);
      }
      if(args[2] == "more") {
        if(args[3] == "temp") {
          int i;
          String prom = args[5];
          int data = prom.toInt();
          prom = args[4];
          int timer = prom.toInt();
          timer = timer*1000;
          int data2 = data + 1;
          for(i=1;i<data2;i++) {
            float t = dht.readTemperature();
            Serial.print("проверка температуры ");
            Serial.print(i);
            Serial.print(" из ");
            Serial.print(data);
            Serial.print(":");
            Serial.println(t);
            delay(timer);
          }
        }
      }
    }
  }
}

void setup() {

  dht.begin();
  pinMode(4,OUTPUT);
  Serial.begin(9600);
  ShowMessage("Note","Type ';' to indicate the end of command, and then press 'Enter'");
  Serial.print("\n \n \n \n>");
}

void loop() {
 char CharCommand = getCharCommand();
 if (CharCommand != ';' && CharCommand != '?'){
    Serial.print(CharCommand);
  if (CharCommand == ' '){
    IDarg++;
  }else{
    ParsedCommand[IDarg] += CharCommand;
  }
 }else if(CharCommand == ';'){
  Serial.println(" ");
  mainL(ParsedCommand);
  IDarg = 0;
  for (int i = 0;i<=20;i++) {ParsedCommand[i]="";}
  Serial.print(">");
 }
}
