Browse Source

added char concat function

added fatfs
alice
Gregor Wüst 3 years ago
parent
commit
0d10df1806
1 changed files with 53 additions and 13 deletions
  1. 53
    13
      RTC/Core/Src/main.c

+ 53
- 13
RTC/Core/Src/main.c View File

/* 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 */
#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 -----------------------------------------------------------*/
/* 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;


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;


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 -----------------------------------------------*/
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 */
} }
} }


/*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;
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 */


/** /**
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);
/* 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,
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…
Cancel
Save