-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathBMP280_exec.hpp
97 lines (85 loc) · 2.77 KB
/
BMP280_exec.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#pragma once
//=====================================================================//
/*! @file
@brief BMP280 exec クラス
@author 平松邦仁 ([email protected])
@copyright Copyright (C) 2021 Kunihito Hiramatsu @n
Released under the MIT license @n
https://github.com/hirakuni45/RX/blob/master/LICENSE
*/
//=====================================================================//
#include "chip/BMP280.hpp"
namespace BMP280 {
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
/*!
@brief BMP280 デバイス操作
@param[in] I2C_IO I2C I/O クラス
@param[in] CMD_LIN コマンドライン入力クラス
*/
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
template <class I2C_IO, class CMD_LIN>
class exec {
typedef chip::BMP280<I2C_IO> BMP280;
BMP280 BMP280_;
CMD_LIN& cmd_;
public:
//-----------------------------------------------------------------//
/*!
@brief コンストラクター
@param[in] i2c_io I2C I/O クラス
@param[in] cmd_ コマンドライン入力クラス
*/
//-----------------------------------------------------------------//
exec(I2C_IO& i2c_io, CMD_LIN& cmd) : BMP280_(i2c_io), cmd_(cmd) { }
//-----------------------------------------------------------------//
/*!
@brief BMP280 開始
@param[in] adr I2C address
@return エラー無ければ「true」
*/
//-----------------------------------------------------------------//
bool start(uint8_t adr)
{
if(!BMP280_.start(adr)) {
utils::format("BMP280 Start fail...\n");
return false;
}
return true;
}
//-----------------------------------------------------------------//
/*!
@brief AS5600 サービス
*/
//-----------------------------------------------------------------//
void service() noexcept
{
}
//-----------------------------------------------------------------//
/*!
@brief BMP280 コマンド解析
*/
//-----------------------------------------------------------------//
void analize() noexcept
{
auto cmdn = cmd_.get_words();
if(cmdn == 0) return;
if(cmdn >= 1 && cmd_.cmp_word(0, "--help")) {
utils::format("BMP280 operations\n");
utils::format(" list\n");
utils::format(" --help\n");
utils::format("\n");
} else if(cmdn >= 1 && cmd_.cmp_word(0, "list")) {
auto t = BMP280_.get_temperature();
utils::format("Temperature: %5.2f C\n") % (static_cast<float>(t) / 100.0f);
auto p = BMP280_.get_pressure();
utils::format("Pressure: %7.2f hPa\n") % (static_cast<float>(p) / 100.0f);
auto a = BMP280_.get_altitude();
utils::format("Altitude: %7.2f m\n") % a;
} else {
char tmp[256];
cmd_.get_word(0, tmp, sizeof(tmp));
utils::format("BMP280 command error: '%s'\n") % tmp;
}
}
};
}