Skip to content

Commit f7c79a2

Browse files
Merge pull request #15 from MuonPi/feature/i2c
feature/i2c
2 parents bd0c950 + f4ceaed commit f7c79a2

Some content is hidden

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

64 files changed

+2879
-3076
lines changed

.github/workflows/check-clang-format.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ jobs:
2525

2626
- name: clang-format
2727
run: cmake --build ${{github.workspace}}/build --target clangformat
28-
28+
2929
- name: show-changed-files
3030
run: git status
31-
31+
3232
- name: show-changes
3333
run: git diff
34-
34+
3535
- name: check-changes
3636
run: bash -c '[ -z "$(git status --porcelain=v1 2>/dev/null)" ]'

cmake/targets/core.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ set(CORE_HEADER_FILES
3030
"${PROJECT_HEADER_DIR}/muonpi/supervision/resource.h"
3131
"${PROJECT_HEADER_DIR}/muonpi/global.h"
3232
"${PROJECT_HEADER_DIR}/muonpi/types.h"
33+
"${PROJECT_HEADER_DIR}/muonpi/concepts.h"
34+
"${PROJECT_HEADER_DIR}/muonpi/range.h"
3335
)
3436

3537

cmake/targets/detector.cmake

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,19 @@ set(DETECTOR_SOURCE_FILES
44
"${PROJECT_SRC_DIR}/gpio_handler.cpp"
55
"${PROJECT_SRC_DIR}/serial/i2cdevice.cpp"
66
"${PROJECT_SRC_DIR}/serial/i2cbus.cpp"
7-
"${PROJECT_SRC_DIR}/serial/i2cdevices/lm75.cpp"
8-
"${PROJECT_SRC_DIR}/serial/i2cdevices/mic184.cpp"
9-
"${PROJECT_SRC_DIR}/serial/i2cdevices/ads1115.cpp"
10-
"${PROJECT_SRC_DIR}/serial/i2cdevices/mcp4728.cpp"
11-
"${PROJECT_SRC_DIR}/serial/i2cdevices/eeprom24aa02.cpp"
7+
"${PROJECT_SRC_DIR}/serial/i2cdevices/generalcall.cpp"
128
)
139

1410
set(DETECTOR_HEADER_FILES
11+
"${PROJECT_HEADER_DIR}/muonpi/addressrange.h"
12+
"${PROJECT_HEADER_DIR}/muonpi/multiaddressrange.h"
1513
"${PROJECT_HEADER_DIR}/muonpi/gpio_handler.h"
1614
"${PROJECT_HEADER_DIR}/muonpi/serial/i2cdevice.h"
15+
"${PROJECT_HEADER_DIR}/muonpi/serial/i2cdefinitions.h"
1716
"${PROJECT_HEADER_DIR}/muonpi/serial/i2cbus.h"
18-
"${PROJECT_HEADER_DIR}/muonpi/serial/i2cdevices.h"
19-
"${PROJECT_HEADER_DIR}/muonpi/serial/i2cdevices/lm75.h"
20-
"${PROJECT_HEADER_DIR}/muonpi/serial/i2cdevices/mic184.h"
21-
"${PROJECT_HEADER_DIR}/muonpi/serial/i2cdevices/ads1115.h"
22-
"${PROJECT_HEADER_DIR}/muonpi/serial/i2cdevices/mcp4728.h"
23-
"${PROJECT_HEADER_DIR}/muonpi/serial/i2cdevices/eeprom24aa02.h"
24-
"${PROJECT_HEADER_DIR}/muonpi/serial/i2cdevices/io_extender.h"
25-
"${PROJECT_HEADER_DIR}/muonpi/serial/i2cdevices/pca9536.h"
26-
"${PROJECT_HEADER_DIR}/muonpi/serial/i2cdevices/pca9554.h"
17+
"${PROJECT_HEADER_DIR}/muonpi/serial/i2ceeprom.h"
18+
"${PROJECT_HEADER_DIR}/muonpi/serial/i2cdevices/generalcall.h"
2719
)
28-
2920
if (NOT LIBMUONPI_FORMAT_ONLY)
3021
if (LIBMUONPI_BUILD_DETECTOR) # libraries specific to the Detector library
3122
find_library(LIBGPIOD gpiod REQUIRED)

config/config.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,41 @@
66
#include <string>
77

