|
@@ -14,6 +14,9 @@
|
|
|
#define SW_SCAN_PERIOD 50
|
|
|
#define SW_SCAN_PAUSE 100
|
|
|
|
|
|
+#define DISP_DAY_BRIGHT 15
|
|
|
+#define DISP_NIGHT_BRIGHT 3
|
|
|
+
|
|
|
/* Display timeout, sec */
|
|
|
#define DISP_WDT_TIME 15
|
|
|
|
|
@@ -23,34 +26,17 @@ typedef struct t_btn {
|
|
|
es_event_t pressed;
|
|
|
es_event_t holded;
|
|
|
uint32_t pin;
|
|
|
- GPIO_TypeDef * idr;
|
|
|
+ //GPIO_TypeDef * port;
|
|
|
} btn_t;
|
|
|
|
|
|
typedef struct t_switch {
|
|
|
- int time;
|
|
|
- es_event_t ev_on;
|
|
|
- es_event_t ev_off;
|
|
|
- uint32_t pin;
|
|
|
- GPIO_TypeDef * idr;
|
|
|
+ int time;
|
|
|
+ void (*pFuncOn)(void);
|
|
|
+ void (*pFuncOff)(void);
|
|
|
+ uint32_t pin;
|
|
|
+ //GPIO_TypeDef * port;
|
|
|
} sw_t;
|
|
|
|
|
|
-/** Private variables */
|
|
|
-static rtc_t Clock;
|
|
|
-static i2c_status_t i2c_status;
|
|
|
-static btn_t Button[BTN_NUM] = {
|
|
|
- {0, evBTN1Pressed, evBTN1Pressed, BTN1_PIN, BTN_PORT},
|
|
|
- {0, evBTN2Pressed, evBTN2Pressed, BTN2_PIN, BTN_PORT},
|
|
|
- {0, evBTN3Pressed, evBTN3Holded, BTN3_PIN, BTN_PORT}
|
|
|
-};
|
|
|
-static sw_t Switch[SWITCH_NUM] = {
|
|
|
- {0, evSwitch1On, evSwitch1Off, SW1_PIN, SWITCH_PORT},
|
|
|
- {0, evSwitch2On, evSwitch2Off, SW2_PIN, SWITCH_PORT},
|
|
|
- {0, evSwitch3On, evSwitch3Off, SW3_PIN, SWITCH_PORT},
|
|
|
- {0, evSwitch4On, evSwitch4Off, SW4_PIN, SWITCH_PORT},
|
|
|
- {0, evSwitch5On, evSwitch5Off, SW5_PIN, SWITCH_PORT}
|
|
|
-};
|
|
|
-volatile static int dispWDT = 0;
|
|
|
-
|
|
|
/** Privaate functions prototypes */
|
|
|
static void buzer_On(void);
|
|
|
static void buzer_Off(void);
|
|
@@ -61,6 +47,33 @@ static void beep_Repeated(void);
|
|
|
static void btnProcess(void);
|
|
|
static void switchProcess(void);
|
|
|
static void dots_Off(void);
|
|
|
+static void switch_1_On(void);
|
|
|
+static void switch_1_Off(void);
|
|
|
+static void switch_2_On(void);
|
|
|
+static void switch_2_Off(void);
|
|
|
+static void switch_3_On(void);
|
|
|
+static void switch_3_Off(void);
|
|
|
+static void switch_4_On(void);
|
|
|
+static void switch_4_Off(void);
|
|
|
+static void switch_5_On(void);
|
|
|
+static void switch_5_Off(void);
|
|
|
+
|
|
|
+/** Private variables */
|
|
|
+static rtc_t Clock;
|
|
|
+static i2c_status_t i2c_status;
|
|
|
+static btn_t Button[BTN_NUM] = {
|
|
|
+ {0, evBTN1Pressed, evBTN1Pressed, BTN1_PIN},
|
|
|
+ {0, evBTN2Pressed, evBTN2Pressed, BTN2_PIN},
|
|
|
+ {0, evBTN3Pressed, evBTN3Holded, BTN3_PIN}
|
|
|
+};
|
|
|
+static sw_t Switch[SWITCH_NUM] = {
|
|
|
+ {0, switch_1_On, switch_1_Off, SW1_PIN},
|
|
|
+ {0, switch_2_On, switch_2_Off, SW2_PIN},
|
|
|
+ {0, switch_3_On, switch_3_Off, SW3_PIN},
|
|
|
+ {0, switch_4_On, switch_4_Off, SW4_PIN},
|
|
|
+ {0, switch_5_On, switch_5_Off, SW5_PIN}
|
|
|
+};
|
|
|
+volatile static int dispWDT = 0;
|
|
|
|
|
|
/** Exported functions */
|
|
|
|
|
@@ -83,7 +96,8 @@ void Clock_Init(void) {
|
|
|
show_Time();
|
|
|
|
|
|
/** Set tasks for Sheduler */
|
|
|
- RTOS_SetTask(btnProcess, BTN_SCAN_PERIOD, BTN_SCAN_PERIOD);
|
|
|
+ RTOS_SetTask(btnProcess, 3, BTN_SCAN_PERIOD);
|
|
|
+ RTOS_SetTask(switchProcess, 5, SW_SCAN_PERIOD);
|
|
|
}
|
|
|
|
|
|
void new_Second(void) {
|
|
@@ -114,7 +128,6 @@ static void btnProcess(void) {
|
|
|
for (i=0; i<BTN_NUM; i++) {
|
|
|
if ((pins & Button[i].pin) == 0) {
|
|
|
/* button pressed */
|
|
|
- beep_Short();
|
|
|
Button[i].time ++;
|
|
|
if (Button[i].time >= (BTN_TIME_HOLDED/BTN_SCAN_PERIOD)) {
|
|
|
Button[i].time -= (BTN_TIME_REPEATED/BTN_SCAN_PERIOD);
|
|
@@ -122,6 +135,8 @@ static void btnProcess(void) {
|
|
|
/* if pressed and holded - same function, then button pressed auto repeat */
|
|
|
ES_PlaceEvent(Button[i].pressed);
|
|
|
}
|
|
|
+ } else if (Button[i].time >= (BTN_TIME_PRESSED/BTN_SCAN_PERIOD)) {
|
|
|
+ beep_Short();
|
|
|
}
|
|
|
} else if (Button[i].time != 0) {
|
|
|
/* button released */
|
|
@@ -139,7 +154,28 @@ static void btnProcess(void) {
|
|
|
}
|
|
|
|
|
|
static void switchProcess(void) {
|
|
|
+ /* get pin state */
|
|
|
+ uint32_t pins = SWS_STATE;
|
|
|
|
|
|
+ int i;
|
|
|
+ for (i=0; i<SWITCH_NUM; i++) {
|
|
|
+ if ((pins & Switch[i].pin) == 0) {
|
|
|
+ /* switch on */
|
|
|
+ if (Switch[i].time == 0) {
|
|
|
+ beep_Short();
|
|
|
+ Switch[i].time ++;
|
|
|
+ Switch[i].pFuncOn();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ /* switch off */
|
|
|
+ if (Switch[i].time != 0) {
|
|
|
+ beep_Short();
|
|
|
+ Switch[i].time = 0;
|
|
|
+ RTOS_SetTask(btnProcess, SW_SCAN_PAUSE, SW_SCAN_PERIOD);
|
|
|
+ Switch[i].pFuncOff();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -178,6 +214,7 @@ void show_Time(void) {
|
|
|
* @brief Show MM:SS. Use 4x7 digits
|
|
|
*/
|
|
|
void show_MMSS(void) {
|
|
|
+ RTOS_DeleteTask(dots_Off);
|
|
|
display_Wait4Display();
|
|
|
|
|
|
uint8_t t;
|
|
@@ -205,7 +242,7 @@ void show_Date(void) {
|
|
|
|
|
|
char buf[26] = {0};
|
|
|
xsprintf(buf, "%s, %d %s, 20%02d %s.\0", Msg_WD_Full[Clock.WD], Clock.Day, Msg_Mon_Full[Clock.Mon], Clock.Year, Msg_rik);
|
|
|
- display_String(buf, 3);
|
|
|
+ display_String(buf, 2);
|
|
|
}
|
|
|
|
|
|
void setTimeShow(void) {}
|
|
@@ -329,6 +366,53 @@ static void beep_Repeated(void) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * @brief Switch control functions
|
|
|
+ */
|
|
|
+static void switch_1_On(void) {
|
|
|
+ // Stop
|
|
|
+}
|
|
|
+
|
|
|
+static void switch_1_Off(void) {
|
|
|
+ // Stop
|
|
|
+}
|
|
|
+
|
|
|
+static void switch_2_On(void) {
|
|
|
+ // show HH:MM
|
|
|
+ ES_PlaceEvent(evSwitch2Off);
|
|
|
+}
|
|
|
+
|
|
|
+static void switch_2_Off(void) {
|
|
|
+ // show MM:SS
|
|
|
+ ES_PlaceEvent(evSwitch2On);
|
|
|
+}
|
|
|
+
|
|
|
+static void switch_3_On(void) {
|
|
|
+ // Alaram Clock Set
|
|
|
+}
|
|
|
+
|
|
|
+static void switch_3_Off(void) {
|
|
|
+ // Alaram Clock Set
|
|
|
+}
|
|
|
+
|
|
|
+static void switch_4_On(void) {
|
|
|
+ // night brightnes
|
|
|
+ display_PWM(DISP_NIGHT_BRIGHT);
|
|
|
+}
|
|
|
+
|
|
|
+static void switch_4_Off(void) {
|
|
|
+ // day brightnes
|
|
|
+ display_PWM(DISP_DAY_BRIGHT);
|
|
|
+}
|
|
|
+
|
|
|
+static void switch_5_On(void) {
|
|
|
+ // global alarm clock buzer off
|
|
|
+}
|
|
|
+
|
|
|
+static void switch_5_Off(void) {
|
|
|
+ // global alarm clock buzer on
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* @brief This function handles EXTI line 4 to 15 interrupts.
|
|
|
*/
|