-
Notifications
You must be signed in to change notification settings - Fork 1
/
gps_temp_display.erl
68 lines (54 loc) · 1.53 KB
/
gps_temp_display.erl
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
-module(gps_temp_display).
-behaviour(gen_server).
-export([
start_link/1,
init/1,
handle_call/3,
handle_cast/2,
handle_info/2,
terminate/2,
code_change/3
]).
-include("erlem.hrl").
start_link(Params) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, Params, []).
init(Params) ->
?AFTER(maps:get(timestep, Params, 1000), show),
{ok, Params}.
%
% gen_server
%
handle_call(_Msg, _From, State) ->
{reply, ok, State}.
handle_cast(_Msg, State) ->
{noreply, State}.
handle_info(show, State) ->
show(),
?AFTER(maps:get(timestep, State, 1000), show),
{noreply, State};
handle_info(_Info, State) ->
{noreply, State}.
terminate(_Reason, _State) ->
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
%
% local
%
show() ->
#{ t := T, p := P } = bmp280:values(),
{Lat, Lng, Time} = case uart_gps:values() of
#{ lat := Lt, lng := Ln, time := undefined } ->
{Lt, Ln, [0, 0, 0]};
#{ lat := Lt, lng := Ln, time := Tm } ->
{Lt, Ln, Tm};
_ ->
{0.0, 0.0, [0, 0, 0]}
end,
oled_display:p({text, {0, 1, format("Temp ~*.*.*f", [11, 2, $ , T])}}),
oled_display:p({text, {0, 2, format("Pres ~*.*.*f", [11, 2, $ , P])}}),
oled_display:p({text, {0, 3, format("Lat ~*.*.*f", [11, 5, $ , Lat])}}),
oled_display:p({text, {0, 4, format("Lng ~*.*.*f", [11, 5, $ , Lng])}}),
oled_display:p({text, {0, 5, format("Time ~2.10.0B:~2.10.0B:~2.10.0B", Time)}}).
format(F, V) ->
lists:flatten(io_lib:format(F, V)).