AVRly - AVR Development Resources
main.c
Go to the documentation of this file.
1/******************************************************************************
2 @copyright Copyright © 2022 by Jason Duffy.
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21******************************************************************************/
22
23/**
24 * @file main.c
25 * @ingroup ccs811
26 * @author Jason Duffy
27 * @date 15th March 2022
28 * @brief Example main routine to demonstrate taking readings using the CCS811
29 * gas sensor.
30 * @bug No known bugs.
31 * @see
32 */
33
34#include <util/delay.h>
35#include "ccs811.h"
36#include "log_system.h"
37
38static const char *p_system_tag = "MAIN";
39
40static uint16_t eco2 = 0;
41static uint16_t etvoc = 0;
42
43ccs811_config_t ccs811_config =
44{
45 .drive_mode = drive_mode_1sec,
46 .wake_pin_enabled = true,
47 .interrupt_dataready = false,
48 .interrupt_threshold = false,
49};
50
51int main()
52{
53 // Setup
55 uint8_t error = init_ccs811(&ccs811_config);
56 log_message_with_dec_val(p_system_tag, ERROR,
57 "CCS81 init return code: ", error);
58 // Loop forever
59 for(;;)
60 {
62 {
63 eco2 = ccs811_get_eco2_level();
64 log_message_with_16bit_dec_val(p_system_tag, DEBUG, "eCo2 Level: ", eco2);
65
66 etvoc = ccs811_get_etvoc_level();
67 log_message_with_16bit_dec_val(p_system_tag, DEBUG, "eTVOC Level: ", etvoc);
68 }
69 }
70}
uint16_t ccs811_get_etvoc_level(void)
Read eTVOC (equivalent total volatile organic compounds) level from sensor.
Definition: ccs811.c:189
uint16_t ccs811_get_eco2_level(void)
Read eCO2 (equivalent carbon dioxide) level from sensor.
Definition: ccs811.c:182
uint8_t init_ccs811(ccs811_config_t *p_config)
Initialisation routine (run once at startup).
Definition: ccs811.c:133
bool ccs811_data_ready_check(void)
Read the status register and check if the data ready flag is set.
Definition: ccs811.c:200
Driver for the CCS811 gas sensor .
void init_log_system(void)
Initialisation routine - call this function once at startup before using other functions.
Definition: log_system.c:46
int main()
Main routine to be executed on the MCU.
Definition: main.c:45
Driver file providing logging functionality over USART, to print debug messages and values to a temin...
Config object, to be instantiated and values assigned to members before passing the object address in...
Definition: ccs811.h:87