Skip to content

Commit bcaa0dc

Browse files
authored
Merge pull request #3876 from SybexX/test4
test1
2 parents c320e4c + 15e9aa7 commit bcaa0dc

File tree

98 files changed

+12628
-10572
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+12628
-10572
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FILE(GLOB_RECURSE app_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.*)
22

33
idf_component_register(SRCS ${app_sources}
4-
INCLUDE_DIRS "."
4+
INCLUDE_DIRS "." "../../include"
55
REQUIRES jomjol_logfile)
66

77

code/components/jomjol_configfile/configFile.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ static const char *TAG = "CONFIG";
1212

1313
ConfigFile::ConfigFile(std::string filePath)
1414
{
15-
std::string config = FormatFileName(filePath);
16-
pFile = fopen(config.c_str(), "r");
15+
std::string config = FormatFileName(filePath);
16+
pFile = fopen(config.c_str(), "r");
1717
}
1818

1919
ConfigFile::~ConfigFile()
2020
{
21-
fclose(pFile);
21+
fclose(pFile);
2222
}
2323

2424
bool ConfigFile::isNewParagraph(std::string input)
@@ -30,18 +30,23 @@ bool ConfigFile::isNewParagraph(std::string input)
3030
return false;
3131
}
3232

33-
bool ConfigFile::GetNextParagraph(std::string& aktparamgraph, bool &disabled, bool &eof)
33+
bool ConfigFile::GetNextParagraph(std::string &aktparamgraph, bool &disabled, bool &eof)
3434
{
35-
while (getNextLine(&aktparamgraph, disabled, eof) && !isNewParagraph(aktparamgraph));
35+
while (getNextLine(&aktparamgraph, disabled, eof) && !isNewParagraph(aktparamgraph))
36+
{
37+
}
3638

3739
if (isNewParagraph(aktparamgraph))
40+
{
3841
return true;
42+
}
43+
3944
return false;
4045
}
4146

