vertical power les bars working
This commit is contained in:
parent
17be17b75c
commit
92d0e1b3da
|
@ -8,6 +8,7 @@
|
|||
#include "uart.h"
|
||||
|
||||
#define BUFSIZE 40
|
||||
#define CURRENT_MAX 30000 // 30 Ampere is max
|
||||
|
||||
volatile uint16_t syscounter = 0;
|
||||
volatile uint8_t digitbuffer[6] = { 0,0,0,0,0,0 };
|
||||
|
@ -34,6 +35,10 @@ const uint8_t digit_translate[10] = {
|
|||
63, 6, 91, 79, 102, 109, 125, 7, 127, 111
|
||||
};
|
||||
|
||||
const uint8_t leddigit_translate[9] = {
|
||||
0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff
|
||||
};
|
||||
|
||||
|
||||
static void timer_init(void) {
|
||||
// clock is 8MHz
|
||||
|
@ -74,6 +79,31 @@ static void print_sevenseg(uint8_t display, uint16_t value) {
|
|||
digitbuffer[i+3] = digit_translate[d[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void print_bar(uint8_t display, uint16_t value, uint16_t max) {
|
||||
uint16_t x = 0;
|
||||
float temp = max;
|
||||
|
||||
x = (uint16_t)( (value / temp) * 8.0);
|
||||
|
||||
if(x > 8) x = 8;
|
||||
|
||||
switch(display) {
|
||||
case LEDS_LOAD:
|
||||
leddigitbuffer[2] = leddigit_translate[x];
|
||||
break;
|
||||
case LEDS_GEN:
|
||||
leddigitbuffer[3] = leddigit_translate[x];
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
static void print_bar_bottom(uint16_t curin, uint16_t curout) {
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -175,19 +205,16 @@ void process_command() {
|
|||
}
|
||||
}
|
||||
|
||||
void work_uart(){
|
||||
static void work_uart(){
|
||||
unsigned int c = uart_getc();
|
||||
|
||||
if ( !(c & UART_NO_DATA) ) {
|
||||
|
||||
data_in[data_count] = c;
|
||||
|
||||
if (data_in[data_count] == 'B') { // finish reading when newline is received
|
||||
if (data_in[data_count] == 'B') {
|
||||
data_count = 0;
|
||||
|
||||
memcpy(command_in, data_in, BUFSIZE);
|
||||
|
||||
// Now clear data_in, the UART can reuse it now
|
||||
memset(data_in, 0, BUFSIZE);
|
||||
|
||||
process_command();
|
||||
|
@ -198,8 +225,6 @@ void work_uart(){
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int main(void) {
|
||||
ports_init();
|
||||
timer_init();
|
||||
|
@ -210,12 +235,15 @@ int main(void) {
|
|||
|
||||
work_uart();
|
||||
|
||||
if(syscounter >= 200) {
|
||||
if(syscounter >= 100) {
|
||||
uart_putc('a'); // send a to receive values
|
||||
|
||||
print_sevenseg(0, power_gen);
|
||||
print_sevenseg(1, power_load);
|
||||
|
||||
print_bar(LEDS_GEN, current_in, CURRENT_MAX);
|
||||
print_bar(LEDS_LOAD, current_out, CURRENT_MAX);
|
||||
|
||||
syscounter = 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue