#pragma once

#ifndef _CLOCK_H
#define _CLOCK_H

/* Includes */
#include "main.h"

/* type defs */
typedef union {
  uint64_t u64;
  uint32_t u32[2];
  uint8_t u8[8];
  struct {
    uint8_t DayHour;
    uint8_t NightHour;
    uint8_t DayBright;
    uint8_t NightBright;
    uint8_t DayMode;
    uint8_t NightMode;
    uint8_t DayColour;
    uint8_t NightColour;
  } name;
} flash_data_t;

typedef enum {
  light_Off = 0x0,
  light_Rainbow = 0x1,
  light_Colour = 0x2
} light_mode_t;

/* macro */
#define FADE_START      0
#define FADE_STOP       15
#define FADE_STEP       1

// Day/Night mode
#define MORNING_HOUR    0x06
#define EVENING_HOUR    0x22
#define DAY_BR_LVL      11
#define NIGHT_BR_LVL    5
#define MAX_BRIGHT_LVL  15
#define MAX_LIGHT_MODE  2
#define MAX_COLOR_VAL   59

// Color HUE angle
#define COLOUR_RED      0
#define COLOUR_GREEN    20
#define COLOUR_BLUE     40
#define COLOUR_NIXIE    1

/* time constant in ms */
#define BTN_SCAN_PERIOD     10
#define BTN_SCAN_PAUSE      200
#define BTN_TIME_PRESSED    30
#define BTN_TIME_HOLDED     500
#define BTN_TIME_REPEATED   50

/* Display timeout, sec */
#define DISP_WDT_TIME   15

/* variables */
extern rtc_t Clock;

/* function prototypes */
void Clock_Init(void);
void btnProcess(void);
void new_Second(void);

#endif /* _CLOCK_H */
