Added MyRTC_Struct_TypeDef, modified battery function to show the time, and the percent

This commit is contained in:
Yohan Boujon 2023-04-11 11:28:42 +02:00
parent 179f7b0f13
commit 33d73b2c82
6 changed files with 51 additions and 25 deletions

View file

@ -32,7 +32,7 @@ void MyADC_ActiveIT(ADC_TypeDef * ADC, uint8_t Prio)
{
ADC->CR1 |= ADC_CR1_EOCIE; //Interruption active
NVIC->IP[ADC1_2_IRQn] |= (Prio << 0x4); //Prio de l'interruption (p.197 manuel reference RM0008 pour ADC1_IRQn)
NVIC->ISER[0] |= (0x1<<ADC1_2_IRQn); //Active l'interruption au niveau NVIC (p.119 manuel programming pour ISER[0])
NVIC->ISER[0] |= (1<<ADC1_2_IRQn); //Active l'interruption au niveau NVIC (p.119 manuel programming pour ISER[0])
}
void ADC1_2_IRQHandler(void)

View file

@ -1,30 +1,42 @@
#include "battery.h"
#include "adc.h"
#include "remote.h"
extern MyUART_Struct_Typedef uartCool;
int actualMinutes =-1;
void battery(uint32_t data)
{
int i;
MyRTC_Struct_TypeDef rtcBattery;
MyRTC_GetTime(&rtcBattery);
if(actualMinutes == rtcBattery.minutes)
{
return;
}
actualMinutes = rtcBattery.minutes;
float percentBattery = ((float)data)/MAX_BAT;
uint8_t batteryBar[12], batteryGauge=percentBattery*10;
uint8_t batteryBar[13]={'[','.','.','.','.','.','.','.','.','.','.',']',0x20}, batteryGauge=percentBattery*10, i;
if(batteryGauge>10)
{
batteryGauge = 10;
}
batteryBar[0] = '[';
for(i=1; i<=(10-batteryGauge); i++)
{
batteryBar[i]='.';
}
while(i<11)
char timerClock[8] = {'[','.','.','h','.','.',']',0x20};
sprintf(timerClock+1,"%.*d",2,rtcBattery.hours);
timerClock[3]=':';
sprintf(timerClock+4,"%.*d",2,rtcBattery.minutes);
timerClock[3]='\t';
MyUART_SendArray(&uartCool, (uint8_t *)timerClock, 8);
for(i=(10-batteryGauge); i<11; i++)
{
batteryBar[i]='#';
i++;
}
batteryBar[i]=']';
MyUART_SendArray(&uartCool, batteryBar, 12);
MyUART_SendArray(&uartCool, batteryBar, 13);
char batteryPercentString[3];
sprintf(batteryPercentString,"%.*g",2,percentBattery*100);
batteryPercentString[2]='%';
MyUART_SendArray(&uartCool, (uint8_t *)batteryPercentString, 6);
MyUART_Send(&uartCool, '\n');
}
void initBattery(void)
@ -32,6 +44,6 @@ void initBattery(void)
MyADC_Init_Periph(battery);
MyADC_Struct_TypeDef adcBattery = {ADC1,10,cycles41d5};
MyADC_Init(&adcBattery);
MyGPIO_Struct_TypeDef gpioBattery = {GPIOC,0,In_Analog};;
MyGPIO_Struct_TypeDef gpioBattery = {GPIOC,0,In_Analog};
MyGPIO_Init(&gpioBattery);
}

View file

@ -1,6 +1,10 @@
#ifndef BATTERY_H
#define BATTERY_H
#include "stm32f10x.h"
#include "adc.h"
#include "remote.h"
#include "rtc.h"
#include <stdio.h>
#define MAX_BAT 1145
void battery(uint32_t data);

View file

@ -11,7 +11,7 @@ void MyRTC_Init(void)
MyI2C_Init(I2C2, 15, IT_I2C_Err);
}
void MyRTC_GetTime(int* sec, int* min, int* hour, int* day, int* date, int* month, int* year)
void MyRTC_GetTime(MyRTC_Struct_TypeDef * rtc)
{
MyI2C_RecSendData_Typedef data;
char regCopy = 0;
@ -21,17 +21,17 @@ void MyRTC_GetTime(int* sec, int* min, int* hour, int* day, int* date, int* mont
data.Nb_Data = 1;
MyI2C_GetString(I2C2, 0x00, &data);
*sec = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
rtc->seconds = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
MyI2C_GetString(I2C2, 0x01, &data);
*min = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
rtc->minutes = ((regCopy >> 4) & 0x07) * 10 + (regCopy & 0x0F);
MyI2C_GetString(I2C2, 0x02, &data);
*hour = 0;
rtc->hours = 0;
MyI2C_GetString(I2C2, 0x03, &data);
*day = (regCopy & 0x07);
rtc->day = (regCopy & 0x07);
MyI2C_GetString(I2C2, 0x04, &data);
*date = ((regCopy >> 4) & 0x03) * 10 + (regCopy & 0x0F);
rtc->date = ((regCopy >> 4) & 0x03) * 10 + (regCopy & 0x0F);
MyI2C_GetString(I2C2, 0x05, &data);
*month = ((regCopy >> 4) & 0x01) * 10 + (regCopy & 0x0F);
rtc->month = ((regCopy >> 4) & 0x01) * 10 + (regCopy & 0x0F);
MyI2C_GetString(I2C2, 0x06, &data);
*year = ((regCopy >> 4) & 0xF0) * 10 + (regCopy & 0x0F) + 2000;
rtc->year = ((regCopy >> 4) & 0xF0) * 10 + (regCopy & 0x0F) + 2000;
}

View file

@ -3,7 +3,17 @@
#include "stm32f10x.h"
#include "MyI2C.h"
typedef struct{
int seconds;
int minutes;
int hours;
int day;
int date;
int month;
int year;
} MyRTC_Struct_TypeDef;
void MyRTC_Init(void);
void MyRTC_GetTime(int* sec, int* min, int* hour, int* day, int* date, int* month, int* year);
void MyRTC_GetTime(MyRTC_Struct_TypeDef * rtc);
#endif

View file

@ -28,6 +28,6 @@ void initImplementation(void)
MyMotor_ChangeSpeed(0);
MyMotor_ChangeDirection(HORAIRE);
MyRTC_Init();
accelerometre();
initBattery();
accelerometre();
}