Skip to content

Commit 5273812

Browse files
committed
new platform added, migration to newest ESP-IDF WiP
+ some new formatting
1 parent 8fc9ac9 commit 5273812

File tree

12 files changed

+211
-222
lines changed

12 files changed

+211
-222
lines changed

main/Tasks/core/blinker.task.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
1-
#include "freertos/FreeRTOS.h"
1+
#include "blinker.task.h"
2+
23
#include "driver/gpio.h"
34
#include "esp_log.h"
5+
#include "freertos/FreeRTOS.h"
46
#include "freertos/task.h"
5-
6-
#include "blinker.task.h"
77
#include "settings.h"
88
#define TAG "BLINKER_TASK"
99

10-
void vBlinkerTask(void *pvParameter)
11-
{
12-
portTickType xLastWakeTime;
10+
void vBlinkerTask(void *pvParameter) {
11+
TickType_t xLastWakeTime;
1312

1413
ESP_LOGI(TAG, "Initialize blinking");
1514

16-
/* specify that the function of a given pin
17-
should be that of GPIO as opposed to some other function
15+
/* specify that the function of a given pin
16+
should be that of GPIO as opposed to some other function
1817
*/
19-
gpio_pad_select_gpio(BLINK_GPIO);
18+
esp_rom_gpio_pad_select_gpio(BLINK_GPIO);
2019
/* Set the GPIO as a push/pull output */
2120
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
22-
while(true) {
21+
while (true) {
2322
xLastWakeTime = xTaskGetTickCount();
24-
vTaskDelayUntil(&xLastWakeTime,1000/portTICK_RATE_MS);
23+
vTaskDelayUntil(&xLastWakeTime, 1000 / portTICK_PERIOD_MS);
2524
gpio_set_level(BLINK_GPIO, 0);
26-
vTaskDelayUntil(&xLastWakeTime,1000/portTICK_RATE_MS);
25+
vTaskDelayUntil(&xLastWakeTime, 1000 / portTICK_PERIOD_MS);
2726
gpio_set_level(BLINK_GPIO, 1);
2827
}
2928
}

main/Tasks/core/calcRideParamsOnISR.task.c

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,81 @@
11

2+
#include "calcRideParamsOnISR.task.h"
3+
4+
#include "esp_log.h"
25
#include "freertos/FreeRTOS.h"
3-
#include "freertos/task.h"
46
#include "freertos/queue.h"
5-
#include "esp_log.h"
6-
7-
#include "calcRideParamsOnISR.task.h"
8-
#include "settings.h"
7+
#include "freertos/task.h"
98
#include "obc.h"
9+
#include "settings.h"
1010

1111
#define TAG "RIDE_CALC"
1212

1313
bool ignoreReed = false;
1414

1515
// handle server sychronization start event and set flags to block data
1616
// during synchronization, calculations should be blocked
17-
static void vOnSyncStartHandle(void* handler_args, esp_event_base_t base, int32_t id, void* event_data) {
17+
static void vOnSyncStartHandle(void *handler_args, esp_event_base_t base, int32_t id, void *event_data) {
1818
ignoreReed = true;
1919
}
2020

2121
// handle server sychronization start event and set flags to block data
2222
// if synchronization finishes with success, finish the ride, by resseting rideParams, otherwise continue
23-
static void vOnSyncFinishHandle(void* handler_args, esp_event_base_t base, int32_t id, void* event_data) {
23+
static void vOnSyncFinishHandle(void *handler_args, esp_event_base_t base, int32_t id, void *event_data) {
24+
bool reset = *((bool *)event_data);
2425

25-
bool reset = *((bool*) event_data);
26-
27-
if (reset){
26+
if (reset) {
2827
rideParams.rotations = 0;
2928
rideParams.totalRideTimeMs = 0;
3029
rideParams.speed = 0.0;
3130
rideParams.distance = 0.0;
3231
rideParams.avgSpeed = 0.0;
3332
rideParams.prevRotationTickCount = 0.0;
34-
}
33+
}
3534

3635
ignoreReed = false;
3736
}
3837

39-
void vCalcRideParamsOnISRTask(void* data)
40-
{
38+
void vCalcRideParamsOnISRTask(void *data) {
4139
float currentSpeed;
4240
uint16_t msBetweenRotationTicks;
4341

4442
ESP_LOGI(TAG, "Init reed switch");
45-
43+
4644
ESP_ERROR_CHECK(esp_event_handler_register_with(obc_events_loop, OBC_EVENTS, SYNC_START_EVENT, vOnSyncStartHandle, NULL));
4745
ESP_ERROR_CHECK(esp_event_handler_register_with(obc_events_loop, OBC_EVENTS, SYNC_STOP_EVENT, vOnSyncFinishHandle, NULL));
4846

49-
for(;;) {
50-
if(xQueueReceive(reed_evt_queue, &rideParams.rotationTickCount, portMAX_DELAY) && !ignoreReed) {
47+
for (;;) {
48+
if (xQueueReceive(reed_evt_queue, &rideParams.rotationTickCount, portMAX_DELAY) && !ignoreReed) {
5149
// TODO create buffer for reed time impulses before calculating time and speed
5250
// TODO block rideParams while calculating?
5351
if (rideParams.prevRotationTickCount != 0) {
5452
if (!rideParams.moving) {
5553
esp_event_post_to(obc_events_loop, OBC_EVENTS, RIDE_START_EVENT, NULL, 0, portMAX_DELAY);
5654
}
57-
msBetweenRotationTicks = ((int) rideParams.rotationTickCount - (int) rideParams.prevRotationTickCount) * (int) portTICK_RATE_MS;
55+
msBetweenRotationTicks = ((int)rideParams.rotationTickCount - (int)rideParams.prevRotationTickCount) * (int)portTICK_PERIOD_MS;
5856
rideParams.totalRideTimeMs += msBetweenRotationTicks;
5957
// TODO sometimes tick count doesn't update even with queue? prevent speed = inf for now
6058
if (msBetweenRotationTicks > 0.00) {
61-
currentSpeed = ( (float) CIRCUMFERENCE/1000000 ) / ( (float) msBetweenRotationTicks / 3600000 ); //km/h
59+
currentSpeed = ((float)CIRCUMFERENCE / 1000000) / ((float)msBetweenRotationTicks / 3600000); // km/h
6260
// simple, soft filtering of noise (from cables?) - should't introduce any discrepancy to actual data
6361
// and also could be used to detect unplanned, immediate stops
6462
// max reasonable acceleration is 5.8 m/s/s
65-
if (abs(currentSpeed - rideParams.speed) > 30) {
63+
if (abs((int)(currentSpeed - rideParams.speed)) > 30) {
6664
continue;
6765
}
6866

6967
rideParams.moving = true;
7068
rideParams.rotations++;
7169
rideParams.speed = currentSpeed;
72-
rideParams.distance += (float)CIRCUMFERENCE/1000000;
73-
rideParams.totalDistance += (float)CIRCUMFERENCE/1000000;
74-
rideParams.avgSpeed = rideParams.distance / ( (float) rideParams.totalRideTimeMs / 3600000 );
70+
rideParams.distance += (float)CIRCUMFERENCE / 1000000;
71+
rideParams.totalDistance += (float)CIRCUMFERENCE / 1000000;
72+
rideParams.avgSpeed = rideParams.distance / ((float)rideParams.totalRideTimeMs / 3600000);
7573
if (rideParams.speed > rideParams.maxSpeed) {
7674
rideParams.maxSpeed = rideParams.speed;
7775
}
7876
}
79-
8077
}
81-
rideParams.prevRotationTickCount = rideParams.rotationTickCount;
78+
rideParams.prevRotationTickCount = rideParams.rotationTickCount;
8279

8380
// ESP_LOGI(TAG, "[REED] count: %d, speed: %0.2f, diff: %d, distance: %0.2f", rideParams.rotations, rideParams.speed, msBetweenRotationTicks, rideParams.distance);
8481
// ESP_LOGI(TAG, "[AVGS] speed: %0.2f", rideParams.avgSpeed);
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
#include "rideStatusWatchdog.task.h"
2+
3+
#include <stdint.h>
4+
5+
#include "esp_event_base.h"
6+
#include "esp_log.h"
17
#include "freertos/FreeRTOS.h"
2-
#include "freertos/task.h"
38
#include "freertos/queue.h"
4-
#include "esp_log.h"
5-
#include "esp_event_base.h"
6-
7-
#include "rideStatusWatchdog.task.h"
8-
#include "settings.h"
9+
#include "freertos/task.h"
910
#include "obc.h"
11+
#include "settings.h"
1012

1113
#define TAG "RIDE_WATCHDOG"
12-
/*
14+
/*
1315
Task which checks every second if bike is still moving, by reading number of
1416
items waiting in reed ISR queue. Posts to obc_event_loop with ride_stop_event
1517
*/
@@ -20,19 +22,19 @@ void vRideStatusWatchdogTask(void *arg) {
2022

2123
ESP_LOGI(TAG, "Initialization");
2224

23-
while(true) {
25+
while (true) {
2426
msg_count = uxQueueMessagesWaitingFromISR(reed_evt_queue);
2527
currentTickCount = xTaskGetTickCount();
26-
timeInactive = ((int) currentTickCount - (int) rideParams.prevRotationTickCount) * (int) portTICK_RATE_MS;
28+
timeInactive = ((int)currentTickCount - (int)rideParams.prevRotationTickCount) * (int)portTICK_PERIOD_MS;
2729

28-
if(rideParams.moving && !msg_count && timeInactive > RIDE_TIMEOUT_MS) {
30+
if (rideParams.moving && !msg_count && timeInactive > RIDE_TIMEOUT_MS) {
2931
ESP_LOGI(TAG, "[RIDE_STATUS] Stopped moving");
3032
rideParams.speed = 0.0;
3133
rideParams.moving = false;
3234
rideParams.prevRotationTickCount = 0;
3335

3436
esp_event_post_to(obc_events_loop, OBC_EVENTS, RIDE_STOP_EVENT, NULL, 0, portMAX_DELAY);
35-
}
36-
vTaskDelayUntil(&currentTickCount, 1000/portTICK_RATE_MS);
37+
}
38+
vTaskDelayUntil(&currentTickCount, 1000 / portTICK_PERIOD_MS);
3739
}
3840
}

main/Tasks/screen_pcd8544/pcd8544_font_utils.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@
1111
* @TODO validate string, skip special chars, cleanup array sizes!
1212
* @TODO dynamic rows number calculation
1313
* */
14-
static void fillCharsFromBuffer(uint8_t **charArr, char *buffer, int nrOfChars, uint8_t bigCharPositions[6]) {
14+
static void fillCharsFromBuffer(uint8_t **charArr, char *buffer, int nrOfChars, uint8_t (*bigCharPositions)[6]) {
1515
for (int i = 0; i <= nrOfChars; i++) {
1616
// convert to int and fill charArr with pointers to big font characters
1717
if (*buffer != '.' && *buffer >= '0' && *buffer <= '9') {
1818
char single_char_buf[1] = {*buffer};
1919
*charArr = fontDetermination[atoi(single_char_buf)];
20-
bigCharPositions[i] = 16;
21-
} else if(*buffer == '.'){
20+
(*bigCharPositions)[i] = 16;
21+
} else if (*buffer == '.') {
2222
*charArr = fontDetermination[10];
23-
bigCharPositions[i] = 3;
23+
(*bigCharPositions)[i] = 3;
2424
} else {
2525
*charArr = NULL;
26-
bigCharPositions[i] = 0;
26+
(*bigCharPositions)[i] = 0;
2727
}
2828
buffer++;
2929
charArr++;
3030
}
3131
}
3232

33-
void vGetSpeedChars(uint8_t *charArr[4], float *speed, uint8_t *bigCharPositions) {
33+
void vGetSpeedChars(uint8_t *charArr[4], float *speed, uint8_t (*bigCharPositions)[6]) {
3434
// create buffer for converted float
3535
char buffer[10];
3636
// prevent overflow
@@ -43,26 +43,26 @@ void vGetSpeedChars(uint8_t *charArr[4], float *speed, uint8_t *bigCharPositions
4343
float tempFrac = *speed - speedInt;
4444
uint8_t fraction = (tempFrac * 10);
4545
// pad str with 0 if speed lower than 10
46-
if(speedInt < 10) {
47-
snprintf(buffer, 10, "0%d.%d", speedInt, fraction);
46+
if (speedInt < 10) {
47+
snprintf(buffer, 10, "0%d.%d", speedInt, fraction);
4848
} else {
4949
snprintf(buffer, 10, "%d.%d", speedInt, fraction);
5050
}
51-
fillCharsFromBuffer(charArr, buffer, 4, bigCharPositions);
51+
fillCharsFromBuffer(charArr, buffer, 4, &bigCharPositions);
5252
}
5353

54-
void vGetDistanceChars(uint8_t *charArr[6], float *distance, uint8_t *bigCharPositions) {
54+
void vGetDistanceChars(uint8_t *charArr[6], float *distance, uint8_t (*bigCharPositions)[6]) {
5555
char buffer[10];
5656
// @TODO handle distance > 999.9
5757
// @TODO handle distance > 99.99
5858
// convert float to int dot int
5959
uint8_t distanceInt = *distance;
6060
float tempFrac = *distance - distanceInt;
6161
uint8_t fraction = (tempFrac * 100);
62-
if(fraction < 10) {
62+
if (fraction < 10) {
6363
snprintf(buffer, 10, "%d.0%d", distanceInt, fraction);
6464
} else {
6565
snprintf(buffer, 10, "%d.%d", distanceInt, fraction);
6666
}
67-
fillCharsFromBuffer(charArr, buffer, 10, bigCharPositions);
67+
fillCharsFromBuffer(charArr, buffer, 10, &bigCharPositions);
6868
}

main/Tasks/screen_pcd8544/pcd8544_font_utils.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
#define TASKS_SCREEN_PCD8544_PCD8544_FONT_UTILS_H
33

44
#include <pcd8544_font16x24.h>
5-
#include "../../utils/macros.h"
65
#include <stdio.h>
76
#include <stdlib.h>
87

8+
#include "../../utils/macros.h"
9+
910
/**
1011
* @brief convert bike speed from float to included font char array
1112
* @param charRowsArr pointer to empty array, which will be filled with next chars row number
1213
* @return pointer to array of binary characters
1314
* */
14-
void vGetSpeedChars(uint8_t *charArr[4], float *value, uint8_t charRowsArr[6]);
15+
void vGetSpeedChars(uint8_t *charArr[4], float *speed, uint8_t (*bigCharPositions)[6]);
1516

1617
/**
1718
* @brief convert distance measured from float to included font char array
1819
* @param charRowsArr pointer to empty array, which will be filled with next chars row number
1920
* @return pointer to array of binary characters
2021
* */
21-
void vGetDistanceChars(uint8_t *charArr[4], float *distance, uint8_t charRowsArr[6]);
22+
void vGetDistanceChars(uint8_t *charArr[6], float *distance, uint8_t (*bigCharPositions)[6]);
2223

2324
#endif

0 commit comments

Comments
 (0)