-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
73 lines (62 loc) · 2.21 KB
/
Copy pathmain.c
File metadata and controls
73 lines (62 loc) · 2.21 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
63
64
65
66
67
68
69
70
71
72
73
#include <stdio.h>
#include <stdbool.h>
#include "pico/stdlib.h"
#include "hardware/adc.h"
/* このファイルでヘッダー実装を有効化(1翻訳単位のみで定義する) */
#define IR_TEMP_RAW_IMPLEMENTATION
#include "infrared_temp_raw.h"
#define SUR_TEMP_PIN 26 /* GP26 = ADC0 */
#define OBJ_TEMP_PIN 27 /* GP27 = ADC1 */
/* true: 電圧も表示 / false: 温度のみ表示 */
static const bool kPrintVoltage = true;
/* ADCを10回平均して生データ(0..4095)を返す */
static uint16_t read_adc_avg(const uint adc_channel) {
uint32_t sum = 0;
for (int i = 0; i < 10; i++) {
adc_select_input(adc_channel);
sum += adc_read();
sleep_ms(10);
}
return (uint16_t)(sum / 10U);
}
int main(void) {
stdio_init_all();
adc_init();
adc_gpio_init(SUR_TEMP_PIN);
adc_gpio_init(OBJ_TEMP_PIN);
sleep_ms(2000);
ir_temp_config_t cfg = ir_temp_default_config();
/* 必要に応じて現場キャリブレーション値だけ調整 */
cfg.temp_calibration_c = 0.0f;
cfg.object_calibration_c = 0.0f;
while (1) {
uint16_t sur_raw = read_adc_avg(0);
uint16_t obj_raw = read_adc_avg(1);
ir_temp_result_t result;
ir_temp_voltage_t voltages;
bool ok = ir_temp(sur_raw, obj_raw, &cfg, &result);
if (kPrintVoltage) {
ir_temp_voltages(sur_raw, obj_raw, &cfg, &voltages);
}
if (ok) {
printf("SUR=%.2fC\tOBJ=%.2fC", result.surrounding_temp_c, result.object_temp_c);
if (kPrintVoltage) {
printf("\tVSUR=%.3fV\tVOBJ=%.3fV\tVDELTA=%.3fV",
voltages.sur_ntc_voltage_v,
voltages.obj_voltage_v,
voltages.obj_delta_voltage_v);
}
printf("\n");
} else {
printf("SUR=%.2fC\tOBJ=out of range", result.surrounding_temp_c);
if (kPrintVoltage) {
printf("\tVSUR=%.3fV\tVOBJ=%.3fV\tVDELTA=%.3fV",
voltages.sur_ntc_voltage_v,
voltages.obj_voltage_v,
voltages.obj_delta_voltage_v);
}
printf("\n");
}
sleep_ms(500);
}
}