add write_uart
This commit is contained in:
parent
c09f0a81b0
commit
66002a0e1d
33
src/main.c
33
src/main.c
@ -12,6 +12,7 @@
|
|||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
const int digit_bitmaps[10][5][3] = {
|
const int digit_bitmaps[10][5][3] = {
|
||||||
{{1,1,1},{1,0,1},{1,0,1},{1,0,1},{1,1,1}}, // 0
|
{{1,1,1},{1,0,1},{1,0,1},{1,0,1},{1,1,1}}, // 0
|
||||||
@ -172,6 +173,35 @@ void read_uart(Tel *t, int fd, SerialParser *uart_str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void write_uart(Tel *t, int fd) {
|
||||||
|
// speed,rpm,power,eff,bat,tens,amp,warn
|
||||||
|
char msg[256];
|
||||||
|
int len = snprintf(msg, sizeof(msg), "%d,%d,%d,%.1f,%d,%.1f,%.1f,%d\n",
|
||||||
|
t->speed.data,
|
||||||
|
t->rpm.data,
|
||||||
|
t->power.data,
|
||||||
|
t->eff.data,
|
||||||
|
t->bat.data,
|
||||||
|
t->tens.data,
|
||||||
|
t->amp.data,
|
||||||
|
t->message.error_level );
|
||||||
|
|
||||||
|
if (len < 0 || len >= (int)sizeof(msg)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int total = 0;
|
||||||
|
while (total < len) {
|
||||||
|
int n = write(fd, msg + total, len - total);
|
||||||
|
if (n < 0) {
|
||||||
|
if (errno == EINTR) continue;
|
||||||
|
if (errno == EAGAIN) continue;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
total += n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void calc_data(Tel *t, Bat_state *b, long now) {
|
void calc_data(Tel *t, Bat_state *b, long now) {
|
||||||
t->power.data = (int)(t->tens.data * t->amp.data);
|
t->power.data = (int)(t->tens.data * t->amp.data);
|
||||||
t->speed.data = (int)(t->rpm.data * 0.017f);
|
t->speed.data = (int)(t->rpm.data * 0.017f);
|
||||||
@ -655,6 +685,9 @@ int main(int argc, char **argv) {
|
|||||||
win_float(&tel.amp, use_color);
|
win_float(&tel.amp, use_color);
|
||||||
win_int(&tel.bat, use_color);
|
win_int(&tel.bat, use_color);
|
||||||
win_warn(&tel, use_color, now);
|
win_warn(&tel, use_color, now);
|
||||||
|
|
||||||
|
if (use_uart) write_uart(&tel, uart_fd);
|
||||||
|
|
||||||
t100 = now;
|
t100 = now;
|
||||||
}
|
}
|
||||||
napms(10);
|
napms(10);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user