You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
toaster-oven-bluepill/Core/Src/app_main.c

179 lines
4.2 KiB

/**
* Main task
*/
#include <stdio.h>
#include <math.h>
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "ufb/framebuffer.h"
#include "iwdg.h"
#include "app_oled.h"
//#include "ufb/fb_text.h"
//#include "ufb/fb_7seg.h"
#include "app_temp.h"
#include "app_knob.h"
#include "app_buzzer.h"
//#include "app_heater.h"
//#include "cmsis_os2.h"
#include "eeprom_emul.h"
#include "app_safety.h"
#include "cmsis_os2.h"
extern osThreadId_t heaterTskHandle;
extern osThreadId_t mainTskHandle;
extern osThreadId_t guiTskHandle;
//static struct App {
// float oven_temp;
// int16_t set_temp;
// int16_t wheel_normed;
// uint16_t wheel;
// bool run;
//} s_app = {};
//static void redraw_display() {
// fb_clear();
//
// char tmp[100];
//
// SPRINTF(tmp, "T=%d°C", (int) s_app.oven_temp);
// fb_text(3, 3, tmp, FONT_5X7, 1);
//
// SPRINTF(tmp, "Cil=%d°C", s_app.set_temp);
// fb_text(3, 11, tmp, FONT_5X7, 1);
//
// SPRINTF(tmp, "Stav=%s", s_app.run ? "ZAP" : "VYP");
// fb_text(3, 19, tmp, FONT_5X7, 1);
//
// if (s_app.run) {
// fb_frame(0, 0, FBW, FBH, 2, 1);
// }
//
// // some funny effects to showcase responsiveness and circle drawing
//
// fb_circle(FBW / 2, 70, 18, 1, 1);
//
// for (int i = 0; i < 6; i++) {
// float x = FBW / 2;
// float y = 70;
//
// int ii = i;
//
// float angle = (float) ii * (M_PI / 3.0) - s_app.wheel_normed * (M_PI / 24);
//
// x = x + sinf(angle) * 10;
// y = y + cosf(angle) * 10;
//
// fb_circle((fbpos_t) x, (fbpos_t) y, 4, i==0?4:1, 1);
// }
//
// fb_text(0, s_app.wheel_normed, ":3 :3", FONT_4X5, 1);
//
// fb_7seg_number(
// 2, FBH - 20,
// 10, 16,
// 2, // th
// 2, // spacing
// 1, // color
// s_app.wheel,
// 4, // places
// 2);// decimals
//
//
//
// fb_blit();
//}
void app_task_main(void *argument)
{
PUTS("Main task\r\n");
EE_Init(EE_CONDITIONAL_ERASE);
app_analog_init();
app_buzzer_init();
app_knob_init();
/* Prepare the framebuffer and OLED interface */
oled_init();
fb_clear();
/* all inited */
// notify threads that we are ready
xTaskNotifyGive(guiTskHandle);
xTaskNotifyGive(heaterTskHandle);
// while(1) {
// LL_GPIO_TogglePin(LED_GPIO_Port, LED_Pin);
// vTaskDelay(pdMS_TO_TICKS(250));
// LL_IWDG_ReloadCounter(IWDG);
// }
// /* Infinite loop */
// bool old_pushed = app_knob_pushed();
//
// bool any_change = true;
// uint32_t last_redraw = osKernelGetTickCount();
PUTS("Main loop\r\n");
for (;;) {
// sampling is done in the heater loop
// s_app.oven_temp = app_temp_read_oven();
//
// uint16_t old_wheel = s_app.wheel;
// s_app.wheel = app_knob_get_raw();
//
// // TODO do this with interrupt and/or debouncing
// bool pushed = app_knob_pushed();
// if (pushed && !old_pushed) {
// s_app.run ^= 1;
// app_heater_enable(s_app.run);
// app_buzzer_beep();
// any_change = true;
// }
// old_pushed = pushed;
//
//
// int16_t wheel_change = (int16_t)(s_app.wheel - old_wheel);
// if (wheel_change != 0) {
// s_app.wheel_normed += wheel_change;
// if (s_app.wheel_normed < 0) {
// s_app.wheel_normed = 0;
// }
// if (s_app.wheel_normed > 500) {
// s_app.wheel_normed = 500;
// }
//
// int16_t old_temp = s_app.set_temp;
//
// s_app.set_temp = (s_app.wheel_normed / 2) * 5;
//
// if (old_temp != s_app.set_temp) {
// app_buzzer_beep();
// app_heater_set_target((float) s_app.set_temp);
// any_change = true;
// }
// }
//
// uint32_t now = osKernelGetTickCount();
// if (any_change || (now - last_redraw > pdMS_TO_TICKS(500))) {
// last_redraw = now;
// redraw_display();
// any_change = false;
//
// // Blink
//
// }
vTaskDelay(pdMS_TO_TICKS(100));
// feed dogs
app_safety_poll();
}
}