-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.cpp
78 lines (61 loc) · 1.17 KB
/
common.cpp
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
74
75
76
#include <Arduino.h>
#include <Time.h>
#include <avr/pgmspace.h>
#include <stdio.h>
#include "common.h"
bool raw_measuring = 0;
char *itoa_10lz(char *buf, uint16_t val, uint8_t digits)
{
uint8_t pos = digits - 1;
for (uint8_t i = 0; i < digits; i++) {
buf[pos] = '0' + val % 10;
val /= 10;
pos--;
}
return buf;
}
char *sprintf_time(char *buf, time_t time)
{
char *p = buf;
itoa_10lz(p, year(time), 4);
p += 4;
*p++ = '-';
itoa_10lz(p, month(time), 2);
p += 2;
*p++ = '-';
itoa_10lz(p, day(time), 2);
p += 2;
*p++ = ' ';
itoa_10lz(p, hour(time), 2);
p += 2;
*p++ = ':';
itoa_10lz(p, minute(time), 2);
p += 2;
*p++ = ':';
itoa_10lz(p, second(time), 2);
p += 2;
*p = '\0';
return buf;
}
static char time_buf[STRBUF_TIME_SIZE];
void printTime(time_t time)
{
Serial.println(sprintf_time(time_buf, time));
}
unsigned short readBattery_mV()
{
unsigned short adc = analogRead(BATT_MEASURE_PIN);
// double v;
return adc * 44 / 10;
// v = adc * 1.1 / 1024;
// v *= (820.0 / 200);
// return v;
}
void set_bluetooth_mode(enum bt_mode mode)
{
bluetooth_mode = mode;
if (mode == BT_PERMANENT) {
digitalWrite(BT_EN_PIN, HIGH);
bt_enabled = true;
}
}