Skip to content

Commit 83e47b7

Browse files
committed
start commenting
1 parent 4a6b44d commit 83e47b7

File tree

6 files changed

+101
-15
lines changed

6 files changed

+101
-15
lines changed

components/battery/battery.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ static adc_oneshot_unit_handle_t adc_handle;
1818
static adc_cali_handle_t adc_cal_handle = NULL;
1919
static bool adc_calibrated = false;
2020
static int measurementCount = 0;
21-
static int sumVoltage = 0; //Voltage in mV
21+
static int sumVoltage = 0; //voltage in mV
2222

2323
static bool adc_calibration(adc_unit_t unit, adc_atten_t atten, adc_cali_handle_t *out_handle);
2424
static int32_t getVoltage();
2525

2626

27-
//determine the esp ADC reference voltage which is around 1100 mV
27+
/**
28+
* determine the esp ADC reference voltage which is around 1100 mV
29+
*/
2830
static bool adc_calibration(adc_unit_t unit, adc_atten_t atten, adc_cali_handle_t *return_handle){
2931
adc_cali_handle_t handle = NULL;
3032
esp_err_t ret = ESP_FAIL;
@@ -47,18 +49,19 @@ static bool adc_calibration(adc_unit_t unit, adc_atten_t atten, adc_cali_handle_
4749
}
4850

4951
void initBatteryRead(){
50-
//adc init
52+
//ADC init
5153
adc_oneshot_unit_init_cfg_t init_config = {
5254
.unit_id = ADC_UNIT_1,
5355
.ulp_mode = ADC_ULP_MODE_DISABLE,
5456
};
5557

5658
ESP_ERROR_CHECK(adc_oneshot_new_unit(&init_config, &adc_handle));
5759

58-
//adc configuration
59-
//wenn .atten auf 0db Dämpfung gesetzt ist, ist der mögliche Wertebereich von 0 bis 1.1V
60-
//bei .atten 12db wird der Wertebereich von 0 bis theoretisch 3.9V (3.55*1.1V) verwendet aber durch VDD auf 3.3V begrenzt
61-
//recommended range between 150 to 2450 mV at 12db
60+
/*ADC configuration
61+
* if .atten is set to 0db attenuation, the possible value range is from 0 to 1.1V
62+
* at .atten 12db the value range from 0 to theoretically 3.9V (3.55*1.1V) is used but limited by VDD to 3.3V
63+
* recommended range between 150 to 2450 mV at 12db
64+
*/
6265
adc_oneshot_chan_cfg_t config = {
6366
.bitwidth = ADC_BITWIDTH_12,
6467
.atten = ADC_ATTEN_DB_11,
@@ -70,7 +73,9 @@ void initBatteryRead(){
7073
adc_calibrated = adc_calibration(ADC_UNIT_1, ADC_ATTEN_DB_11, &adc_cal_handle);
7174
}
7275

73-
//Voltage in mV
76+
/**
77+
* determines the applied voltage at the ADC. Either calibrated or raw.
78+
*/
7479
static int32_t getVoltage(){
7580
int raw_val, voltage;
7681
adc_oneshot_read(adc_handle, ADC_CHANNEL_4, &raw_val);
@@ -86,7 +91,10 @@ static int32_t getVoltage(){
8691
}
8792

8893
void battery_Timer_Event(TimerHandle_t ev){
89-
//https://esp32.com/viewtopic.php?t=1459
94+
/* If there is too much output, the ESP crashes
95+
* https://esp32.com/viewtopic.php?t=1459
96+
*/
97+
9098

9199
getVoltage();
92100
if(measurementCount < 10){
@@ -98,7 +106,7 @@ void battery_Timer_Event(TimerHandle_t ev){
98106
measurementCount = 0;
99107

100108
//battery range between 3.4 and 4.2V
101-
//r2/(r1+r2) = 0.755 akutell
109+
//r2/(r1+r2) = 0.755 with the used resistors
102110
//vmax_in = 4.2*0.755 = 3.171
103111
//vmin_in = 3.8*0.755 = 2.869
104112
//steps = (3171-2869)/100 = 302/100

components/battery/include/battery.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@
66
#include "freertos/FreeRTOS.h"
77
#include "freertos/timers.h"
88

9+
//global storage var of the battery percentage
910
extern uint8_t batteryPercentage;
1011

12+
/**
13+
* initialize the required ADC.
14+
*/
1115
void initBatteryRead();
16+
17+
/**
18+
* Timer event which determines a percentage value from the measured voltage.
19+
*
20+
* @param ev timer handle. Not used.
21+
*/
1222
void battery_Timer_Event(TimerHandle_t ev);
1323

1424
#endif

components/ble/gap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void bleAdvertise(void){
3535
struct ble_gap_adv_params adv_params;
3636
struct ble_hs_adv_fields fields;
3737
int rc;
38+
const char* name;
3839

3940
/*
4041
* Set the advertisement data included in our advertisements:
@@ -60,8 +61,9 @@ void bleAdvertise(void){
6061
fields.tx_pwr_lvl_is_present = 1;
6162
fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO;
6263

63-
fields.name = (uint8_t *)CONFIG_BT_NIMBLE_SVC_GAP_DEVICE_NAME;
64-
fields.name_len = strlen(CONFIG_BT_NIMBLE_SVC_GAP_DEVICE_NAME);
64+
name = ble_svc_gap_device_name();
65+
fields.name = (uint8_t *)name;
66+
fields.name_len = strlen(name);
6567
fields.name_is_complete = 1;
6668

6769
fields.appearance = ble_svc_gap_device_appearance();

components/button/button.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ void initButtons(){
3030
gpio_set_pull_mode(GPIO_NUM_25,GPIO_PULLUP_ONLY);
3131
}
3232

33+
/**
34+
* Interrupt Service Routine for the buttons
35+
*
36+
* @param arg enum of the pressedbutton
37+
*/
3338
static void IRAM_ATTR buttonISRHandler(void* arg)
3439
{
3540
BUTTON pressedButton = (BUTTON) arg;

components/button/include/button.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
#ifndef BUTTON_H
22
#define BUTTON_H
33

4+
/**
5+
* enum with the possible buttons
6+
*/
47
typedef enum BUTTON {
58
LEFTBUTTON,
69
RIGHTBUTTON,
710
} BUTTON;
811

12+
/**
13+
* setup the gpios for the buttons
14+
*/
915
void initButtons();
16+
17+
/**
18+
* Get the last value for a specific button. If there is no data for 30 seconds it will be aborted.
19+
*
20+
* @param selectedButton specify a specific button
21+
* @return High or Low for the button output
22+
*/
1023
int getButton(BUTTON *selectedButton);
24+
25+
/**
26+
* Clear the Queue with stored button states
27+
*/
1128
void clearStoredButtons();
1229

1330
#endif

components/ssd1306/include/ssd1306.h

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,66 @@
1+
/*credits: https://github.com/nopnop2002/esp-idf-ssd1306
2+
* http://robotcantalk.blogspot.com/2015/03/interfacing-arduino-with-ssd1306-driven.html
3+
*/
4+
15
#ifndef SSD1306_H
26
#define SSD1306_H
37

4-
//credits: https://github.com/nopnop2002/esp-idf-ssd1306
5-
// http://robotcantalk.blogspot.com/2015/03/interfacing-arduino-with-ssd1306-driven.html
6-
78
#include <stdint.h>
89
#include <stdbool.h>
910

1011
#define SSD1306_WIDTH 128
1112
#define SSD1306_HEIGHT 32
1213

14+
/**
15+
* setup the ssd1306 display
16+
*/
1317
void ssd1306_init();
18+
19+
/**
20+
* setup the I2C interface on the ESP
21+
*/
1422
void I2C_master_init();
23+
24+
/**
25+
* clear the memory of the selected pixels. Only on the ESP side.
26+
*/
1527
void ssd1306_clear();
28+
29+
/**
30+
* display the current stored pixel data on the ESP
31+
*/
1632
void ssd1306_display();
33+
34+
/**
35+
* Set a specific pixel in the pixel data. Axis origin is the left top.
36+
*
37+
* @param x x coord
38+
* @param y y coord
39+
* @param status enable or disable the bit
40+
*/
1741
void ssd1306_setPixel(uint8_t x, uint8_t y, bool status);
42+
43+
/**
44+
* Set a char at a specific position in the pixel data.
45+
*
46+
* @param c the character to be written
47+
* @param x x coord
48+
* @param y y coord
49+
*/
1850
void ssd1306_setChar(char c, uint8_t x, uint8_t y);
51+
52+
/**
53+
* set a string at a specific position in the pixel data.
54+
*
55+
* @param str The string to be written
56+
* @param x x coord
57+
* @param y y coord
58+
*/
1959
void ssd1306_setString(const char* str, uint8_t x, uint8_t y);
60+
61+
/**
62+
* set an image in the whole pixel data with a connected icon.
63+
*/
2064
void ssd1306_setConnectedImage();
2165

2266
#endif

0 commit comments

Comments
 (0)