diff --git a/Core/Inc/myComms.h b/Core/Inc/myComms.h index 15541f4..19bea8a 100644 --- a/Core/Inc/myComms.h +++ b/Core/Inc/myComms.h @@ -14,7 +14,6 @@ typedef enum { com_WhoAmI, com_setTime, com_getTime, - com_setLedOffset, com_setColour_hour, com_setColour_minute, com_setColour_second, @@ -31,7 +30,6 @@ void cmd_RunCommand(commands_e cmd, uint32_t * input); void cmd_WhoAmI(uint32_t); void cmd_SetTime(uint32_t time); -void cmd_SetOffsetDiode(uint32_t diode); void cmd_GetTime(uint32_t time); void cmd_setColour_hour(uint32_t colour); void cmd_setColour_minute(uint32_t colour); diff --git a/Core/Src/clock.c b/Core/Src/clock.c index 18486e1..cee5871 100644 --- a/Core/Src/clock.c +++ b/Core/Src/clock.c @@ -10,13 +10,9 @@ // define LED marking 12:00 or 00:00 -__attribute__((section(".noinit"))) volatile uint8_t ledOffset = 0; +#define LED_OFFSET 10 -void clock_LedOffset(uint8_t offset){ - ledOffset = offset; -} - uint8_t clock_convert_hours(uint8_t hours){ int8_t h = 0; @@ -32,7 +28,7 @@ uint8_t clock_convert_hours(uint8_t hours){ h = hours; } - led = 2 * h + ledOffset; + led = 2 * h + LED_OFFSET; if(led > 23){ led -= 24; } @@ -50,7 +46,7 @@ uint8_t clock_convert_min_sec(uint8_t min_sec){ if(min_sec < 60){ led = (float) min_sec/(60/24); - led += ledOffset; + led += LED_OFFSET; if(led > 23){ led -= 24; } diff --git a/Core/Src/main.c b/Core/Src/main.c index 37e0f09..9df411c 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -50,6 +50,9 @@ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ +// RTC container +ds1307_dev_t my_rtc; + extern uint8_t UART_RxBuf[6]; /* USER CODE END PV */ @@ -108,8 +111,7 @@ int main(void) // RTC config ds1307_init(); - ds1307_dev_t my_rtc; - ds1307_config(0, 10, 19, THURSDAY, 26, MARCH, 2026, +1, 33); + // ds1307_config(0, 10, 19, THURSDAY, 26, MARCH, 2026, +1, 33); /* USER CODE END 2 */ @@ -146,7 +148,7 @@ uint8_t UART_Buff[] = "Hello World\n"; HAL_GPIO_TogglePin(LED_Green_GPIO_Port, LED_Green_Pin); - HAL_UART_Transmit(&huart2, UART_Buff, sizeof(UART_Buff), 1000); + //HAL_UART_Transmit(&huart2, UART_Buff, sizeof(UART_Buff), 1000); HAL_Delay(1000); diff --git a/Core/Src/myComms.c b/Core/Src/myComms.c index 5632f23..425bca8 100644 --- a/Core/Src/myComms.c +++ b/Core/Src/myComms.c @@ -10,6 +10,8 @@ #include "usart.h" #include "clock.h" +#include "stdio.h" + #include "ds1307.h" typedef struct { @@ -35,22 +37,11 @@ void (*commands[])(uint32_t) = { cmd_WhoAmI, cmd_SetTime, cmd_GetTime, - cmd_SetOffsetDiode, cmd_setColour_hour, cmd_setColour_minute, cmd_setColour_second }; -void cmd_SetOffsetDiode(uint32_t diode){ - - uint8_t offset = (uint8_t) diode; - - clock_LedOffset(offset); - - HAL_UART_Transmit(&huart2, ok, sizeof(ok), 1000); - -} - void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){ cmd_UART_Request(); @@ -63,9 +54,9 @@ void cmd_UART_Request(void){ cmd_RunCommand((uint8_t) msg->cmdId, (uint32_t*) &msg->bytes); - HAL_UART_Transmit(&huart2, (uint8_t*) msg, sizeof(*msg), 1000); + // HAL_UART_Transmit(&huart2, (uint8_t*) msg, sizeof(*msg), 1000); - HAL_UART_Transmit(&huart2, ok, sizeof(ok), 1000); + // HAL_UART_Transmit(&huart2, ok, sizeof(ok), 1000); } @@ -102,7 +93,26 @@ void cmd_SetTime(uint32_t time){ } -void cmd_GetTime(uint32_t time){} +void cmd_GetTime(uint32_t time){ + + extern ds1307_dev_t my_rtc; + + uint8_t msg[6] = {0}; + + uint8_t resp[] = "Hello Ewaryst\n"; + + // sprintf(resp, "%d, %d, %d, \n", my_rtc.hours, my_rtc.minutes, my_rtc.seconds); + + msg[0] = com_getTime + 200; + msg[1] = my_rtc.hours; + msg[2] = my_rtc.minutes; + msg[3] = my_rtc.seconds; + msg[4] = 251; + + msg[5] = 44; + + HAL_UART_Transmit(&huart2, resp, sizeof(resp), 1000); +} void cmd_setColour_hour(uint32_t colour){