mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Add buzzer beep when at temperature 🎵
This commit is contained in:
@@ -412,9 +412,19 @@ bool isTipDisconnected() {
|
|||||||
|
|
||||||
return tipDisconnected;
|
return tipDisconnected;
|
||||||
}
|
}
|
||||||
|
void setBuzzer(bool on) {
|
||||||
|
if (on) {
|
||||||
|
htim3.Instance->CCR2 = 128;
|
||||||
|
htim3.Instance->PSC = 100; // drop down into audible range
|
||||||
|
} else {
|
||||||
|
htim3.Instance->CCR2 = 0;
|
||||||
|
htim3.Instance->PSC = 1; // revert back out of hearing range
|
||||||
|
}
|
||||||
|
}
|
||||||
void setStatusLED(const enum StatusLED state) {
|
void setStatusLED(const enum StatusLED state) {
|
||||||
static enum StatusLED lastState = LED_UNKNOWN;
|
static enum StatusLED lastState = LED_UNKNOWN;
|
||||||
|
static TickType_t buzzerEnd = 0;
|
||||||
|
|
||||||
if (lastState != state || state == LED_HEATING) {
|
if (lastState != state || state == LED_HEATING) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
default:
|
default:
|
||||||
@@ -426,11 +436,12 @@ void setStatusLED(const enum StatusLED state) {
|
|||||||
ws2812.led_set_color(0, 0, 0xFF, 0); // green
|
ws2812.led_set_color(0, 0, 0xFF, 0); // green
|
||||||
break;
|
break;
|
||||||
case LED_HEATING: {
|
case LED_HEATING: {
|
||||||
ws2812.led_set_color(0, ((HAL_GetTick() / 10) % 192) + 64, 0,
|
ws2812.led_set_color(0, ((HAL_GetTick() / 10) % 192) + 64, 0, 0); // Red fade
|
||||||
0); // Red fade
|
|
||||||
} break;
|
} break;
|
||||||
case LED_HOT:
|
case LED_HOT:
|
||||||
ws2812.led_set_color(0, 0xFF, 0, 0); // red
|
ws2812.led_set_color(0, 0xFF, 0, 0); // red
|
||||||
|
// We have hit the right temp, run buzzer for a short period
|
||||||
|
buzzerEnd = xTaskGetTickCount() + TICKS_SECOND / 3;
|
||||||
break;
|
break;
|
||||||
case LED_COOLING_STILL_HOT:
|
case LED_COOLING_STILL_HOT:
|
||||||
ws2812.led_set_color(0, 0xFF, 0x8C, 0x00); // Orange
|
ws2812.led_set_color(0, 0xFF, 0x8C, 0x00); // Orange
|
||||||
@@ -439,4 +450,9 @@ void setStatusLED(const enum StatusLED state) {
|
|||||||
ws2812.led_update();
|
ws2812.led_update();
|
||||||
lastState = state;
|
lastState = state;
|
||||||
}
|
}
|
||||||
|
if (state == LED_HOT && xTaskGetTickCount() < buzzerEnd) {
|
||||||
|
setBuzzer(true);
|
||||||
|
} else {
|
||||||
|
setBuzzer(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,9 @@
|
|||||||
#define PWM_Out_Pin GPIO_PIN_6
|
#define PWM_Out_Pin GPIO_PIN_6
|
||||||
#define PWM_Out_GPIO_Port GPIOA
|
#define PWM_Out_GPIO_Port GPIOA
|
||||||
#define PWM_Out_CHANNEL TIM_CHANNEL_1
|
#define PWM_Out_CHANNEL TIM_CHANNEL_1
|
||||||
|
#define BUZZER_Pin GPIO_PIN_7
|
||||||
|
#define BUZZER_GPIO_Port GPIOA
|
||||||
|
#define BUZZER_CHANNEL TIM_CHANNEL_2
|
||||||
#define SCL_Pin GPIO_PIN_6
|
#define SCL_Pin GPIO_PIN_6
|
||||||
#define SCL_GPIO_Port GPIOB
|
#define SCL_GPIO_Port GPIOB
|
||||||
#define SDA_Pin GPIO_PIN_7
|
#define SDA_Pin GPIO_PIN_7
|
||||||
|
|||||||
@@ -223,7 +223,9 @@ static void MX_TIM3_Init(void) {
|
|||||||
TIM_ClockConfigTypeDef sClockSourceConfig;
|
TIM_ClockConfigTypeDef sClockSourceConfig;
|
||||||
TIM_MasterConfigTypeDef sMasterConfig;
|
TIM_MasterConfigTypeDef sMasterConfig;
|
||||||
TIM_OC_InitTypeDef sConfigOC;
|
TIM_OC_InitTypeDef sConfigOC;
|
||||||
|
memset(&sClockSourceConfig, 0, sizeof(sClockSourceConfig));
|
||||||
|
memset(&sMasterConfig, 0, sizeof(sMasterConfig));
|
||||||
|
memset(&sConfigOC, 0, sizeof(sConfigOC));
|
||||||
htim3.Instance = TIM3;
|
htim3.Instance = TIM3;
|
||||||
htim3.Init.Prescaler = 1;
|
htim3.Init.Prescaler = 1;
|
||||||
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
@@ -248,17 +250,18 @@ static void MX_TIM3_Init(void) {
|
|||||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||||
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
|
||||||
HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, PWM_Out_CHANNEL);
|
HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, PWM_Out_CHANNEL);
|
||||||
// TODO need to do buzzer
|
HAL_TIM_PWM_ConfigChannel(&htim3, &sConfigOC, BUZZER_CHANNEL);
|
||||||
GPIO_InitTypeDef GPIO_InitStruct;
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||||||
|
|
||||||
/**TIM3 GPIO Configuration
|
/**TIM3 GPIO Configuration
|
||||||
PWM_Out_Pin ------> TIM3_CH1
|
PWM_Out_Pin ------> TIM3_CH1
|
||||||
*/
|
*/
|
||||||
GPIO_InitStruct.Pin = PWM_Out_Pin;
|
GPIO_InitStruct.Pin = PWM_Out_Pin | BUZZER_Pin;
|
||||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; // We would like sharp rising edges
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; // We would like sharp rising edges
|
||||||
HAL_GPIO_Init(PWM_Out_GPIO_Port, &GPIO_InitStruct);
|
HAL_GPIO_Init(PWM_Out_GPIO_Port, &GPIO_InitStruct);
|
||||||
HAL_TIM_PWM_Start(&htim3, PWM_Out_CHANNEL);
|
HAL_TIM_PWM_Start(&htim3, PWM_Out_CHANNEL);
|
||||||
|
HAL_TIM_PWM_Start(&htim3, BUZZER_CHANNEL);
|
||||||
}
|
}
|
||||||
/* TIM3 init function */
|
/* TIM3 init function */
|
||||||
static void MX_TIM2_Init(void) {
|
static void MX_TIM2_Init(void) {
|
||||||
|
|||||||
Reference in New Issue
Block a user