application: minor, rename yeast to levain

This commit is contained in:
King Kévin 2020-12-17 12:41:21 +01:00
parent 991921ed99
commit 0b984d2db8
1 changed files with 40 additions and 38 deletions

View File

@ -1,4 +1,4 @@
/** firmware to raise sourdough starter (also called yeast)
/** firmware to raise sourdough starter (aka. levain)
* @file
* @author King Kévin <kingkevin@cuvoodoo.info>
* @copyright SPDX-License-Identifier: GPL-3.0-or-later
@ -55,14 +55,14 @@ static volatile bool second_flag = false; /**< flag set when a second passed */
static uint32_t boot_time = 0;
// current state
static uint32_t yeast_time = 0; /**< when we start heating the yeas */
static uint32_t max_time = 0; /**< when the yeast has grown */
static uint32_t levain_time = 0; /**< when we start heating the yeas */
static uint32_t max_time = 0; /**< when the sourdough starter has grown */
static uint16_t current_height = 0; /**< current height */
static uint8_t container_height = 0; /**< how height the container is */
static uint8_t starter_height = 0; /**< how height the yeast/sour dough starter is */
static uint8_t max_height = 0; /**< the maximum height the yeast reached */
static uint8_t starter_height = 0; /**< how height the sourdough starter starter is */
static uint8_t max_height = 0; /**< the maximum height the sourdough starter reached */
static float heater_temp = NAN; /**< heater temperature */
static float yeast_temp = NAN; /**< yeast/sour dough starter temperature */
static float levain_temp = NAN; /**< sourdough starter temperature */
/** heater control pin
* @note connected to power nMOS gate, pulled up to 5V
@ -83,8 +83,8 @@ const uint8_t channels[] = {ADC_CHANNEL17, ADC_CHANNEL(THERMISTOR_CHANNEL)};
/** pin to control buzzer (active high, piezo-element with driver circuit) */
#define BUZZER_PIN PB2
/** temperature to heat the yeast to, in °C */
const float yeast_target = 30.0;
/** temperature to heat the sourdough starter to, in °C */
const float levain_target = 30.0;
size_t putc(char c)
{
@ -348,16 +348,16 @@ static void command_state(void* argument)
printf("initial height: %u mm\n", height);
height = ((container_height && current_height) ? (container_height - current_height) : 0);
printf("current height: %u mm\n", height);
printf("sourdough temperature: %.02f °C\n", yeast_temp);
printf("sourdough temperature: %.02f °C\n", levain_temp);
printf("heater temperature: %.02f °C\n", heater_temp);
puts("heater: ");
puts(gpio_get(GPIO_PORT(HEATER_PIN), GPIO_PIN(HEATER_PIN)) ? "on\n" : "off\n");
uint32_t time = (yeast_time ? (rtc_to_seconds() - yeast_time) : 0);
printf("current time: %02u:%02u:%02u\n", time / 60 / 24, (time / 60) % 60, time % 60);
uint32_t time = (levain_time ? (rtc_to_seconds() - levain_time) : 0);
printf("current time: %02u:%02u:%02u\n", time / (60 * 60), (time / 60) % 60, time % 60);
height = ((container_height && max_height) ? (container_height - max_height) : 0);
printf("maximum height: %u mm\n", height);
time = (max_time ? (max_time - yeast_time) : 0);
printf("maximum height time: %02u:%02u:%02u\n", time / 60 / 24, (time / 60) % 60, time % 60);
time = (max_time ? (max_time - levain_time) : 0);
printf("maximum height time: %02u:%02u:%02u\n", time / (60 * 60), (time / 60) % 60, time % 60);
}
/** list of all supported commands */
@ -496,7 +496,7 @@ void main(void)
board_setup(); // setup board
uart_setup(); // setup USART (for printing)
usb_cdcacm_setup(); // setup USB CDC ACM (for printing)
puts("\nwelcome to the CuVoodoo STM32F4 yeast raiser\n"); // print welcome message
puts("\nwelcome to the CuVoodoo elevainitor sourdough starter raiser\n"); // print welcome message
#if DEBUG
// show reset cause
@ -639,7 +639,7 @@ void main(void)
const bool oled_text_ok = oled_text_setup(); // setup display
if (oled_text_ok) {
oled_text_clear();
oled_text_line("YEAST RAISER", 0);
oled_text_line("ELEVAINITOR", 0);
oled_text_update();
puts("OK\n");
} else {
@ -687,7 +687,7 @@ void main(void)
bool action = false; // if an action has been performed don't go to sleep
button_flag = false; // reset button flag
led_on(); // switch LED to indicate booting completed
uint32_t peak_time = 0; // when the yeast has reached its peak
uint32_t peak_time = 0; // when the sourdough starter has reached its peak
while (true) { // infinite loop
iwdg_reset(); // kick the dog
if (user_input_available) { // user input is available
@ -703,7 +703,7 @@ void main(void)
if (!all_ok) {
puts("can only start when all peripherals are ok\n");
puts("restart to check again\n");
} else if (0 == container_height) { // time to get container height
} else if (0 == container_height) { // time to get container height
puts("container height: ");
sleep_ms(2000); // wait for used to remove his finger from the lid
sensor_sr04_distance = 0; // clear measurement
@ -723,7 +723,7 @@ void main(void)
beep(1); // beep to indicate action completed
}
sensor_sr04_distance = 0; // clear measurement
} else if (0 == yeast_time || 0 == starter_height) { // time to start monitoring
} else if (0 == levain_time || 0 == starter_height) { // time to start monitoring
puts("starter height: ");
sleep_ms(2000); // wait for used to remove his finger from the lid
sensor_sr04_distance = 0; // clear measurement
@ -738,8 +738,8 @@ void main(void)
} else { // valid height
starter_height = sensor_sr04_distance; // remember height
max_height = starter_height; // initialize the maximum height
yeast_time = rtc_to_seconds(); // remember when we start monitoring
max_time = yeast_time; // initialize the maximum height time
levain_time = rtc_to_seconds(); // remember when we start monitoring
max_time = levain_time; // initialize the maximum height time
printf("%u mm\n", starter_height); // display measurement
beep(1); // beep to indicate action completed
}
@ -755,63 +755,65 @@ void main(void)
second_flag = false; // clear flag
action = true; // action will be performed
led_toggle(); // toggle LED to indicate if main function is stuck
// show heater temperature
// get heater temperature
if (sensor_ds18b20_present) {
heater_temp = sensor_ds18b20_temperature(0); // get temperature
if (85.0 != heater_temp) { // the conversion has not been completed
sensor_ds18b20_convert(0); // start next conversion
}
}
// show yeast temperature
// get sourdough starter temperature
if (thermsitor_ok) {
yeast_temp = thermistor_temperature(); // get temperature
levain_temp = thermistor_temperature(); // get temperature
}
// update uptime
if (yeast_time) {
const uint32_t uptime = rtc_to_seconds() - yeast_time; // get time from internal RTC
if (levain_time) {
const uint32_t uptime = rtc_to_seconds() - levain_time; // get time from internal RTC
char strtime[12]; // to store time representation
snprintf(strtime, sizeof(strtime), "%u.%02u:%02u:%02u", uptime / (24 * 60 * 60), (uptime / (60 * 60)) % 24, (uptime / 60) % 60, uptime % 60); // get uptime representation
oled_text_line(strtime, 1); // add text to display buffer
}
// update height
// get height
if (sensor_sr04_ok) { // sensor working
sensor_sr04_trigger(); // start measurement
}
// heat up yeast
if (yeast_time && !isnan(yeast_temp) && heater_ok && !isnan(heater_temp)) {
if (yeast_temp < yeast_target - 0.5 && 0 == peak_time) { // temperature not reached
// heat up sourdough starter
if (levain_time && !isnan(levain_temp) && heater_ok && !isnan(heater_temp)) {
if (levain_temp < levain_target - 0.5 && 0 == peak_time) { // temperature not reached
heater_on(); // keep heating
} else if (yeast_temp > yeast_target + 0.5) { // temperature reached
} else if (levain_temp > levain_target + 0.5) { // temperature reached
heater_off(); // stop heating
}
}
if (!isnan(heater_temp) && heater_temp > HEATER_LIMIT) { // turn off heater for safety
// turn off heater for safety
if (!isnan(heater_temp) && heater_temp > HEATER_LIMIT) {
heater_off(); // stop heating
}
// update how much the start raised
// update how much the starter raised
if (current_height && container_height && starter_height && max_height && current_height <= starter_height) {
const float rising = (container_height - current_height) * 1.0 / (container_height - starter_height); // calculate ratio
char text[13]; // to store text representation
snprintf(text, sizeof(text), "%.02fx %.01fC", rising, yeast_temp); // display ratio and temperature
snprintf(text, sizeof(text), "%.02fx %.01fC", rising, levain_temp); // display ratio and temperature
oled_text_line(text, 2); // add text to display buffer
if (current_height < max_height && current_height + 5U > max_height) { // a new maximum height has been reached (and is credible)
if (current_height < max_height && (current_height + 5U) > max_height) { // a new maximum height has been reached (and is credible)
max_height = current_height; // save new maximum height
max_time = rtc_to_seconds(); // remember the time
}
if (current_height > max_height + 5) { // the yeast has been falling again
if (current_height > max_height + 5) { // the sourdough starter has been falling again
if (max_time > peak_time) {
heater_off(); // stop heating
peak_time = max_time; // remember the peak yeast time
peak_time = max_time; // remember the peak sourdough starter time
const float peak_ratio = (container_height - max_height) * 1.0 / (container_height - starter_height); // calculate ratio
const uint16_t peak_period = peak_time - yeast_time; // calculate peak time
const uint16_t peak_period = peak_time - levain_time; // calculate peak time
snprintf(text, sizeof(text), "%.02fx %um", peak_ratio, peak_period / 60); // display peak ratio and time
oled_text_line(text, 3); // add text to display buffer
beep(2); // beep to indicate the peak has been reached
}
}
}
// display new data (even if nothing new)
if (oled_text_ok) {
oled_text_update(); // display new (even if not new)
oled_text_update(); // display buffered data
}
}
if (sensor_sr04_distance) { // distance measurement is available