Skip to content

Commit

Permalink
Добавил настройку ограничителя FPS
Browse files Browse the repository at this point in the history
  • Loading branch information
7134956 committed Jan 24, 2016
1 parent e778960 commit 8431c59
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 25 deletions.
19 changes: 13 additions & 6 deletions main/src/buttons.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
#endif

#include "main.h"
#include "draw.h"
#include "power.h"
#include "timer.h"

//extern uint8_t stateMain;
extern track_t track;
extern state_t state;
extern config_t config;

uint8_t button_count; //Счетчик цыклов чтения
uint8_t buttonPushed; //В данный момент нажато
Expand Down Expand Up @@ -107,11 +109,9 @@ void ButtonsInit(uint8_t mode) {
/*******************************************************************************
*Функция чтения состояния кнопок
******************************************************************************/
uint8_t readButtons(void) {
void readButtons(void) {
#ifdef SYSTEM_STM32
uint16_t adc_res;
if (state.button != BUTTON_NULL) //Тут считанное подтвержденное необработанное нажатие
return 1;
adc_res = ADC_GetConversionValue(ADC2); //Считываем значение АЦП
ADC_SoftwareStartConvCmd(ADC2, ENABLE);// Запускаем преобразование. Пускай готовится новое значение
#ifdef DEBUG
Expand Down Expand Up @@ -162,7 +162,6 @@ uint8_t readButtons(void) {
}
}
#endif
return 1;
}

/*******************************************************************************
Expand Down Expand Up @@ -211,13 +210,19 @@ void EXTI15_10_IRQHandler(void) {
if (!(state.taskList & TASK_DRIVE)) { //Если не стоял флаг движения,
TIM_Cmd(TIM4, ENABLE);//Включаем таймер
TIM_SetCounter(TIM4, 0);//Обнуляем счетчик
state.taskList |= TASK_DRIVE;//запускаем движение
circleStep(0);//Обнулили показания скорости
state.taskList |= TASK_DRIVE;// Pапускаем движение
if(config.maxFPS) //Установлено ограничение
SysTick_task_add(drawTask, 10); //Запускаем перерисовку экрана с ограничителем,
} else {
track.circleTics = TIM_GetCounter(TIM4); //Считали значение счетчика
TIM_SetCounter(TIM4, 0);//Обнуляем счетчик
track.tics += track.circleTics;
circleStep(track.circleTics);//Вызвали функцию рассчета скорости
state.taskList |= TASK_REDRAW;//Запросили перерисовку экрана
if(!config.maxFPS) //Ограничения нету
state.taskList |= TASK_REDRAW;
else
state.taskList |= TASK_LIM_REDRAW;
}
}
setPowerMode(POWERMODE_NORMAL);
Expand Down Expand Up @@ -263,6 +268,8 @@ void TIM4_IRQHandler(void) {
TIM_ClearITPendingBit(TIM4, TIM_IT_Update); //Сбрасываем бит переполнения
state.taskList &=~ TASK_DRIVE; //Снимаем признак движения
TIM_Cmd(TIM4, DISABLE); //Выключаем таймер
SysTick_task_del(drawTask); //Снимаем запросы перерисовки
state.taskList |= TASK_REDRAW; //Перерисовка
}
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion main/src/buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define MODE_ADC 2

void ButtonsInit(uint8_t );
uint8_t readButtons(void);
void readButtons(void);
void CircleSensorInit(void);
void CircleTimerInit(void);
void WakeupInit(void);
Expand Down
19 changes: 19 additions & 0 deletions main/src/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ U8G_INIT
time_p = timeGetSet(NULL);//Взяли указатель на время
u8g_SetContrast(&u8g, config.contrast);
}

/*******************************************************************************
*Запросить перерисовку
******************************************************************************/
uint8_t drawDelay = 0;

void drawTask(void) {
if(!drawDelay){
if(state.taskList & TASK_LIM_REDRAW)
{
state.taskList &=~ TASK_LIM_REDRAW;
state.taskList |= TASK_REDRAW;
drawDelay = 100/config.maxFPS;
}
}
else
drawDelay -=1;
}

/*******************************************************************************
*Включить дисплей
******************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions main/src/draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ typedef struct popup_t {
} popup_t;

void drawInit(void);
void drawTask(void);//Запросить перерисовку экрана
void redrawDisplay(void);
void displayOff(void);
void displayOn(void);
Expand Down
28 changes: 19 additions & 9 deletions main/src/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "pwm.h"
#include "rtc.h"
#include "i2c.h"
#include "timer.h"
#include "rtc.h"

#ifdef SYSTEM_STM32
#include "stm32f10x.h"
Expand Down Expand Up @@ -83,6 +85,7 @@ void I2C_EE_ByteWrite(uint8_t* pBuffer, uint16_t WriteAddr) {
* @return None
******************************************************************************/
void I2C_EE_BufferRead(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRead) {
SysTick_task_add(NVIC_GenerateSystemReset, 1000);
/* While the bus is busy */
while (I2C_GetFlagStatus(I2C_UNIT, I2C_FLAG_BUSY))
;
Expand Down Expand Up @@ -154,6 +157,7 @@ void I2C_EE_BufferRead(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRe

/* Enable Acknowledgement to be ready for another reception */
I2C_AcknowledgeConfig(I2C_UNIT, ENABLE);
SysTick_task_del(NVIC_GenerateSystemReset);
}

/*******************************************************************************
Expand All @@ -173,6 +177,8 @@ void I2C_EE_BufferWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteTo
NumOfPage = NumByteToWrite / I2C_FLASH_PAGESIZE;
NumOfSingle = NumByteToWrite % I2C_FLASH_PAGESIZE;

SysTick_task_add(NVIC_GenerateSystemReset, 1000);

/* If WriteAddr is I2C_FLASH_PAGESIZE aligned */
if (Addr == 0) {
/* If NumByteToWrite < I2C_FLASH_PAGESIZE */
Expand Down Expand Up @@ -239,6 +245,7 @@ void I2C_EE_BufferWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteTo
}
}
}
SysTick_task_del(NVIC_GenerateSystemReset);
}
/*******************************************************************************
* @brief Writes more than one byte to the EEPROM with a single WRITE cycle.
Expand Down Expand Up @@ -396,11 +403,12 @@ void saveParams(void) {
memcpy(&Buffer[25], &track.endCapacity, 2);
memcpy(&Buffer[27], &track.startTime, 4);
memcpy(&Buffer[31], &config.lang, 1);
memcpy(&Buffer[32], &config.SecInTime, 1);
memcpy(&Buffer[33], &config.SleepSec, 2);
memcpy(&Buffer[35], &config.SleepDisplayOff, 1);
memcpy(&Buffer[36], &config.password, 2);
memcpy(&Buffer[38], &config.contrast, 1);
memcpy(&Buffer[32], &config.maxFPS, 1);
memcpy(&Buffer[33], &config.SecInTime, 1);
memcpy(&Buffer[34], &config.SleepSec, 2);
memcpy(&Buffer[36], &config.SleepDisplayOff, 1);
memcpy(&Buffer[37], &config.password, 2);
memcpy(&Buffer[39], &config.contrast, 1);

config.crc = crc32_calc(Buffer, CONFIG_UNINT_SIZE - 4);
memcpy(&Buffer[60], &config.crc, 4);
Expand All @@ -423,11 +431,12 @@ void loadParams(void) {
memcpy(&track.endCapacity, &Buffer[25], 2);
memcpy(&track.startTime, &Buffer[27], 4);
memcpy(&config.lang, &Buffer[31], 1);
memcpy(&config.SecInTime, &Buffer[32], 1);
memcpy(&config.SleepSec, &Buffer[33], 2);
memcpy(&config.maxFPS, &Buffer[32], 1);
memcpy(&config.SecInTime, &Buffer[33], 1);
memcpy(&config.SleepSec, &Buffer[34], 2);
memcpy(&config.SleepDisplayOff, &Buffer[35], 1);
memcpy(&config.password, &Buffer[36], 2);
memcpy(&config.contrast, &Buffer[38], 1);
memcpy(&config.password, &Buffer[37], 2);
memcpy(&config.contrast, &Buffer[39], 1);

memcpy(&config.crc, &Buffer[60], 4);
} else {
Expand All @@ -441,6 +450,7 @@ void loadParams(void) {
track.endCapacity = 0;
track.startTime = 0;
config.lang = 0;
config.maxFPS = 2;
config.SecInTime = 1;
config.SleepSec = 60;
config.SleepDisplayOff = 0;
Expand Down
11 changes: 6 additions & 5 deletions main/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ mtk_element_t
mtkPin, //Пароль стартового экрана
mtkLang, //Выбор языка интерфейса
mtkDateTime, mtkDate, mtkTime, mtkPower, mtkSecInTime,
mtkSleepDisplayOff, mtkSleepSec, mtkMenuBMS, mtkAbout;
mtkMaxFPS, mtkSleepDisplayOff, mtkSleepSec, mtkMenuBMS, mtkAbout;

mtk_select_t mtkLangList;

Expand Down Expand Up @@ -183,7 +183,8 @@ int main() {
mtk_SetupElement(&mtkLang, ELEMENT_SEL, NULL, 2, 0, &mtkLangList, &mtkPower);
mtkLangList.pointer = &config.lang;
//------------------------------------------
mtk_SetupElement(&mtkPower, ELEMENT_MENU, NULL, 0, 0, &mtkSecInTime, &mtkMenuBMS);
mtk_SetupElement(&mtkPower, ELEMENT_MENU, NULL, 0, 0, &mtkMaxFPS, &mtkMenuBMS);
mtk_SetupElement(&mtkMaxFPS, ELEMENT_NUM8, NULL, 1, 0, &config.maxFPS, &mtkSecInTime);
mtk_SetupElement(&mtkSecInTime, ELEMENT_FLAG, NULL, 0, 0, &config.SecInTime, &mtkSleepSec);
mtk_SetupElement(&mtkSleepSec, ELEMENT_NUM16, NULL, 4, 0, &config.SleepSec, &mtkSleepDisplayOff);
mtk_SetupElement(&mtkSleepDisplayOff, ELEMENT_FLAG, NULL, 0, TYPE_NEEDOK, &config.SleepDisplayOff, NULL);
Expand Down Expand Up @@ -268,7 +269,7 @@ void mainLoop() {
#ifdef DEBUG_DISPLAY
track.circleTics=TIM_GetCounter(TIM4); //Считали значение счетчика. 32768 импульсов в секунду
#endif
state.taskList &= ~TASK_REDRAW;
state.taskList &= ~(TASK_REDRAW | TASK_LIM_REDRAW);
}
setPowerState(state.powerMode);
// WWDG_Renew();
Expand Down Expand Up @@ -819,7 +820,7 @@ void calculateStat(track_t *tr) {
/*******************************************************************************
*Добавить значение температуры в буфер граффика
******************************************************************************/
uint8_t addTermItem(void){
void addTermItem(void){
uint8_t i;
#ifdef SYSTEM_WIN
termo.buff[termo.in] = 10 * (sin((double) (termo.in / 15.0) + (double) 50) * 40 + 100);
Expand All @@ -840,5 +841,5 @@ uint8_t addTermItem(void){
if (termo.buff[i] > termo.max)
termo.max = termo.buff[i];
}
return 1;

}
10 changes: 6 additions & 4 deletions main/src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ typedef signed long long int64_t;
//void drawClockEditor(void);
//void buttonsParse(void);
void circleStep(uint16_t);
uint8_t addTermItem(void);
void addTermItem(void);
//void drawMain(void);

typedef struct config_t { //Глобальная структура с настройками сохраняется в EEPROM
uint8_t lang; //Выбор языка интерфейса
uint8_t SecInTime; //Отрисовывать секунды
uint8_t maxFPS; //Спящий режим через
uint16_t SleepSec; //Спящий режим через
uint8_t SleepDisplayOff; //Выключение экрана после автозасыпания
uint16_t password; //Пароль устройства
Expand All @@ -98,9 +99,10 @@ typedef struct config_t { //Глобальная структура с наст
//Глобальный флаг текущих задач
#define TASK_DRIVE 1 //Признак движения
#define TASK_REDRAW 2 //Флаг запроса перерисовки экрана
#define TASK_UPDATETIME 4
#define TASK_TIMESETUP 8
#define TASK_SAVEPARAMS 16
#define TASK_LIM_REDRAW 4 //Флаг запроса перерисовки с ограничением скорости
#define TASK_UPDATETIME 8
#define TASK_TIMESETUP 16
#define TASK_SAVEPARAMS 32

typedef struct calendar_t {
uint16_t year; //Год
Expand Down

0 comments on commit 8431c59

Please sign in to comment.