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 bme280
26 * @author Jason Duffy
27 * @date 22nd June 2022
28 * @brief Example main routine demonstrating the BME280 sensor.
29 * @bug No known bugs.
30 */
31
32#include <util/delay.h>
33
34#include "bme280.h"
35#include "log_system.h"
36
37int16_t temperature = 0;
38uint16_t humidity = 0;
39
40int8_t neg_val = -43;
41int8_t pos_val = 56;
42int8_t zer_val = 0;
43
44log_system_config_t log_system_main =
45{
46 .p_system_tag = "Main",
47 .file_log_level = DEBUG,
48};
49
50
51
52int main()
53{
54 // Initialisations & Setup
59
60 // Superloop
61 while (1)
62 {
63 temperature = bme280_get_temperature();
64 humidity = bme280_get_humidity();
65 /*
66 log_message_with_16bit_unsigned_val(&log_system_main,
67 INFO,
68 "Temperature: ",
69 temperature,
70 DECIMAL);
71
72 log_message_with_16bit_unsigned_val(&log_system_main,
73 INFO,
74 "Humidity: ",
75 humidity,
76 DECIMAL);
77 */
78 _delay_ms(1000);
79 log_message_with_8bit_signed_val(&log_system_main,
80 INFO,
81 "Signed variable: ",
82 neg_val,
83 DECIMAL);
84
85 log_message_with_8bit_signed_val(&log_system_main,
86 INFO,
87 "Signed variable: ",
88 pos_val,
89 DECIMAL);
90
91 log_message_with_8bit_signed_val(&log_system_main,
92 INFO,
93 "Signed variable: ",
94 zer_val,
95 DECIMAL);
96 }
97
98 return 0;
99}
uint16_t bme280_get_humidity(void)
Fetches the latest humidity data from the sensor, compensates and formats the data as RH * 100.
Definition: bme280.c:207
void init_bme280(void)
Initialise the device ready for measurements to be taken.
Definition: bme280.c:125
int16_t bme280_get_temperature(void)
Fetches the latest temperature data from the sensor, compensates and formats the data in degrees Celc...
Definition: bme280.c:164
void log_global_on(void)
Turns logging system on globally.
Definition: log_system.c:133
void init_log_system(void)
Initialisation routine - call this function once at startup before using other functions.
Definition: log_system.c:46
void log_set_global_max_output_level(log_type_t level)
Sets maximum output level of logging required, has global effect.
Definition: log_system.c:229
int main()
Main routine to be executed on the MCU.
Definition: main.c:45
void log_message_with_8bit_signed_val(log_system_config_t *p_config, log_type_t level, const char *msg, int8_t val, format_type_t format)
Sends a string, followed by an 8 bit value.
Definition: log_system.c:118
Driver file providing logging functionality over USART, to print debug messages and values to a temin...
Config object, to be instantiated in each file the log system is to be used, then pass it's address i...
Definition: log_system.h:59