My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
///////////////////////////////////////////////////////////////////////////////
// arduino_master.cpp - Home automation library
//
// Copyright (C) 2009 Jochen Toppe <jochen@jtoee.com>. All right reserved.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
///////////////////////////////////////////////////////////////////////////////

//
// If the user sends a "p" to the arduino via the serial port a pulse
// command is sent to device two, port two.
//
// All incoming commands are printed to the serial port in human-readable form
//

// important -- must include Wire.h first
#include <Wire.h>
// then the rf link libary
#include <RfLink.h>

//
// Handle external RF commands.
//
void handleIncomingCommand(struct Command *cmd)
{
Serial.println("Got external command from device");
Serial.print(" Source Device: ");Serial.println(cmd->sourceDevice, DEC);
Serial.print(" Target Device: ");Serial.println(cmd->targetDevice, DEC);
Serial.print(" Command: ");Serial.println(cmd->command, DEC);
Serial.print(" Data Size: ");Serial.println(cmd->dataSize, DEC);
uint8_t i = 0;
for(; i < cmd->dataSize; i++) {
Serial.print(" Data: ");Serial.println(cmd->data[i], DEC);
}
}

//
// set everything up
//
void setup() {
// register the call-back for incoming commands
RfLink.onReceive(handleIncomingCommand);
// start the serial port
Serial.begin(57600);
// start the RfLink (must-have!)
RfLink.begin();
}

////////////////////////////////////////////////////////////

// a byte to store incoming communication
uint8_t sByte;

//
// repeat
//
void loop()
{
// data available from computer?
if (Serial.available()) {
// read the incoming byte from the serial port
sByte = Serial.read();
if(sByte == 'p') {
Serial.println("sending pulse");
RfLink.pulse(2 /* device two */, 2 /* port 2 */, 100);
}
// check if we got any commands
}


// Since the communication between the Arduino and the attiny rf controller
// on its back is via TWI, the Arduino as the TWI master has to initiate the
// communication to see whether commands where received.
//
// The following call will poll the slave to grab any incoming commands.
//
// This has to be called in a loop. If this is not called, the slave will drop
// wireless commands waiting for the Arduino to pick the current one up.
RfLink.pollSlave();
}


Change log

r117 by jochen.toppe on Jan 2, 2010   Diff
[No log message]
Go to: 
Project members, sign in to write a code review

Older revisions

r116 by jochen.toppe on Jan 2, 2010   Diff
[No log message]
r115 by jochen.toppe on Jan 2, 2010   Diff
[No log message]
r114 by jochen.toppe on Jan 2, 2010   Diff
[No log message]
All revisions of this file

File info

Size: 3178 bytes, 94 lines
Powered by Google Project Hosting