/*
 * clock.c
 *
 *  Created on: Mar 26, 2026
 *      Author: ewars
 */


#include "clock.h"

// define LED marking 12:00 or 00:00

#define LED_OFFSET 12

void clock_update(ds1307_dev_t *ds1307_dev){

	ds1307_update(ds1307_dev);
}

void clock_InitModule(void){

	ds1307_init();

}


uint8_t clock_convert_hours(uint8_t hours){
	int8_t h = 0;
	uint8_t led = 0;

	// input check
	if(hours < 24){

		if(hours > 12){
			h = hours - 12;
		}
		else{
			h = hours;
		}

		led = 2 * h + LED_OFFSET;
		if(led > 23){
			led -= 24;
		}

	}

	return led;

}

uint8_t clock_convert_min_sec(uint8_t min_sec){

	float led = 0;
	float divider = 2.5;

	if(min_sec < 60){
		led = (float) min_sec/divider;


		led = led + LED_OFFSET;
		while(led > 23){
			led = led - 24;
		}
	}

	return (uint8_t) led;
}

