pass boolean for period to digit_to_binary()

This commit is contained in:
Lea 2023-09-01 09:47:56 +02:00
parent 35da2e5a0b
commit 9bfe08ade6
Signed by: Lea
GPG key ID: 1BAFFE8347019C42
4 changed files with 19 additions and 17 deletions

View file

@ -14,25 +14,27 @@ void set_display_raw(volatile uint8_t * header, uint8_t data) {
*header = data; *header = data;
} }
uint8_t digit_to_binary(uint8_t input, uint8_t digit) { uint8_t digit_to_binary(bool period, uint8_t digit) {
uint8_t val = period << 7;
switch(digit) { switch(digit) {
case 0: return input | 0x3f; case 0: return val | 0x3f;
case 1: return input | 0x06; case 1: return val | 0x06;
case 2: return input | 0x5b; case 2: return val | 0x5b;
case 3: return input | 0x4f; case 3: return val | 0x4f;
case 4: return input | 0x66; case 4: return val | 0x66;
case 5: return input | 0x6d; case 5: return val | 0x6d;
case 6: return input | 0x7d; case 6: return val | 0x7d;
case 7: return input | 0x07; case 7: return val | 0x07;
case 8: return input | 0x7f; case 8: return val | 0x7f;
case 9: return input | 0x6f; case 9: return val | 0x6f;
// by default only draw the period if it was provided in the input // by default draw a dash
default: return input & (uint8_t) 0x10000000; default: return 0x01000000;
} }
} }
void set_display(volatile uint8_t * header, uint8_t value, bool period) { void set_display(volatile uint8_t * header, uint8_t value, bool period) {
uint8_t byte = digit_to_binary(period << 7, value); uint8_t byte = digit_to_binary(period, value);
set_display_raw(header, byte); set_display_raw(header, byte);
} }

View file

@ -4,4 +4,4 @@ void set_display_raw(volatile uint8_t * header, uint8_t data);
void set_display(volatile uint8_t * header, uint8_t value, bool period); void set_display(volatile uint8_t * header, uint8_t value, bool period);
uint8_t digit_to_binary(uint8_t in, uint8_t digit); uint8_t digit_to_binary(bool period, uint8_t digit);

View file

@ -54,6 +54,6 @@ void show_float(float value) {
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
bool show_period = digits == i + 1; bool show_period = digits == i + 1;
int digit = get_digit_at_position(full_number, 3 - i); int digit = get_digit_at_position(full_number, 3 - i);
set_display_value(i, digit_to_binary(show_period << 7, digit)); set_display_value(i, digit_to_binary(show_period, digit));
} }
} }

2
main.c
View file

@ -1,6 +1,6 @@
#define __AVR_ATmega2560__ #define __AVR_ATmega2560__
#define F_CPU 16000000UL #define F_CPU 16000000UL
#define TICK_BEEP true #define TICK_BEEP false
#include <avr/io.h> #include <avr/io.h>
#include <util/delay.h> #include <util/delay.h>