88
#ifdef _MSC_VER
9-
// Microsoft
10-
#define EXPORT __declspec(dllexport)
11-
#define IMPORT __declspec(dllimport)
9+
// Microsoft
10+
#define EXPORT __declspec(dllexport)
11+
#define IMPORT __declspec(dllimport)
1212
#elif defined(__GNUC__)
13-
// GCC
14-
#define EXPORT __attribute__((visibility("default")))
15-
#define IMPORT
16-
#define HIDDEN __attribute__((visibility("hidden")))
13+
// GCC
14+
#define EXPORT __attribute__((visibility("default")))
15+
#define IMPORT
16+
#define HIDDEN __attribute__((visibility("hidden")))
1717
#else
18-
// do nothing and hope for the best?
19-
#define EXPORT
20-
#define IMPORT
21-
#pragma warning Unknown dynamic link import/export semantics.
18+
// do nothing and hope for the best?
19+
#define EXPORT
20+
#define IMPORT
21+
#pragma warning Unknown dynamic link import / export semantics.
2222
#endif
2323

2424
#cmakedefine LIBMUONPI_COMPILING
2525

2626
#ifdef LIBMUONPI_COMPILING
27-
# define LIBMUONPI_PUBLIC EXPORT
27+
#define LIBMUONPI_PUBLIC EXPORT
2828
#else
29-
# define LIBMUONPI_PUBLIC IMPORT
29+
#define LIBMUONPI_PUBLIC IMPORT
3030
#endif
3131

3232
#define BOOST_ENABLE_ASSERT_DEBUG_HANDLER
3333

3434
namespace muonpi::Version::libmuonpi {
35-
constexpr int major { @PROJECT_VERSION_MAJOR@ };
36-
constexpr int minor { @PROJECT_VERSION_MINOR@ };
37-
constexpr int patch { @PROJECT_VERSION_PATCH@ };
38-
constexpr const char* additional { "@PROJECT_VERSION_ADDITIONAL@" };
35+
// clang-format off
36+
constexpr int major {@PROJECT_VERSION_MAJOR@};
37+
constexpr int minor {@PROJECT_VERSION_MINOR@};
38+
constexpr int patch {@PROJECT_VERSION_PATCH@};
39+
constexpr const char* additional {"@PROJECT_VERSION_ADDITIONAL@"};
40+
// clang-format on
3941

4042
[[nodiscard]] auto string() -> std::string;
4143

4244
} // namespace muonpi::Version::libmuonpi
4345

44-
4546
#endif // MUONPI_GLOBAL_H

examples/config/src/main.cpp

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
1+
#include <iostream>
12
#include <muonpi/configuration.h>
23
#include <muonpi/log.h>
34

