Skip to content

Commit

Permalink
add ArrayPointer class
Browse files Browse the repository at this point in the history
  • Loading branch information
aldwinhermanudin committed Dec 19, 2023
1 parent 1b0a649 commit bd1a210
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/mbedos/test-bme688/source/bme688/BME688.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ BME688::ReturnCode BME688::SetBme68xConfigParallel( const bsec_bme_settings_t& b
shared_heater_dur = BSEC_TOTAL_HEAT_DUR - (GetMeasurementDuration(BME68X_PARALLEL_MODE) / INT64_C(1000));

// set heater profile
status = SetHeaterProfile( (uint16_t*) bsec_bme_conf.heater_temperature_profile,
(uint16_t*) bsec_bme_conf.heater_duration_profile,
status = SetHeaterProfile( ArrayPointer<uint16_t>((uint16_t*) bsec_bme_conf.heater_temperature_profile, sizeof(bsec_bme_conf.heater_temperature_profile)),
ArrayPointer<uint16_t>((uint16_t*) bsec_bme_conf.heater_duration_profile, sizeof(bsec_bme_conf.heater_duration_profile)),
shared_heater_dur,
bsec_bme_conf.heater_profile_len );
if( status != ReturnCode::kOk )
Expand Down Expand Up @@ -412,16 +412,16 @@ BME688::ReturnCode BME688::SetHeaterProfile( const uint16_t temp,
/**
* @brief Function to set the heater profile for Parallel mode
*/
BME688::ReturnCode BME688::SetHeaterProfile( uint16_t* const temp,
uint16_t* const mul,
BME688::ReturnCode BME688::SetHeaterProfile( const ArrayPointer<uint16_t>& temp,
const ArrayPointer<uint16_t>& mul,
const uint16_t shared_heater_dur,
const uint8_t profile_len )
{
bme68x_heatr_conf heater_conf
{
.enable = BME68X_ENABLE,
.heatr_temp_prof = temp,
.heatr_dur_prof = mul,
.heatr_temp_prof = temp.ptr,
.heatr_dur_prof = mul.ptr,
.profile_len = profile_len,
.shared_heatr_dur = shared_heater_dur
};
Expand Down
5 changes: 3 additions & 2 deletions src/mbedos/test-bme688/source/bme688/BME688.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "bsec_interface.h"
#include "bsec_datatypes.h"
#include "bme68x.h"
#include "ArrayPointer.h"

#define BME688_CHIP_ID_LOCATION 0xD0
#define BSEC_REQUESTED_VIRTUAL_SENSORS_NUMBER 4
Expand Down Expand Up @@ -99,8 +100,8 @@ class BME688{
ReturnCode SetOperationMode(const uint8_t op_mode);
ReturnCode SetHeaterProfile( const uint16_t temp,
const uint16_t dur );
ReturnCode SetHeaterProfile( uint16_t* const temp,
uint16_t* const mul,
ReturnCode SetHeaterProfile( const ArrayPointer<uint16_t>& temp,
const ArrayPointer<uint16_t>& mul,
const uint16_t sharedHeatrDur,
const uint8_t profileLen );
uint32_t GetMeasurementDuration(const uint8_t op_mode);
Expand Down
15 changes: 15 additions & 0 deletions src/mbedos/test-bme688/source/utils/ArrayPointer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef ARRAY_POINTER_H
#define ARRAY_POINTER_H

#include <cstdint>
#include <cstddef>

template <class T>
class ArrayPointer {
public:
T* const ptr;
const size_t size;
ArrayPointer(T * ptr, size_t size): ptr(ptr), size(size){}
};

#endif // ARRAY_POINTER_H
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __DEFER__H
#define __DEFER__H
#ifndef DEFER_H
#define DEFER_H

template <class T>
class Defer
Expand Down

0 comments on commit bd1a210

Please sign in to comment.