added char concat function
added fatfs
This commit is contained in:
parent
9e4072b3cb
commit
0d10df1806
@ -19,6 +19,7 @@
|
|||||||
/* USER CODE END Header */
|
/* USER CODE END Header */
|
||||||
/* Includes ------------------------------------------------------------------*/
|
/* Includes ------------------------------------------------------------------*/
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "fatfs.h"
|
||||||
|
|
||||||
/* Private includes ----------------------------------------------------------*/
|
/* Private includes ----------------------------------------------------------*/
|
||||||
/* USER CODE BEGIN Includes */
|
/* USER CODE BEGIN Includes */
|
||||||
@ -26,6 +27,8 @@
|
|||||||
#include "stdbool.h"
|
#include "stdbool.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "fatfs_sd.h"
|
||||||
|
#include <stdarg.h>
|
||||||
/* USER CODE END Includes */
|
/* USER CODE END Includes */
|
||||||
|
|
||||||
/* Private typedef -----------------------------------------------------------*/
|
/* Private typedef -----------------------------------------------------------*/
|
||||||
@ -44,6 +47,8 @@
|
|||||||
/* USER CODE END PM */
|
/* USER CODE END PM */
|
||||||
|
|
||||||
/* Private variables ---------------------------------------------------------*/
|
/* Private variables ---------------------------------------------------------*/
|
||||||
|
SPI_HandleTypeDef hspi1;
|
||||||
|
ADC_HandleTypeDef hadc;
|
||||||
RTC_HandleTypeDef hrtc;
|
RTC_HandleTypeDef hrtc;
|
||||||
UART_HandleTypeDef huart2;
|
UART_HandleTypeDef huart2;
|
||||||
|
|
||||||
@ -53,7 +58,6 @@ RTC_DateTypeDef sDate;
|
|||||||
RTC_AlarmTypeDef sAlarmA, sAlarmB;
|
RTC_AlarmTypeDef sAlarmA, sAlarmB;
|
||||||
static volatile uint16_t gLastError;
|
static volatile uint16_t gLastError;
|
||||||
static volatile bool gButtonPressed = FALSE;
|
static volatile bool gButtonPressed = FALSE;
|
||||||
static volatile float sunWindow;
|
|
||||||
|
|
||||||
//Nuremberg coordinates
|
//Nuremberg coordinates
|
||||||
int latitude_nbg = 49;
|
int latitude_nbg = 49;
|
||||||
@ -92,6 +96,20 @@ typedef struct {
|
|||||||
|
|
||||||
timeStamp time;
|
timeStamp time;
|
||||||
|
|
||||||
|
// SD CARD Variables
|
||||||
|
FATFS fs;
|
||||||
|
FATFS *pfs;
|
||||||
|
FIL fil;
|
||||||
|
FRESULT fres;
|
||||||
|
DWORD fre_clust;
|
||||||
|
uint32_t totalSpace, freeSpace;
|
||||||
|
char buffer[100];
|
||||||
|
uint16_t AD_RES;
|
||||||
|
int num;
|
||||||
|
|
||||||
|
//Variable name for txt file
|
||||||
|
char txtVar[19];
|
||||||
|
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
/* Private function prototypes -----------------------------------------------*/
|
/* Private function prototypes -----------------------------------------------*/
|
||||||
@ -99,6 +117,8 @@ void SystemClock_Config(void);
|
|||||||
static void MX_GPIO_Init(void);
|
static void MX_GPIO_Init(void);
|
||||||
static void MX_USART2_UART_Init(void);
|
static void MX_USART2_UART_Init(void);
|
||||||
static void MX_RTC_Init(void);
|
static void MX_RTC_Init(void);
|
||||||
|
static void MX_SPI1_Init(void);
|
||||||
|
static void MX_ADC_Init(void);
|
||||||
static void MyFlagInterruptHandler(void);
|
static void MyFlagInterruptHandler(void);
|
||||||
void ButtonHandler(void);
|
void ButtonHandler(void);
|
||||||
/* USER CODE BEGIN PFP */
|
/* USER CODE BEGIN PFP */
|
||||||
@ -443,17 +463,6 @@ void set_time_and_date(timeAndDate *timeanddate){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void setDate(timeAndDate *date){
|
|
||||||
|
|
||||||
if (HAL_RTC_GetDate(&hrtc, &sDate, RTC_FORMAT_BIN) == HAL_OK)
|
|
||||||
{
|
|
||||||
date->weekDay = sDate.WeekDay;
|
|
||||||
date->month = sDate.Month;
|
|
||||||
date->day = sDate.Date;
|
|
||||||
date->year = 2000 + sDate.Year;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int calc_interval_duration(timeAndDate *sunrise, timeAndDate *sunset){
|
int calc_interval_duration(timeAndDate *sunrise, timeAndDate *sunset){
|
||||||
int duration_h=0;
|
int duration_h=0;
|
||||||
int duration_m=0;
|
int duration_m=0;
|
||||||
@ -469,6 +478,20 @@ int calc_interval_duration(timeAndDate *sunrise, timeAndDate *sunset){
|
|||||||
return (duration_h * 60 + duration_m) / leapsFor180Deg;
|
return (duration_h * 60 + duration_m) / leapsFor180Deg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char int_to_char_and_concat(int amount, char* separator, ...){
|
||||||
|
va_list argumentlist;
|
||||||
|
va_start(argumentlist, separator);
|
||||||
|
char str[200] = "";
|
||||||
|
|
||||||
|
while (amount--){
|
||||||
|
char arg = va_arg(argumentlist, char);
|
||||||
|
strcat(str, arg);
|
||||||
|
strcat(str, separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -501,9 +524,13 @@ int main(void)
|
|||||||
MX_GPIO_Init();
|
MX_GPIO_Init();
|
||||||
MX_USART2_UART_Init();
|
MX_USART2_UART_Init();
|
||||||
MX_RTC_Init();
|
MX_RTC_Init();
|
||||||
|
MX_SPI1_Init();
|
||||||
|
MX_FATFS_Init();
|
||||||
|
MX_ADC_Init();
|
||||||
/* USER CODE BEGIN 2 */
|
/* USER CODE BEGIN 2 */
|
||||||
|
|
||||||
//----- Init of the Motor control library
|
//######### Inits of the Motor control library #########
|
||||||
|
|
||||||
/* Set the L6208 library to use 1 device */
|
/* Set the L6208 library to use 1 device */
|
||||||
BSP_MotorControl_SetNbDevices(BSP_MOTOR_CONTROL_BOARD_ID_L6208, 1);
|
BSP_MotorControl_SetNbDevices(BSP_MOTOR_CONTROL_BOARD_ID_L6208, 1);
|
||||||
BSP_MotorControl_Init(BSP_MOTOR_CONTROL_BOARD_ID_L6208, NULL);
|
BSP_MotorControl_Init(BSP_MOTOR_CONTROL_BOARD_ID_L6208, NULL);
|
||||||
@ -523,6 +550,17 @@ int main(void)
|
|||||||
/* Disable the power bridges after initialization */
|
/* Disable the power bridges after initialization */
|
||||||
BSP_MotorControl_CmdDisable(0);
|
BSP_MotorControl_CmdDisable(0);
|
||||||
|
|
||||||
|
//######### Mount SD-Card #########
|
||||||
|
|
||||||
|
fres = f_mount(&fs, "", 0);
|
||||||
|
if (fres == FR_OK) {
|
||||||
|
transmit_uart("SD card is mounted successfully!\r\n");
|
||||||
|
} else if (fres != FR_OK) {
|
||||||
|
transmit_uart("SD card is not mounted!\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
//######### Variable inits #########
|
||||||
|
|
||||||
timeAndDate sunrise, sunset, wakeUpTimeForStep, tomorrowsDate, initialDate;
|
timeAndDate sunrise, sunset, wakeUpTimeForStep, tomorrowsDate, initialDate;
|
||||||
sunrise = sunset = wakeUpTimeForStep = tomorrowsDate = initialDate = (timeAndDate) {\
|
sunrise = sunset = wakeUpTimeForStep = tomorrowsDate = initialDate = (timeAndDate) {\
|
||||||
0,
|
0,
|
||||||
@ -549,6 +587,8 @@ int main(void)
|
|||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//######### Motor settings and motor test #########
|
||||||
|
|
||||||
HAL_Delay(2000);
|
HAL_Delay(2000);
|
||||||
|
|
||||||
transmit_uart("Resetting motor position and calculating new dates and times.\r\n");
|
transmit_uart("Resetting motor position and calculating new dates and times.\r\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user