-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathmain.cpp
More file actions
62 lines (55 loc) · 1.63 KB
/
main.cpp
File metadata and controls
62 lines (55 loc) · 1.63 KB
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
/*
* Copyright (c) 2023, Alexander Solovets
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------
#include <modm/architecture/driver/atomic/flag.hpp>
#include <modm/board.hpp>
#include <modm/debug/logger.hpp>
#include <modm/driver/inertial/qmc5883l.hpp>
using namespace Board;
using namespace std::chrono_literals;
using Compass = modm::Qmc5883l<I2cMaster>;
Compass::Data data;
Compass compass(data);
modm::atomic::Flag dataReady(true);
MODM_ISR(INT2)
{
dataReady.set();
}
int
main()
{
Board::initialize();
// DRDY pin must be connected to Board pin 19 (Port D2).
Board::D19::setInput(Gpio::InputType::PullUp);
Board::D19::setInputTrigger(Gpio::InputTrigger::RisingEdge);
Board::D19::enableExternalInterrupt();
compass.initialize();
auto mode = Compass::Mode_t(Compass::Mode::Continious);
auto rate = Compass::OutputDataRate_t(Compass::OutputDataRate::_10Hz);
auto scale = Compass::FullScale_t(Compass::FullScale::_8G);
compass.configure(mode, rate | scale);
for (;;)
{
if (dataReady.testAndSet(false))
{
if (compass.readData())
{
MODM_LOG_INFO << "X:" << compass.x() << " Y: " << compass.y()
<< " Z: " << compass.z()
<< " OVL: " << (compass.status() & Compass::Status::OVL)
<< modm::endl;
} else
{
MODM_LOG_INFO << "readData(): Error: " << uint8_t(I2cMaster::getErrorState())
<< modm::endl;
}
}
}
}