3 Commits

Author SHA1 Message Date
hasslesstech 4f8fe7ba39 [DNI] refresh ancient code that could hang the system
- remove the usage of ancient PANIC macro
- remove the unused fahrenheit conversion code
- add proper detection and printouts of HAL errors
2025-04-20 11:43:00 +03:00
hasslesstech d145aa3661 add test number tags automatically written to framebuffers and accomodate module formatting to make room for those 2025-04-19 16:53:19 +03:00
hasslesstech c9b90a679e [lcd] forbid writing outside of current framebuffer memory 2025-04-19 15:54:14 +03:00
2 changed files with 51 additions and 35 deletions
+48 -35
View File
@@ -3,25 +3,23 @@
#include "lcd.h"
#include "DNI.h"
static uint32_t DNI_read(void)
static int DNI_read(void)
{
HAL_ADC_Start(&hadc1);
if (HAL_ADC_PollForConversion(&hadc1, 100) != HAL_OK)
PANIC(0x4000);
return HAL_ADC_GetValue(&hadc1);
HAL_StatusTypeDef s = HAL_ADC_PollForConversion(&hadc1, 100);
if (HAL_OK != s)
return -s;
else
return HAL_ADC_GetValue(&hadc1);
}
static int DNI_convert_to_celsius(uint32_t value)
static int DNI_convert_to_celsius(int value)
{
return (2512 - value) << 2;
}
static int DNI_convert_to_fahrenheit(uint32_t value)
{
return (2953 - value) * 50 / 7;
}
static void DNI_print(int temperature)
{
int add_sign = temperature < 0;
@@ -50,27 +48,48 @@ static void DNI_print(int temperature)
}
if (add_sign) {
DISPLAY_SET_CURSOR(1, 4);
DISPLAY_SET_CURSOR(1, 9);
display_write_data_byte('-');
}
}
static void DNI_print_celsius(int temperature)
{
DISPLAY_SET_CURSOR(1, 10);
DISPLAY_SET_CURSOR(1, 15);
DISPLAY_SET_DECREMENT;
display_write_data_seq("C ");
DNI_print(temperature);
}
static void DNI_print_fahrenheit(int temperature)
static void print_ok(void)
{
DISPLAY_SET_CURSOR(1, 10);
DISPLAY_SET_DECREMENT;
display_write_data_seq("F ");
DISPLAY_SET_CURSOR(1, 4);
DISPLAY_SET_INCREMENT;
display_write_data_seq("OK");
}
DNI_print(temperature);
static void print_error(int err_code)
{
DISPLAY_SET_CURSOR(1, 4);
DISPLAY_SET_INCREMENT;
switch (err_code) {
case HAL_OK:
break;
case HAL_ERROR:
display_write_data_seq("HAL_ERROR");
break;
case HAL_BUSY:
display_write_data_seq("HAL_BUSY");
break;
case HAL_TIMEOUT:
display_write_data_seq("HAL_TIMEOUT");
break;
default:
display_write_data_seq("WRONG ERROR");
break;
}
}
int DNI_show_celsius(void)
@@ -80,23 +99,17 @@ int DNI_show_celsius(void)
display_write_data_seq("DNI Temperature");
uint32_t value = DNI_read();
int temp = DNI_convert_to_celsius(value);
DNI_print_celsius(temp);
int value = DNI_read();
return 0;
}
int DNI_show_fahrenheit(void)
{
DISPLAY_CLEAR;
DISPLAY_SET_INCREMENT;
display_write_data_seq("DNI Temperature");
uint32_t value = DNI_read();
int temp = DNI_convert_to_fahrenheit(value);
DNI_print_fahrenheit(temp);
return 0;
if (value < 0) {
print_error(-value);
return 1;
} else {
int temp = DNI_convert_to_celsius(value);
DNI_print_celsius(temp);
print_ok();
return 0;
}
}
+3
View File
@@ -139,6 +139,9 @@ static void display_write_data_byte_framebuffer(uint8_t code)
if (display_current_frame >= DISPLAY_FRAMES_AVAILABLE)
return;
if (((int) des.cursor_offset >= 32) || ((int) des.cursor_offset < 0))
return;
display_framebuffer[16*2*display_current_frame + des.cursor_offset] = (char) code;
des.cursor_offset += des.next ? -1 : 1;
}