Added MyRTC_Struct_TypeDef, modified battery function to show the time, and the percent
This commit is contained in:
parent
179f7b0f13
commit
33d73b2c82
6 changed files with 51 additions and 25 deletions
|
@ -32,7 +32,7 @@ void MyADC_ActiveIT(ADC_TypeDef * ADC, uint8_t Prio)
|
||||||
{
|
{
|
||||||
ADC->CR1 |= ADC_CR1_EOCIE; //Interruption active
|
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->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)
|
void ADC1_2_IRQHandler(void)
|
||||||
|
|
|
@ -1,30 +1,42 @@
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
#include "adc.h"
|
|
||||||
#include "remote.h"
|
|
||||||
|
|
||||||
extern MyUART_Struct_Typedef uartCool;
|
extern MyUART_Struct_Typedef uartCool;
|
||||||
|
int actualMinutes =-1;
|
||||||
|
|
||||||
void battery(uint32_t data)
|
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;
|
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)
|
if(batteryGauge>10)
|
||||||
{
|
{
|
||||||
batteryGauge = 10;
|
batteryGauge = 10;
|
||||||
}
|
}
|
||||||
batteryBar[0] = '[';
|
char timerClock[8] = {'[','.','.','h','.','.',']',0x20};
|
||||||
for(i=1; i<=(10-batteryGauge); i++)
|
sprintf(timerClock+1,"%.*d",2,rtcBattery.hours);
|
||||||
{
|
timerClock[3]=':';
|
||||||
batteryBar[i]='.';
|
sprintf(timerClock+4,"%.*d",2,rtcBattery.minutes);
|
||||||
}
|
timerClock[3]='\t';
|
||||||
while(i<11)
|
MyUART_SendArray(&uartCool, (uint8_t *)timerClock, 8);
|
||||||
|
|
||||||
|
for(i=(10-batteryGauge); i<11; i++)
|
||||||
{
|
{
|
||||||
batteryBar[i]='#';
|
batteryBar[i]='#';
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
batteryBar[i]=']';
|
MyUART_SendArray(&uartCool, batteryBar, 13);
|
||||||
MyUART_SendArray(&uartCool, batteryBar, 12);
|
|
||||||
|
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)
|
void initBattery(void)
|
||||||
|
@ -32,6 +44,6 @@ void initBattery(void)
|
||||||
MyADC_Init_Periph(battery);
|
MyADC_Init_Periph(battery);
|
||||||
MyADC_Struct_TypeDef adcBattery = {ADC1,10,cycles41d5};
|
MyADC_Struct_TypeDef adcBattery = {ADC1,10,cycles41d5};
|
||||||
MyADC_Init(&adcBattery);
|
MyADC_Init(&adcBattery);
|
||||||
MyGPIO_Struct_TypeDef gpioBattery = {GPIOC,0,In_Analog};;
|
MyGPIO_Struct_TypeDef gpioBattery = {GPIOC,0,In_Analog};
|
||||||
MyGPIO_Init(&gpioBattery);
|
MyGPIO_Init(&gpioBattery);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
#ifndef BATTERY_H
|
#ifndef BATTERY_H
|
||||||
#define BATTERY_H
|
#define BATTERY_H
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
|
#include "adc.h"
|
||||||
|
#include "remote.h"
|
||||||
|
#include "rtc.h"
|
||||||
|
#include <stdio.h>
|
||||||
#define MAX_BAT 1145
|
#define MAX_BAT 1145
|
||||||
|
|
||||||
void battery(uint32_t data);
|
void battery(uint32_t data);
|
||||||
|
|
|
@ -11,7 +11,7 @@ void MyRTC_Init(void)
|
||||||
MyI2C_Init(I2C2, 15, IT_I2C_Err);
|
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;
|
MyI2C_RecSendData_Typedef data;
|
||||||
char regCopy = 0;
|
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;
|
data.Nb_Data = 1;
|
||||||
|
|
||||||
MyI2C_GetString(I2C2, 0x00, &data);
|
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);
|
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);
|
MyI2C_GetString(I2C2, 0x02, &data);
|
||||||
*hour = 0;
|
rtc->hours = 0;
|
||||||
MyI2C_GetString(I2C2, 0x03, &data);
|
MyI2C_GetString(I2C2, 0x03, &data);
|
||||||
*day = (regCopy & 0x07);
|
rtc->day = (regCopy & 0x07);
|
||||||
MyI2C_GetString(I2C2, 0x04, &data);
|
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);
|
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);
|
MyI2C_GetString(I2C2, 0x06, &data);
|
||||||
*year = ((regCopy >> 4) & 0xF0) * 10 + (regCopy & 0x0F) + 2000;
|
rtc->year = ((regCopy >> 4) & 0xF0) * 10 + (regCopy & 0x0F) + 2000;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,17 @@
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
#include "MyI2C.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_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
|
#endif
|
||||||
|
|
|
@ -28,6 +28,6 @@ void initImplementation(void)
|
||||||
MyMotor_ChangeSpeed(0);
|
MyMotor_ChangeSpeed(0);
|
||||||
MyMotor_ChangeDirection(HORAIRE);
|
MyMotor_ChangeDirection(HORAIRE);
|
||||||
MyRTC_Init();
|
MyRTC_Init();
|
||||||
accelerometre();
|
|
||||||
initBattery();
|
initBattery();
|
||||||
|
accelerometre();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue