Skip to content

Commit d7693cb

Browse files
author
Ivan
committed
Implemented duration warning
1 parent 66d5694 commit d7693cb

File tree

6 files changed

+50
-2084
lines changed

6 files changed

+50
-2084
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"*.tcc": "c",
99
"cmath": "c",
1010
"complex": "c",
11-
"random": "c"
11+
"random": "c",
12+
"stdio.h": "c"
1213
}
1314
}

main/lcd.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,18 @@ static void i2c_master_init(void)
9999
I2C_MASTER_TX_BUF_LEN, 0);
100100
}
101101

102+
void lcd_set_warning(uint8_t lvl)
103+
{
104+
printf("Warning: %d\n", lvl);
105+
if (lvl >= 3) lvl = 3;
106+
107+
i2c_lcd1602_move_cursor(p_lcd_info, 13, 0);
108+
i2c_lcd1602_write_string(p_lcd_info, " ");
109+
110+
i2c_lcd1602_move_cursor(p_lcd_info, 13, 0);
111+
112+
for (uint8_t cnt = 0; cnt < lvl; cnt++)
113+
{
114+
i2c_lcd1602_write_char(p_lcd_info, '!');
115+
}
116+
}

main/lcd.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,20 @@ uint8_t lcd_init(void);
2121
uint8_t lcd_set_dur(uint16_t dur_val);
2222

2323
/**
24-
* @brief Place curcor to user defined position.
24+
* @brief Place cursor to user defined position.
2525
* @note None.
2626
* @param *p_pos: Position where we want to put the cursor to.
2727
* @retval 0 -> ok
2828
* 1 -> not ok
2929
*/
3030
uint8_t lcd_user_pointer(uint8_t *p_pos);
3131

32+
/**
33+
* @brief Prints ! in top right corner.
34+
* @note
35+
* @param lvl: Level of warning.
36+
* @retval None
37+
*/
38+
void lcd_set_warning(uint8_t lvl);
39+
3240
#endif

main/rotary_encoder.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
static QueueHandle_t p_encoder_queue = NULL;
1515
static int16_t duration = 100;
1616

17+
static uint8_t warning1 = 150;
18+
static uint8_t warning2 = 500;
19+
static uint8_t warning3 = 1000;
20+
1721
/**
1822
* @brief Rotary encoder interrupt service routine.
1923
* @note Debounce protocol should be done here.
@@ -131,10 +135,28 @@ static void rotary_encoder_task(void *arg)
131135
duration = 5000;
132136
}
133137

138+
// Signal the user if the duration is to long.
139+
if (0 <= duration && warning1 > duration){
140+
lcd_set_warning(0);
141+
}
142+
else if (warning1 < duration && warning2 > duration)
143+
{
144+
lcd_set_warning(1);
145+
}
146+
else if ((warning2 < duration && 1000 > duration))
147+
{
148+
lcd_set_warning(2);
149+
}
150+
else
151+
{
152+
lcd_set_warning(3);
153+
}
154+
134155
lcd_set_dur(duration);
135-
vTaskDelay(60/portTICK_PERIOD_MS);
156+
vTaskDelay(50/portTICK_PERIOD_MS);
136157
gpio_intr_enable(ENC_DT);
137158
gpio_intr_enable(ENC_SW);
159+
gpio_intr_enable(ENC_CLK);
138160
}
139161
}
140162
}
@@ -153,6 +175,7 @@ static void IRAM_ATTR encoder_isr_handler(void *arg)
153175
// Disable interrupts until the handling is done.
154176
gpio_intr_disable(ENC_DT);
155177
gpio_intr_disable(ENC_SW);
178+
gpio_intr_disable(ENC_CLK);
156179

157180
uint8_t a = gpio_get_level(ENC_CLK);
158181
uint8_t b = gpio_get_level(ENC_DT);

0 commit comments

Comments
 (0)