PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
Learn
Examples
Badge
06 Infrared Data
04 Receive and Store IR Data.c
1
/*
2
Send Data with IR.c
3
This is the 'with structures' version of 02 Receive and Store IR Strings.side.
4
*/
5
6
#include "
simpletools.h
"
// Include simpletools library
7
#include "
badgetools.h
"
// Include badgetools library
8
9
typedef
struct
info_st
// info container
10
{
11
char
name[16];
12
char
email[32];
13
}
info
;
14
15
info
their;
// For storing incoming info
16
17
int
irlen, states, exist;
// IR, button and EEPROM status
18
19
void
main
()
// Main function
20
{
21
badge_setup
();
// Call badge setup
22
while
(1)
23
{
24
clear
();
// Menu
25
text_size
(
LARGE
);
26
oledprint
(
" IR Rcv "
);
27
text_size
(
SMALL
);
28
cursor
(0, 5);
29
oledprint
(
" Receive-P27\n"
);
30
oledprint
(
"P15-Upload "
);
31
text_size
(
LARGE
);
32
33
while
(1)
// Wait for button press
34
{
35
states =
buttons
();
36
if
(states)
break
;
37
}
38
39
if
(states == 0b0001000)
// If P15, upload contacts
40
{
41
clear
();
42
oledprint
(
"Upload ..."
);
43
int
contacts =
contacts_count
();
44
for
(
int
record = 0; record < contacts; record++)
45
{
46
eescan
(record,
"%s%s"
, their.name, their.email);
47
print
(
"record %d = %s, %s\n"
, record, their.name, their.email);
48
}
49
oledprint
(
"Done"
);
50
pause
(700);
51
continue
;
// Back to while(1)
52
}
53
if
(states != 0b0000001)
// Not P27?, try again
54
{
55
cursor
(0, 0);
56
text_size
(
LARGE
);
57
oledprint
(
" Try Again "
);
58
pause
(1000);
59
continue
;
// Back to while(1)
60
}
61
62
// P27 has to have been pressed to get to here
63
clear
();
64
oledprint
(
"Ready for IR "
);
// Display ready for IR
65
66
// Wait for IR message
67
irclear
();
// Clear ir com buffers
68
memset(&their, 0,
sizeof
(their));
// Clear their variables
69
while
(1)
70
{
71
irscan
(
"%s%s"
, their.name, their.email);
72
if
(strlen(their.name) > 0)
73
{
74
break
;
75
}
76
}
77
78
clear
();
// Menu, what to do with data
79
text_size
(
SMALL
);
80
oledprint
(
"%s, %s\n"
, their.name, their.email);
81
cursor
(0, 5);
82
oledprint
(
" Store-P26"
);
83
cursor
(0, 6);
84
oledprint
(
" Discard-P25"
);
85
86
87
while
((states =
buttons
()) == 0);
// Wait for button press
88
89
text_size
(
LARGE
);
// Act on button press
90
clear
();
91
if
(states == 0b0000010)
92
{
93
exist =
eeprinted
(
"%16s\n%32s\n"
, their.name, their.email);
94
print
(
"exist = %d\n"
, exist);
95
if
(!exist)
96
eeprint
(
"%16s\n%32s\n"
, their.name, their.email);
97
oledprint
(
"Stored"
);
98
}
99
if
(states == 0b0000100)
100
{
101
oledprint
(
"Discard"
);
102
}
103
pause
(500);
104
}
105
}
106
107
eeprinted
int eeprinted(const char *fmt,...)
Can be called before storing a record with eeprint. Example: if(!eeprinted("Hello EEPROM") eeprint("H...
Definition:
peb_eeprinted.c:12
LARGE
#define LARGE
For setting oLED character size to 32x16 pixels. Example: text_size(LARGE).
Definition:
badgetools.h:192
clear
int clear(void)
Clear the display.
Definition:
oled_clear.c:7
info_st
Definition:
06 Store and Retrieve Data.c:10
eeprint
int eeprint(const char *fmt,...)
Use to store strings to EEPROM in a manner similar to displaying combinations of strings and variable...
Definition:
peb_eeprint.c:12
contacts_count
int contacts_count()
Find out how many contacts are currently stored in EEPROM. This is useful for setting up a loop to fe...
Definition:
peb_contacts_count.c:11
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition:
libws2812.c:125
irscan
int irscan(const char *fmt,...)
Use to receive strings over IR from another badge in a manner similar to retrieving strings that repr...
Definition:
peb_irscan.c:4
buttons
int buttons(void)
Gets the states of all seven touch buttons, and returns them in a value with 1s and 0s that correspon...
Definition:
jm_touchpads.c:90
cursor
void cursor(int col, int row)
Position the cursor to a certain column and row for printing text on the oLED display....
Definition:
oled_cursor.c:7
eescan
int eescan(int recIdx, const char *fmt,...)
Use to retrieve strings to EEPROM in a manner similar to retrieving strings that represent combinatio...
Definition:
peb_eescan.c:12
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
print
int print(const char *format,...) __attribute__((format(printf
Print format "..." args to the default simple terminal device. The output is limited to 256 bytes.
main
int main(void)
Definition:
GraphicsTest.c:20
oledprint
int oledprint(const char *fmt,...)
Use to display strings on the oLED display in a manner similar to displaying combinations of strings ...
Definition:
peb_text.c:4
badge_setup
int badge_setup(void)
Set up all available badge drivers. Call this function at the start of any given program to allow acc...
Definition:
badgealpha.c:29
badgetools.h
This library provides convenient functions for a variety of Parallax eBadge operations.
irclear
void irclear(void)
Clear the infrared send/receive buffers. The most common use of this function is to clear any stray m...
Definition:
peb_irclear.c:4
text_size
void text_size(int size)
Set the text size to either 32x16 pixel (LARGE) or 7x5 (SMALL) characters. Examples: text_size(LARGE)...
Definition:
oled_text_size.c:7
SMALL
#define SMALL
For setting oLED character size to 7x5 pixels. Example: text_size(SMALL).
Definition:
badgetools.h:200
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17