/**
 * 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

//NRF Radio config part
#define RADIO_CHANNEL 108 //0-125
#define RADIO_NODE_ADDRESS "WEST1" //Weather Station 1 network because the mail box is connected on it
#define RADIO_PA_LEVEL RF24_PA_MAX //RF24_PA_MIN,RF24_PA_LOW,RF24_PA_HIGH,RF24_PA_MAX
#define ENABLE_LNA true //true or false
#define RADIO_DATARATE RF24_250KBPS //Slow datarate to maximize range
#define MAX_SEND_ROUND_RETRIES 5  //If no ACK is received, tries to resend a MAX_SEND_ROUND_RETRIES-1 more 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_NRF_CE = 6,
  D7_SWITCH_V_SENS_EN = 7,
  D10_NRF_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_UNKNOWN,
} 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
