-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinfo_view.c
115 lines (94 loc) · 2.08 KB
/
info_view.c
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Puella Ardens - Burning Man GirlTech based IM communicator.
*/
#include <cc1110.h>
#include <stdio.h>
#include <string.h>
#include "clock.h"
#include "display.h"
#include "info_view.h"
#include "keys.h"
#include "message.h"
#include "music.h"
#include "radio.h"
#define MAX_PINGS 12
/* File global variables. */
static int8_t __xdata pings_[MAX_PINGS];
static uint8_t __xdata ping_id_[4];
static uint8_t __xdata pong_id_[4];
static int8_t num_pings_;
bit need_redraw_;
/* Ping for nearby girltechs. The ping is sent in the foreground. */
void ping() {
num_pings_ = 0;
info_draw();
display_print_message("Pinging now...", 2, 0);
message_send("p", ping_id_, 0);
while (message_still_sending()) {
message_tick();
}
display_print_message("pung", 2, 70);
}
/* Public API */
/* Someone pinged us. */
void info_gotping(const uint8_t* ping_id) {
beep();
/* If we're currently sending a message, ignore the ping. */
if (!message_still_sending()) {
message_send("o", ping_id, 1);
}
}
/* We got back a ping. */
void info_gotpong(const uint8_t* ping_id) {
if (memcmp(ping_id, ping_id_, 4)) {
if (num_pings_ < MAX_PINGS) {
pings_[num_pings_] = radio_last_rssi;
num_pings_++;
need_redraw_ = 1;
}
}
}
void info_init() {
num_pings_ = 0;
need_redraw_ = 0;
}
void info_draw() {
int8_t i, row, col;
need_redraw_ = 0;
clear();
SSN = LOW;
setDisplayStart(0);
setCursor(0, 0);
printf("Radio Status:");
setCursor(1, 0);
printf("RSSI: %d, LQI: %02X", radio_last_rssi, radio_last_lqi);
if (num_pings_) {
setCursor(2, 0);
printf("Results from last ping:");
}
i = 0; row = 3; col = 0;
while (i < num_pings_) {
setCursor(row, col);
printf("%d", pings_[i]);
col += 40;
if (col > 80) {
col = 0;
++row;
}
++i;
}
SSN = HIGH;
}
void info_handle_keypress(uint8_t key) {
switch (key) {
case KONL:
/* Only allow ping if we're not already sending a message. */
if (!message_still_sending()) {
ping();
}
break;
}
}
bit info_tick() {
return need_redraw_;
}