text: /*
   * The MIT License (MIT)
   * Copyright (c) 2017 Novel Bits
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
   * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
   * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
   *
   * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
   *
   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
   * IN THE SOFTWARE.
   *
   */
  
  #ifndef MAIN_H
  #define MAIN_H
  
  #include <stdbool.h>
  #include <stdint.h>
  #include <string.h>
  #include "nordic_common.h"
  #include "nrf.h"
  #include "app_error.h"
  #include "ble.h"
  #include "ble_hci.h"
  #include "ble_srv_common.h"
  #include "ble_advdata.h"
  #include "ble_advertising.h"
  #include "ble_conn_params.h"
  #include "nrf_sdh.h"
  #include "nrf_sdh_soc.h"
  #include "nrf_sdh_ble.h"
  #include "app_timer.h"
  #include "fds.h"
  #include "peer_manager.h"
  #include "bsp_btn_ble.h"
  #include "sensorsim.h"
  #include "ble_conn_state.h"
  #include "nrf_ble_gatt.h"
  #include "ble_gap.h"
  
  #include "nrf_log.h"
  #include "nrf_log_ctrl.h"
  #include "nrf_log_default_backends.h"
  
  #include "ble_bas.h"
  #include "services/button_service.h"
  
  #include "battery_level/battery_voltage.h"
  
  
  #define APP_FEATURE_NOT_SUPPORTED       BLE_GATT_STATUS_ATTERR_APP_BEGIN + 2    /**< Reply when unsupported features are requested. */
  
  #define DEVICE_NAME                     "NovelBits RC"              /**< Name of device. Will be included in the advertising data. */
  #define MANUFACTURER_NAME               "NordicSemiconductor"                   /**< Manufacturer. Will be passed to Device Information Service. */
  #define APP_ADV_INTERVAL                300                                     /**< The advertising interval (in units of 0.625 ms. This value corresponds to 187.5 ms). */
  #define APP_ADV_TIMEOUT_IN_SECONDS      180                                     /**< The advertising timeout in units of seconds. */
  
  #define APP_BLE_OBSERVER_PRIO           1                                       /**< Application's BLE observer priority. You shouldn't need to modify this value. */
  #define APP_BLE_CONN_CFG_TAG            1                                       /**< A tag identifying the SoftDevice BLE configuration. */
  
  #define MIN_CONN_INTERVAL               MSEC_TO_UNITS(15, UNIT_1_25_MS)        /**< Minimum acceptable connection interval (15 msec). */
  #define MAX_CONN_INTERVAL               MSEC_TO_UNITS(15, UNIT_1_25_MS)        /**< Maximum acceptable connection interval (15 msec). */
  #define SLAVE_LATENCY                   9                                       /**< Slave latency. */
  #define CONN_SUP_TIMEOUT                MSEC_TO_UNITS(4000, UNIT_10_MS)         /**< Connection supervisory timeout (4 seconds). */
  
  #define FIRST_CONN_PARAMS_UPDATE_DELAY  APP_TIMER_TICKS(5000)                   /**< Time from initiating event (connect or start of notification) to first time sd_ble_gap_conn_param_update is called (5 seconds). */
  #define NEXT_CONN_PARAMS_UPDATE_DELAY   APP_TIMER_TICKS(30000)                  /**< Time between each call to sd_ble_gap_conn_param_update after the first call (30 seconds). */
  #define MAX_CONN_PARAMS_UPDATE_COUNT    3                                       /**< Number of attempts before giving up the connection parameter negotiation. */
  
  #define DEAD_BEEF                       0xDEADBEEF                              /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */
  
  #define BATTERY_LEVEL_MEAS_INTERVAL      APP_TIMER_TICKS(120000)  /**< Battery level measurement interval (ticks). */
  
  #define ADC_REF_VOLTAGE_IN_MILLIVOLTS           1200
  #define ADC_PRE_SCALING_COMPENSATION            3
  #define DIODE_FWD_VOLT_DROP_MILLIVOLTS          270
  #define ADC_RESULT_IN_MILLI_VOLTS(ADC_VALUE)    ((((ADC_VALUE) * ADC_REF_VOLTAGE_IN_MILLIVOLTS) / 1023) * ADC_PRE_SCALING_COMPENSATION)
  #define ADC_BUFFER_SIZE 6                                                            /**< Size of buffer for ADC samples.  */
  
  #endif /* MAIN_H */
  