stm32duino / STM32RTC

Arduino RTC library for STM32.
125 stars 48 forks source link

Dinamical modification of hour format #104

Closed slavendam closed 4 months ago

slavendam commented 5 months ago

In RTC_StartAlarm function https://github.com/stm32duino/STM32RTC/blob/90414bcb87c41307b9a93b84a4ae589d6d621325/src/rtc.c#L801 it is implemented that user can send 12h hours format, together with AM or PM flag, but that will not be used if 24h format is hardcoded.

If for example user wants to send 14:00h time in 12h format he will send: RTC_StartAlarm(RTC_ALARM_B, 0, 2, 0, 0, 0, HOUR_PM, 31UL); // old

If 24h format is hardcoded alarm will be set at 2:00 AM and user will not have feedback.

From UX side it would be the best to add additional value to hourAM_PM_t enum: https://github.com/stm32duino/STM32RTC/blob/90414bcb87c41307b9a93b84a4ae589d6d621325/src/rtc.h#L67

typedef enum {
  HOUR_AM,
  HOUR_PM,
  HOUR_24H
} hourAM_PM_t;

Modifiying code wherever new hourAM_PM_t is used, will enable user to dinamically set hour format he wants.

FRASTM commented 5 months ago

A proposal could be introduce a rtc.getFormat (or so) that will return HOUR_12 or HOUR_24 So that you can check the format 12 or 24 hours before setting the Alarm (or Time) Of course when format is 24 hours, HOUR_AM or HOUR_PM are useless