/**
 * Author : Anatole SCHRAMM-HENRY
 * Created the : 08/09/2022
 * This file contains all the config used by the other classes and sources files.
 */
#ifndef DEFINITION_H
#define DEFINITION_H

#include <Arduino.h>
#include <RF24.h>
#include "packet_format.h"

//Serial debug config part
#define SERIAL_DEBUG_ENABLED 0
#define SERIAL_BAUD_RATE 115200

//Battery config part
#define ADC_QUANTUM 0.0033017578125 //ADC_VREF / ADC_RESOLUTION -> 3.314 and 10 bits (1024) in my case
#define VOLTAGE_DIV_COEFF 1.321127673363577  //(R1 + R2)/R2

//RFM95 LoRa Radio config part
#define LORA_BAND (868E6)           // LoRa used frequency is 868 MHz in the EU
#define LORA_SPREADING_FACTOR (10)  // LoRa modulation spreading factor 6 to 12
#define RFM95W_ENABLE_CRC (true)    // Set CRC check for the frame
#define RFM95W_TX_POWER (17)        //2 to 20 dB
#define MAX_SEND_ROUND_RETRIES (3)  //Sends the packet 3 times
                                    //Increase this parameter if the RF link is bad.

//Pin config part
typedef enum
{
  D2_EXTERNAL_INT = 2,
  D4_LDO_EN = 4,
  D5_BAT_V_SENS_EN = 5,
  D6_RFM_RST = 6,
  D7_SWITCH_V_SENS_EN = 7,
  D8_RFM_DI0 = 8,
  D10_RFM_CS = 10,
  D11_MOSI = 11,
  D12_MISO = 12,
  D13_SCK = 13,
  A0_BAT_V_SENS = A0,
  A1_SWITCH_V_SENS = A1,
} Pin;

typedef enum
{
  MAILBOX_LETTER = 0,
  MAILBOX_PACKAGE,
  MAILBOX_COLLECTED,
  MAILBOX_TEST,
  MAILBOX_UNKNOWN,
} __attribute__((__packed__)) MAILBOX_EVENT_e;

//Payload structure
typedef struct 
{
  uint16_t id;
  HEADER_e header : 6;
  float battery;
  MAILBOX_EVENT_e mailbox_event;
} __attribute__((__packed__)) MailboxDataPacket;

#endif //DEFINITION_H
