mirror of
https://git.etud.insa-toulouse.fr/boujon/voilier-team-1.git
synced 2025-06-08 07:50:49 +02:00
Added MyUART_SendArray function in uart.c, Modified battery function to send a battery gauge. Created MAX_BAT that defines the max level of the battery
This commit is contained in:
parent
1874f666d4
commit
179f7b0f13
4 changed files with 29 additions and 5 deletions
|
@ -106,6 +106,17 @@ void MyUART_InitGPIO(MyUART_Struct_Typedef * UARTStructPtr)
|
|||
MyGPIO_Init(&txd);
|
||||
}
|
||||
|
||||
int MyUART_SendArray(MyUART_Struct_Typedef *UART, uint8_t * data, int dataLength)
|
||||
{
|
||||
int i;
|
||||
for(i=0; i<dataLength; i++)
|
||||
{
|
||||
UART->UART->DR = data[i];
|
||||
while (!(UART->UART->SR & USART_SR_TXE));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void MyUART_Send(MyUART_Struct_Typedef *UART, uint8_t data)
|
||||
{
|
||||
UART->UART->DR = data;
|
||||
|
|
|
@ -30,6 +30,7 @@ typedef struct {
|
|||
|
||||
void MyUART_Init(MyUART_Struct_Typedef * UARTStructPtr);
|
||||
void MyUART_InitGPIO(MyUART_Struct_Typedef * UARTStructPtr);
|
||||
int MyUART_SendArray(MyUART_Struct_Typedef *UART, uint8_t * data, int dataLength);
|
||||
void MyUART_Send(MyUART_Struct_Typedef *UART, uint8_t data);
|
||||
uint8_t MyUART_Receive(MyUART_Struct_Typedef *UART);
|
||||
void MyUART_Init_Periph (void (* ptrFonction)(uint8_t));
|
||||
|
|
|
@ -6,14 +6,25 @@ extern MyUART_Struct_Typedef uartCool;
|
|||
|
||||
void battery(uint32_t data)
|
||||
{
|
||||
if(data >= 0x420) //0x429 -> approx. 12V
|
||||
int i;
|
||||
float percentBattery = ((float)data)/MAX_BAT;
|
||||
uint8_t batteryBar[12], batteryGauge=percentBattery*10;
|
||||
if(batteryGauge>10)
|
||||
{
|
||||
MyUART_Send(&uartCool,'h');
|
||||
batteryGauge = 10;
|
||||
}
|
||||
else {
|
||||
MyUART_Send(&uartCool,'l');
|
||||
batteryBar[0] = '[';
|
||||
for(i=1; i<=(10-batteryGauge); i++)
|
||||
{
|
||||
batteryBar[i]='.';
|
||||
}
|
||||
|
||||
while(i<11)
|
||||
{
|
||||
batteryBar[i]='#';
|
||||
i++;
|
||||
}
|
||||
batteryBar[i]=']';
|
||||
MyUART_SendArray(&uartCool, batteryBar, 12);
|
||||
}
|
||||
|
||||
void initBattery(void)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef BATTERY_H
|
||||
#define BATTERY_H
|
||||
#include "stm32f10x.h"
|
||||
#define MAX_BAT 1145
|
||||
|
||||
void battery(uint32_t data);
|
||||
void initBattery(void);
|
||||
|
|
Loading…
Add table
Reference in a new issue