4-
#include <iostream>
5-
6-
auto main(int argc, const char* argv[]) -> int
7-
{
8-
muonpi::log::system::setup(muonpi::log::Level::Info, [](int c){exit(c);}, std::cerr);
5+
auto main(int argc, const char* argv[]) -> int {
6+
muonpi::log::system::setup(
7+
muonpi::log::Level::Info,
8+
[](int c) { exit(c); },
9+
std::cerr);
910

10-
muonpi::config config{};
11+
muonpi::config config {};
1112

1213
auto cmd_options = config.setup("Commandline options");
1314
cmd_options.add_option("test,t", "This is just a test!");
14-
cmd_options.add_option("var,v", boost::program_options::value<std::string>(), "This is also just a test!");
15-
cmd_options.add_option("int,i", boost::program_options::value<int>()->required(), "This is also just a test!");
15+
cmd_options.add_option("var,v",
16+
boost::program_options::value<std::string>(),
17+
"This is also just a test!");
18+
cmd_options.add_option("int,i",
19+
boost::program_options::value<int>()->required(),
20+
"This is also just a test!");
1621
cmd_options.commit(argc, argv);
1722

18-
std::cout<<cmd_options;
19-
23+
std::cout << cmd_options;
2024

2125
auto file_options = config.setup("Commandline options");
22-
file_options.add_option("ftest", boost::program_options::value<std::string>(), "This is just a test!");
23-
file_options.add_option("fvar", boost::program_options::value<std::string>(), "This is also just a test!");
24-
file_options.add_option("fint", boost::program_options::value<int>()->required(), "This is also just a test!");
26+
file_options.add_option("ftest",
27+
boost::program_options::value<std::string>(),
28+
"This is just a test!");
29+
file_options.add_option("fvar",
30+
boost::program_options::value<std::string>(),
31+
"This is also just a test!");
32+
file_options.add_option("fint",
33+
boost::program_options::value<int>()->required(),
34+
"This is also just a test!");
2535
file_options.commit("example.cfg");
2636

27-
std::cout<<file_options;
37+
std::cout << file_options;
2838

2939
if (config.is_set("var")) {
30-
std::cout<<"option var: "<<config.get<std::string>("var")<<'\n';
40+
std::cout << "option var: " << config.get<std::string>("var") << '\n';
3141
}
32-
std::cout<<"option int: "<<config.get<int>("int")<<'\n';
42+
std::cout << "option int: " << config.get<int>("int") << '\n';
3343
}

examples/gpiod/src/main.cpp

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,59 @@
1+
#include <iostream>
12
#include <muonpi/gpio_handler.h>
23
#include <muonpi/log.h>
34

4-
#include <iostream>
5-
6-
auto main() -> int
7-
{
8-
muonpi::log::system::setup(muonpi::log::Level::Info, [](int c){exit(c);}, std::cerr);
9-
5+
auto main() -> int {
6+
muonpi::log::system::setup(
7+
muonpi::log::Level::Info,
8+
[](int c) { exit(c); },
9+
std::cerr);
1010

11-
muonpi::gpio_handler gpio{"/dev/gpiochip0", "muonpi"};
11+
muonpi::gpio_handler gpio {"/dev/gpiochip0", "muonpi"};
1212

1313
auto chip = gpio.get_chip_info();
1414

15-
std::cout
16-
<<"chip name: "<<chip.name
17-
<<"\nchip label: "<<chip.label
18-
<<"\nchip num lines: "<<chip.num_lines
19-
<<"\nlines:\n";
20-
unsigned int gpio_index { 0 };
21-
for (const auto& line: chip.lines) {
15+
std::cout << "chip name: " << chip.name << "\nchip label: " << chip.label
16+
<< "\nchip num lines: " << chip.num_lines << "\nlines:\n";
17+
unsigned int gpio_index {0};
18+
for (const auto& line : chip.lines) {
2219
std::cout << gpio_index++ << "\t: " << line.name << " " << line.consumer << "\n";
2320
}
24-
std::cout<<'\n';
21+
std::cout << '\n';
2522

26-
auto led_set_fn { gpio.set_pin_output( 19, muonpi::gpio::state_t{muonpi::gpio::state_t::Low}, muonpi::gpio::bias_t::OpenSource ) };
27-
auto gpio_read_fn { gpio.get_pin_input( 23, muonpi::gpio::bias_t::Disabled ) };
23+
auto led_set_fn {gpio.set_pin_output(19,
24+
muonpi::gpio::state_t {muonpi::gpio::state_t::Low},
25+
muonpi::gpio::bias_t::OpenSource)};
26+
auto gpio_read_fn {gpio.get_pin_input(23, muonpi::gpio::bias_t::Disabled)};
2827

2928
muonpi::gpio::pins_t pins {
30-
muonpi::gpio::pin_setting_t{5, muonpi::gpio::edge_t::Falling, muonpi::gpio::bias_t::Disabled},
31-
muonpi::gpio::pin_setting_t{27, muonpi::gpio::edge_t::Rising, muonpi::gpio::bias_t::Disabled},
29+
muonpi::gpio::pin_setting_t {5,
30+
muonpi::gpio::edge_t::Falling,
31+
muonpi::gpio::bias_t::Disabled},
32+
muonpi::gpio::pin_setting_t {27,
33+
muonpi::gpio::edge_t::Rising,
34+
muonpi::gpio::bias_t::Disabled},
3235
};
3336

34-
auto callback { [&](muonpi::gpio::event_t evt){
35-
std::cout
36-
<<evt.pin
37-
<<": "<<((evt.edge==muonpi::gpio::edge_t::Rising)?"Rising":"Falling")
38-
<<": "<<std::chrono::duration_cast<std::chrono::microseconds>(evt.time.time_since_epoch()).count()<<"\n";
37+
auto callback {[&](muonpi::gpio::event_t evt) {
38+
std::cout << evt.pin << ": "
39+
<< ((evt.edge == muonpi::gpio::edge_t::Rising) ? "Rising" : "Falling") << ": "
40+
<< std::chrono::duration_cast<std::chrono::microseconds>(
41+
evt.time.time_since_epoch())
42+
.count()
43+
<< "\n";
3944
// read state of the pin with the provided lambda function
4045
muonpi::gpio::state_t state = gpio_read_fn();
4146
// set state of other pin with this state, but invert
4247
bool ok = led_set_fn(!state);
4348
if (!ok) {
44-
std::cout<<" error setting LED\n";
49+
std::cout << " error setting LED\n";
4550
}
46-
} };
51+
}};
4752

48-
if (gpio.set_pin_interrupt(pins, callback))
49-
{
50-
std::cout<<"success.\n";
53+
if (gpio.set_pin_interrupt(pins, callback)) {
54+
std::cout << "success.\n";
5155
} else {
52-
std::cout<<"fail\n";
56+
std::cout << "fail\n";
5357
}
5458

5559
gpio.join();

examples/http-request/src/main.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1+
#include <iostream>
12
#include <muonpi/http_request.h>
23
#include <muonpi/log.h>
34

4-
#include <iostream>
5-
6-
auto main() -> int
7-
{
5+
auto main() -> int {
86
muonpi::log::system::setup(muonpi::log::Level::Info);
97

108
muonpi::http::destination_t config {};
11-
config.host = "localhost";
12-
config.port = 8000;
9+
config.host = "localhost";
10+
config.port = 8000;
1311
config.target = "/hello";
1412
config.method = muonpi::http::http_verb::get;
1513

16-
1714
std::cout << muonpi::http::http_request(config, "hello.") << '\n';
1815
}

examples/http/src/main.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,41 @@
1-
#include <muonpi/http_server.h>
1+
#include <iostream>
22
#include <muonpi/http_response.h>
3+
#include <muonpi/http_server.h>
34
#include <muonpi/log.h>
45

5-
#include <iostream>
6-
7-
auto main() -> int
8-
{
6+
auto main() -> int {
97
muonpi::log::system::setup(muonpi::log::Level::Info);
108

119
muonpi::http::http_server::configuration config {};
1210
config.address = "0.0.0.0";
13-
config.port = 8000;
14-
config.ssl = false;
11+
config.port = 8000;
12+
config.ssl = false;
1513

16-
muonpi::http::http_server service{config};
14+
muonpi::http::http_server service {config};
1715

1816
muonpi::http::path_handler handler1 {};
19-
handler1.matches = [](std::string_view path) {return path == "hello";};
20-
handler1.handle = [](muonpi::http::request_type& req, const std::queue<std::string>& /*unused*/) -> muonpi::http::response_type {
21-
std::cout<<"Got request for /hello\n"<<std::flush;
17+
handler1.matches = [](std::string_view path) { return path == "hello"; };
18+
handler1.handle = [](muonpi::http::request_type& req,
19+
const std::queue<std::string>& /*unused*/) -> muonpi::http::response_type {
20+
std::cout << "Got request for /hello\n" << std::flush;
2221
return muonpi::http::http_response<muonpi::http::http_status::ok>(req)("Hello!");
2322
};
2423

2524
service.add_handler(handler1);
2625

2726
muonpi::http::path_handler handler2 {};
28-
handler2.matches = [](std::string_view path) {return path == "bye";};
29-
handler2.handle = [](muonpi::http::request_type& req, const std::queue<std::string>& /*unused*/) -> muonpi::http::response_type {
30-
std::cout<<"Got request for /bye\n"<<std::flush;
27+
handler2.matches = [](std::string_view path) { return path == "bye"; };
28+
handler2.handle = [](muonpi::http::request_type& req,
29+
const std::queue<std::string>& /*unused*/) -> muonpi::http::response_type {
30+
std::cout << "Got request for /bye\n" << std::flush;
3131
return muonpi::http::http_response<muonpi::http::http_status::ok>(req)("Bye!");
3232
};
3333

3434
muonpi::http::path_handler handler3 {};
35-
handler3.matches = [](std::string_view path) {return path == "bye";};
36-
handler3.handle = [](muonpi::http::request_type& req, const std::queue<std::string>& /*unused*/) -> muonpi::http::response_type {
37-
std::cout<<"Got request for /bye/bye\n"<<std::flush;
35+
handler3.matches = [](std::string_view path) { return path == "bye"; };
36+
handler3.handle = [](muonpi::http::request_type& req,
37+
const std::queue<std::string>& /*unused*/) -> muonpi::http::response_type {
38+
std::cout << "Got request for /bye/bye\n" << std::flush;
3839
return muonpi::http::http_response<muonpi::http::http_status::ok>(req)("Bye-Bye!");
3940
};
4041

0 commit comments

Comments
 (0)