/* **************************************************************
  Fonction Blynk
 ***************************************************************/

#include "ESP12F.h"

 
BLYNK_CONNECTED() {
  rtc.begin();
}

BLYNK_WRITE(V20) {
  //Remonter

  int val = param.asInt() << 0;
  uint8_t in[2];
  uint8_t nbTr = 2;
  uint8_t out[8];

  //lecture ancien param
  in[0] = READACTI;
  if (transmit(in, 1, out)) {
    ;// todo return 1;
  }

  //envoie nouveau parametre
  in[0] = WRITACTI;
  in[1] = out[1] & (!ACTIREM | val);
  if (transmit(in, nbTr, out)) {
    ;// todo return 1;
  }
}

BLYNK_WRITE(V21) {
  //Ecumeur

  int val = param.asInt() << 1;
  uint8_t in[2];
  uint8_t nbTr = 2;
  uint8_t out[8];

  //lecture ancien param
  in[0] = READACTI;
  if (transmit(in, 1, out)) {
    ;// todo return 1;
  }

  //envoie nouveau parametre
  in[0] = WRITACTI;
  in[1] = out[1] & (!ACTIECU | val);
  if (transmit(in, nbTr, out)) {
    ;// todo return 1;
  }
}

BLYNK_WRITE(V22) {
  //Chauffage

  int val = param.asInt() << 2;
  uint8_t in[2];
  uint8_t nbTr = 2;
  uint8_t out[8];

  //lecture ancien param
  in[0] = READACTI;
  if (transmit(in, 1, out)) {
    ;// todo return 1;
  }

  //envoie nouveau parametre
  in[0] = WRITACTI;
  in[1] = out[1] & (!ACTICHA | val);
  if (transmit(in, nbTr, out)) {
    ;// todo return 1;
  }
}

BLYNK_WRITE(V23) {
  //Brassage Général

  int val = param.asInt() << 3;
  uint8_t in[2];
  uint8_t nbTr = 2;
  uint8_t out[8];

  //lecture ancien param
  in[0] = READACTI;
  if (transmit(in, 1, out)) {
    ;// todo return 1;
  }

  //envoie nouveau parametre
  in[0] = WRITACTI;
  in[1] = out[1] & (!ACTIBGE | val);
  if (transmit(in, nbTr, out)) {
    ;// todo return 1;
  }
}

BLYNK_WRITE(V24) {
  //Brassage1

  int val = param.asInt() << 4;
  uint8_t in[2];
  uint8_t nbTr = 2;
  uint8_t out[8];

  //lecture ancien param
  in[0] = READACTI;
  if (transmit(in, 1, out)) {
    ;// todo return 1;
  }

  //envoie nouveau parametre
  in[0] = WRITACTI;
  in[1] = out[1] & (!ACTIBR1 | val);
  if (transmit(in, nbTr, out)) {
    ;// todo return 1;
  }
}


BLYNK_WRITE(V25) {
  //Brassage2

  int val = param.asInt() << 5;
  uint8_t in[2];
  uint8_t nbTr = 2;
  uint8_t out[8];

  //lecture ancien param
  in[0] = READACTI;
  if (transmit(in, 1, out)) {
    ;// todo return 1;
  }

  //envoie nouveau parametre
  in[0] = WRITACTI;
  in[1] = out[1] & (!ACTIBR2 | val);
  if (transmit(in, nbTr, out)) {
    ;// todo return 1;
  }
}

BLYNK_WRITE(V26) {
  int val = param.asInt() << 6;
  uint8_t in[2];
  uint8_t nbTr = 2;
  uint8_t out[8];

  //lecture ancien param
  in[0] = READACTI;
  if (transmit(in, 1, out)) {
    ;// todo return 1;
  }

  //envoie nouveau parametre
  in[0] = WRITACTI;
  in[1] = out[1] & (!ACTIOSM | val);
  if (transmit(in, nbTr, out)) {
    ;// todo return 1;
  }
}

BLYNK_WRITE(V27) {
  //Nourrisage

  int val = param.asInt() << 7;
  uint8_t in[2];
  uint8_t nbTr = 2;
  uint8_t out[8];

  //lecture ancien param
  in[0] = READACTI;
  if (transmit(in, 1, out)) {
    ;// todo return 1;
  }

  //envoie nouveau parametre
  in[0] = WRITACTI;
  in[1] = out[1] & (!ACTINOU | val);
  if (transmit(in, nbTr, out)) {
    ;// todo return 1;
  }
}

BLYNK_WRITE(V40) {
  int val = param.asInt();
  uint8_t in[2];
  uint8_t nbTr = 2;
  uint8_t out[8];


  //lecture ancien param
  in[0] = READVENT;
  if (transmit(in, 1, out)) {
    ;// todo return 1;
  }

  //envoie nouveau parametre
  in[0] = WRITVENT;
  in[1] = out[1] & (!0xF0 | val << 4); // todo a modif
  if (transmit(in, nbTr, out)) {
    ;// todo return 1;
  }
}

BLYNK_WRITE(V41) {
  int val = param.asInt();
  uint8_t in[2];
  uint8_t nbTr = 2;
  uint8_t out[8];


  //lecture ancien param
  in[0] = READVENT;
  if (transmit(in, 1, out)) {
    ;// todo return 1;
  }

  //envoie nouveau parametre
  in[0] = WRITVENT;
  in[1] = out[1] & (!0x0F | val);// todo a modif
  if (transmit(in, nbTr, out)) {
    ;// todo return 1;
  }
}

BLYNK_WRITE(V50) {
  int val = param.asInt();
  uint8_t in[2];
  uint8_t nbTr = 2;
  uint8_t out[8];

  in[0] = WRITVENT;
  in[1] = val;
  if (transmit(in, nbTr, out)) {
    ;// todo return 1;
  }

}
