  *  - analyse drawn current
  */
 
-#include <avr/sleep.h>
-#include <avr/power.h>
 #include <SPI.h>
 #include <Wire.h>
 #include <Adafruit_Sensor.h>

#include "structures.h"

// Debug options
#define VERBOSE_MODE          0               // Echo data to serial port: 0: none, 1 basic info, 2 detailed info, 3 extended info
#define WAIT_TO_START         0               // Wait for serial input in setup()

// General
#define MILLISEC              1000L
#define SEC                   1L
#define MINUTE                (unsigned int)60L*SEC
#define HOUR                  (unsigned int)60L*MINUTE
#define DAY                   (unsigned long)24L*HOUR

// Error codes
#define ERROR_ADXL345_INIT    1
#define ERROR_HMC5883_INIT    2
const char PROGMEM                            //Remember to update the buffer when adding a larger string [7]
  errmsg_0[] =                "",             //SPARE
  errmsg_1[] =                "Ac err",       //Accelerometer init error
  errmsg_2[] =                "Co err";       //Compass init error
const char* const PROGMEM
  ERROR_MESSAGES[] =          {errmsg_0, errmsg_1, errmsg_2};

// Pins
#define REF_3V3               A0              // 3.3V reference sampling
#define BATT_OUT              A1              // Battery voltage
#define BUTTON_PIN            2               // Interrupt pin
#define LASER_PIN             7               // Laser pointer
#define PCD8544_DC_PIN        8               // LCD Data/Command select
#define PCD8544_RST_PIN       9               // LCD Reset
#define PCD8544_CE_PIN        10              // LCD Chip Select

// Sensors settings
#define ADXL345               1               // Accelerometer's ID
#define HMC5883               2               // Compass's ID
#define ALPHA                 0.5             // Low Pass Filter constant
#define READ_SAMPLES          8.0             // Number of samples to compute reading average

// Battery settings
#define BATT_MIN              9.0             // Maximum voltage delivered by the battery (volts)
#define BATT_MAX              8.0             // Maximum voltage delivered by the battery (volts)
#define BATT_REFRESH_RATE     5*SEC           // how often battery measurement is refreshed (seconds)

// Button settings
#define DEBOUNCE_DELAY        200             // Delay during which we ignore the button actions (milliseconds)

// Display settings
#define PCD8544_TEXT_WRAP     0               // (true, false) wrap the text
#define PCD8544_CONTRAST      0x31            // LCD Contrast value (0x00 to 0x7F) (the higher the value, the higher the contrast)
#define PCD8544_BIAS          0x13            // LCD Bias mode for MUX rate (0x10 to 0x17) (optimum: 0x13, 1:48)
#define PCD8544_SPI_CLOCK_DIV SPI_CLOCK_DIV2  // Max SPI clock speed for PCD8544 of 2mhz (8mhz / 4)
#define PCD8544_REFRESH_RATE  0.175*SEC       // how often display is refreshed (seconds)
#define PCD8544_FLIP          0               // (true, false) flip vertically the display

// Device settings
#define REVISION_NR           F("1.0")        // Revision # of the design

// Global variables
Adafruit_PCD8544 _PCD8544 =           Adafruit_PCD8544(PCD8544_DC_PIN, PCD8544_CE_PIN, PCD8544_RST_PIN);

static unsigned long
  _timer =                            -PCD8544_REFRESH_RATE*MILLISEC,
  _battTimer =                        -BATT_REFRESH_RATE*MILLISEC;
int _batt =                           0;
V
  _y_ADXL345 =                        {0, 0, 0, 0, 0, 0, 0},
  _y_HMC5883 =                        {0, 0, 0, 0, 0, 0, 0};