4247
bool ConfigFile::getNextLine(std::string *rt, bool &disabled, bool &eof)
4348
{
44-
eof = false;
49+
eof = false;
4550
char zw[1024] = "";
4651
if (pFile == NULL)
4752
{
@@ -74,13 +79,13 @@ bool ConfigFile::getNextLine(std::string *rt, bool &disabled, bool &eof)
7479
if (feof(pFile))
7580
{
7681
*rt = "";
77-
eof = true;
82+
eof = true;
7883
return false;
7984
}
8085
*rt = zw;
8186
*rt = trim(*rt);
8287
}
8388

84-
disabled = ((*rt)[0] == ';');
89+
disabled = ((*rt)[0] == ';');
8590
return true;
8691
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Unlicense OR CC0-1.0
5+
*/
6+
#include <string.h>
7+
#include "ds18b20.h"
8+
#include "esp_check.h"
9+
10+
static const char *TAG = "ds18b20";
11+
12+
esp_err_t ds18b20_trigger_temperature_conversion(onewire_bus_handle_t handle, const uint8_t *rom_number)
13+
{
14+
ESP_RETURN_ON_FALSE(handle, ESP_ERR_INVALID_ARG, TAG, "invalid 1-wire handle");
15+
16+
ESP_RETURN_ON_ERROR(onewire_bus_reset(handle), TAG, "error while resetting bus"); // reset bus and check if the device is present
17+
18+
uint8_t tx_buffer[10];
19+
uint8_t tx_buffer_size;
20+
21+
if (rom_number) { // specify rom id
22+
tx_buffer[0] = ONEWIRE_CMD_MATCH_ROM;
23+
tx_buffer[9] = DS18B20_CMD_CONVERT_TEMP;
24+
memcpy(&tx_buffer[1], rom_number, 8);
25+
tx_buffer_size = 10;
26+
} else { // skip rom id
27+
tx_buffer[0] = ONEWIRE_CMD_SKIP_ROM;
28+
tx_buffer[1] = DS18B20_CMD_CONVERT_TEMP;
29+
tx_buffer_size = 2;
30+
}
31+
32+
ESP_RETURN_ON_ERROR(onewire_bus_write_bytes(handle, tx_buffer, tx_buffer_size),
33+
TAG, "error while triggering temperature convert");
34+
35+
return ESP_OK;
36+
}
37+
38+
esp_err_t ds18b20_get_temperature(onewire_bus_handle_t handle, const uint8_t *rom_number, float *temperature)
39+
{
40+
ESP_RETURN_ON_FALSE(handle, ESP_ERR_INVALID_ARG, TAG, "invalid 1-wire handle");
41+
ESP_RETURN_ON_FALSE(temperature, ESP_ERR_INVALID_ARG, TAG, "invalid temperature pointer");
42+
43+
ESP_RETURN_ON_ERROR(onewire_bus_reset(handle), TAG, "error while resetting bus"); // reset bus and check if the device is present
44+
45+
ds18b20_scratchpad_t scratchpad;
46+
47+
uint8_t tx_buffer[10];
48+
uint8_t tx_buffer_size;
49+
50+
if (rom_number) { // specify rom id
51+
tx_buffer[0] = ONEWIRE_CMD_MATCH_ROM;
52+
tx_buffer[9] = DS18B20_CMD_READ_SCRATCHPAD;
53+
memcpy(&tx_buffer[1], rom_number, 8);
54+
tx_buffer_size = 10;
55+
} else {
56+
tx_buffer[0] = ONEWIRE_CMD_SKIP_ROM;
57+
tx_buffer[1] = DS18B20_CMD_READ_SCRATCHPAD;
58+
tx_buffer_size = 2;
59+
}
60+
61+
ESP_RETURN_ON_ERROR(onewire_bus_write_bytes(handle, tx_buffer, tx_buffer_size),
62+
TAG, "error while sending read scratchpad command");
63+
ESP_RETURN_ON_ERROR(onewire_bus_read_bytes(handle, (uint8_t *)&scratchpad, sizeof(scratchpad)),
64+
TAG, "error while reading scratchpad command");
65+
66+
ESP_RETURN_ON_FALSE(onewire_check_crc8((uint8_t *)&scratchpad, 8) == scratchpad.crc_value, ESP_ERR_INVALID_CRC,
67+
TAG, "crc error");
68+
69+
static const uint8_t lsb_mask[4] = { 0x07, 0x03, 0x01, 0x00 };
70+
uint8_t lsb_masked = scratchpad.temp_lsb & (~lsb_mask[scratchpad.configuration >> 5]); // mask bits not used in low resolution
71+
*temperature = (((int16_t)scratchpad.temp_msb << 8) | lsb_masked) / 16.0f;
72+
73+
return ESP_OK;
74+
}
75+
76+
esp_err_t ds18b20_set_resolution(onewire_bus_handle_t handle, const uint8_t *rom_number, ds18b20_resolution_t resolution)
77+
{
78+
ESP_RETURN_ON_FALSE(handle, ESP_ERR_INVALID_ARG, TAG, "invalid 1-wire handle");
79+
80+
ESP_RETURN_ON_ERROR(onewire_bus_reset(handle), TAG, "error while resetting bus"); // reset bus and check if the device is present
81+
82+
uint8_t tx_buffer[10];
83+
uint8_t tx_buffer_size;
84+
85+
if (rom_number) { // specify rom id
86+
tx_buffer[0] = ONEWIRE_CMD_MATCH_ROM;
87+
tx_buffer[9] = DS18B20_CMD_WRITE_SCRATCHPAD;
88+
memcpy(&tx_buffer[1], rom_number, 8);
89+
tx_buffer_size = 10;
90+
} else {
91+
tx_buffer[0] = ONEWIRE_CMD_SKIP_ROM;
92+
tx_buffer[1] = DS18B20_CMD_WRITE_SCRATCHPAD;
93+
tx_buffer_size = 2;
94+
}
95+
96+
ESP_RETURN_ON_ERROR(onewire_bus_write_bytes(handle, tx_buffer, tx_buffer_size),
97+
TAG, "error while sending read scratchpad command");
98+
99+
tx_buffer[0] = 0;
100+
tx_buffer[1] = 0;
101+
tx_buffer[2] = resolution;
102+
ESP_RETURN_ON_ERROR(onewire_bus_write_bytes(handle, tx_buffer, 3),
103+
TAG, "error while sending write scratchpad command");
104+
105+
return ESP_OK;
106+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Unlicense OR CC0-1.0
5+
*/
6+
#pragma once
7+
8+
#include "onewire_bus.h"
9+
10+
#define DS18B20_CMD_CONVERT_TEMP 0x44
11+
#define DS18B20_CMD_WRITE_SCRATCHPAD 0x4E
12+
#define DS18B20_CMD_READ_SCRATCHPAD 0xBE
13+
14+
/**
15+
* @brief Structure of DS18B20's scratchpad
16+
*
17+
*/
18+
typedef struct {
19+
uint8_t temp_lsb; /*!< lsb of temperature */
20+
uint8_t temp_msb; /*!< msb of temperature */
21+
uint8_t th_user1; /*!< th register or user byte 1 */
22+
uint8_t tl_user2; /*!< tl register or user byte 2 */
23+
uint8_t configuration; /*!< configuration register */
24+
uint8_t _reserved1;
25+
uint8_t _reserved2;
26+
uint8_t _reserved3;
27+
uint8_t crc_value; /*!< crc value of scratchpad data */
28+
} ds18b20_scratchpad_t;
29+
30+
/**
31+
* @brief Enumeration of DS18B20's resolution config
32+
*
33+
*/
34+
typedef enum {
35+
DS18B20_RESOLUTION_12B = 0x7F, /*!< 750ms convert time */
36+
DS18B20_RESOLUTION_11B = 0x5F, /*!< 375ms convert time */
37+
DS18B20_RESOLUTION_10B = 0x3F, /*!< 187.5ms convert time */
38+
DS18B20_RESOLUTION_9B = 0x1F, /*!< 93.75ms convert time */
39+
} ds18b20_resolution_t;
40+
41+
/**
42+
* @brief Trigger temperature conversion of DS18B20
43+
*
44+
* @param[in] handle 1-wire handle with DS18B20 on
45+
* @param[in] rom_number ROM number to specify which DS18B20 to send command, NULL to skip ROM
46+
* @return
47+
* - ESP_OK Trigger tempreture convertsion success.
48+
* - ESP_ERR_INVALID_ARG Invalid argument.
49+
* - ESP_ERR_NOT_FOUND There is no device present on 1-wire bus.
50+
*/
51+
esp_err_t ds18b20_trigger_temperature_conversion(onewire_bus_handle_t handle, const uint8_t *rom_number);
52+
53+
/**
54+
* @brief Get temperature from DS18B20
55+
*
56+
* @param[in] handle 1-wire handle with DS18B20 on
57+
* @param[in] rom_number ROM number to specify which DS18B20 to read from, NULL to skip ROM
58+
* @param[out] temperature result from DS18B20
59+
* @return
60+
* - ESP_OK Get tempreture from DS18B20 success.
61+
* - ESP_ERR_INVALID_ARG Invalid argument.
62+
* - ESP_ERR_NOT_FOUND There is no device present on 1-wire bus.
63+
* - ESP_ERR_INVALID_CRC CRC check failed.
64+
*/
65+
esp_err_t ds18b20_get_temperature(onewire_bus_handle_t handle, const uint8_t *rom_number, float *temperature);
66+
67+
/**
68+
* @brief Set DS18B20's temperation conversion resolution
69+
*
70+
* @param[in] handle 1-wire handle with DS18B20 on
71+
* @param[in] rom_number ROM number to specify which DS18B20 to read from, NULL to skip ROM
72+
* @param[in] resolution resolution of DS18B20's temperation conversion
73+
* @return
74+
* - ESP_OK Set DS18B20 resolution success.
75+
* - ESP_ERR_INVALID_ARG Invalid argument.
76+
* - ESP_ERR_NOT_FOUND There is no device present on 1-wire bus.
77+
*/
78+
esp_err_t ds18b20_set_resolution(onewire_bus_handle_t handle, const uint8_t *rom_number, ds18b20_resolution_t resolution);

0 commit comments

Comments
 (0)