Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c016ae2ebf |
+35
-48
@@ -3,23 +3,25 @@
|
|||||||
#include "lcd.h"
|
#include "lcd.h"
|
||||||
#include "DNI.h"
|
#include "DNI.h"
|
||||||
|
|
||||||
static int DNI_read(void)
|
static uint32_t DNI_read(void)
|
||||||
{
|
{
|
||||||
HAL_ADC_Start(&hadc1);
|
HAL_ADC_Start(&hadc1);
|
||||||
|
if (HAL_ADC_PollForConversion(&hadc1, 100) != HAL_OK)
|
||||||
|
PANIC(0x4000);
|
||||||
|
|
||||||
HAL_StatusTypeDef s = HAL_ADC_PollForConversion(&hadc1, 100);
|
return HAL_ADC_GetValue(&hadc1);
|
||||||
|
|
||||||
if (HAL_OK != s)
|
|
||||||
return -s;
|
|
||||||
else
|
|
||||||
return HAL_ADC_GetValue(&hadc1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int DNI_convert_to_celsius(int value)
|
static int DNI_convert_to_celsius(uint32_t value)
|
||||||
{
|
{
|
||||||
return (2512 - value) << 2;
|
return (2512 - value) << 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int DNI_convert_to_fahrenheit(uint32_t value)
|
||||||
|
{
|
||||||
|
return (2953 - value) * 50 / 7;
|
||||||
|
}
|
||||||
|
|
||||||
static void DNI_print(int temperature)
|
static void DNI_print(int temperature)
|
||||||
{
|
{
|
||||||
int add_sign = temperature < 0;
|
int add_sign = temperature < 0;
|
||||||
@@ -48,48 +50,27 @@ static void DNI_print(int temperature)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (add_sign) {
|
if (add_sign) {
|
||||||
DISPLAY_SET_CURSOR(1, 9);
|
DISPLAY_SET_CURSOR(1, 4);
|
||||||
display_write_data_byte('-');
|
display_write_data_byte('-');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DNI_print_celsius(int temperature)
|
static void DNI_print_celsius(int temperature)
|
||||||
{
|
{
|
||||||
DISPLAY_SET_CURSOR(1, 15);
|
DISPLAY_SET_CURSOR(1, 10);
|
||||||
DISPLAY_SET_DECREMENT;
|
DISPLAY_SET_DECREMENT;
|
||||||
display_write_data_seq("C ");
|
display_write_data_seq("C ");
|
||||||
|
|
||||||
DNI_print(temperature);
|
DNI_print(temperature);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_ok(void)
|
static void DNI_print_fahrenheit(int temperature)
|
||||||
{
|
{
|
||||||
DISPLAY_SET_CURSOR(1, 4);
|
DISPLAY_SET_CURSOR(1, 10);
|
||||||
DISPLAY_SET_INCREMENT;
|
DISPLAY_SET_DECREMENT;
|
||||||
display_write_data_seq("OK");
|
display_write_data_seq("F ");
|
||||||
}
|
|
||||||
|
|
||||||
static void print_error(int err_code)
|
DNI_print(temperature);
|
||||||
{
|
|
||||||
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)
|
int DNI_show_celsius(void)
|
||||||
@@ -99,17 +80,23 @@ int DNI_show_celsius(void)
|
|||||||
|
|
||||||
display_write_data_seq("DNI Temperature");
|
display_write_data_seq("DNI Temperature");
|
||||||
|
|
||||||
int value = DNI_read();
|
uint32_t value = DNI_read();
|
||||||
|
int temp = DNI_convert_to_celsius(value);
|
||||||
|
DNI_print_celsius(temp);
|
||||||
|
|
||||||
if (value < 0) {
|
return 0;
|
||||||
print_error(-value);
|
}
|
||||||
return 1;
|
|
||||||
} else {
|
int DNI_show_fahrenheit(void)
|
||||||
int temp = DNI_convert_to_celsius(value);
|
{
|
||||||
DNI_print_celsius(temp);
|
DISPLAY_CLEAR;
|
||||||
|
DISPLAY_SET_INCREMENT;
|
||||||
print_ok();
|
|
||||||
|
display_write_data_seq("DNI Temperature");
|
||||||
return 0;
|
|
||||||
}
|
uint32_t value = DNI_read();
|
||||||
|
int temp = DNI_convert_to_fahrenheit(value);
|
||||||
|
DNI_print_fahrenheit(temp);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -139,9 +139,6 @@ static void display_write_data_byte_framebuffer(uint8_t code)
|
|||||||
if (display_current_frame >= DISPLAY_FRAMES_AVAILABLE)
|
if (display_current_frame >= DISPLAY_FRAMES_AVAILABLE)
|
||||||
return;
|
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;
|
display_framebuffer[16*2*display_current_frame + des.cursor_offset] = (char) code;
|
||||||
des.cursor_offset += des.next ? -1 : 1;
|
des.cursor_offset += des.next ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user