#ifndef LIGHTS_H__
#define LIGHTS_H__ 1

#define TESTING_FW 1

#define N_PWMLED_MODES 4

#define N_BUTTONS 2

/* logging.c */
#ifdef USE_LOGGING
void init_log();
void log_set_state(unsigned char val);
void log_flush();
void log_byte(unsigned char byte);
void log_word(uint16_t word);
#else
void inline init_log() { }
void inline log_set_state(unsigned char val) { }
void inline log_flush() { }
void inline log_byte(unsigned char byte) { }
void inline log_word(uint16_t word) { }
#endif

/* adc.c */
#define PWMLED_ADC_SHIFT 1 /* 1<<1 measurements per single callback */
void init_adc();
void susp_adc();
void timer_start_slow_adcs();

/* pwm.c */
#define PWM_MAX 0xFF
void init_pwm();
void susp_pwm();
void pwm_off();
void pwm_set(uint8_t stride);

/* tmr.c */
extern volatile uint16_t jiffies;
void init_tmr();
void susp_tmr();

/* pwmled.c */
void init_pwmled();
void pwmled_adc(uint16_t adcval);
void pwmled_set_target(unsigned char mode);
void pwmled_on_off(unsigned char on);

/* gpio.c */
void init_gpio();
void susp_gpio();
void gpio_set(unsigned char n, unsigned char on);

/* ambient.c */
#define AMBIENT_ADC_SHIFT 0	/* 1 measurement per callback */
void init_ambient();
extern volatile unsigned char ambient_zone;
void ambient_adc(uint16_t adc_val);

/* pattern.c */
typedef struct {
	unsigned char mode: 3;
	unsigned char duration: 5;
} pattern_t;

#define PATTERN_END { 0, 0 }
void init_pattern();
void patterns_next_tick();
void led_set_pattern(unsigned char led, pattern_t *pattern);
pattern_t *number_pattern(unsigned char num, unsigned char inv);
void pattern_reload();

/* buttons.c */
#define MAX_USER_PARAMS 3
void init_buttons();
void susp_buttons();
void timer_check_buttons();
void button_adc(uint16_t adcval);
unsigned char get_user_param(unsigned char param);
unsigned char buttons_wait_for_release();
unsigned char buttons_setup_in_progress();
pattern_t *buttons_setup_status0_pattern_select();
pattern_t *buttons_setup_status1_pattern_select();

/* battery.c */
extern volatile unsigned char battery_critical;
void battery_adc();
void init_battery();
unsigned char battery_gauge();

/* control.c */
extern pattern_t on1_pattern[];

void init_control();
void brake_on();
void brake_off();
void toggle_dim_mode();
void set_panic_mode();
pattern_t *pwmled0_pattern_select();
pattern_t *pwmled1_pattern_select();
pattern_t *pwmled2_pattern_select();
pattern_t *status_led_pattern_select();
pattern_t *illumination_led_pattern_select();
pattern_t *laser_pattern_select();

/* main.c */
void power_down();

#endif /* !LIGHTS_H__ */

