Commit beae7261 authored by Hermann Mayer's avatar Hermann Mayer
Browse files

Implemented simple chat.

parent 7c6e1b56
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
17887
18398
+1 −1
Original line number Diff line number Diff line
6617
6801
+25 −10
Original line number Diff line number Diff line
@@ -81,23 +81,38 @@ int main(void)
    RFM70.Initialize();
    RFMSendTime = millis();

    char message[] = "Slave #1: Hello.";
    char messageBuffer[MAX_PACKET_LEN];
    uint16_t recLen = 0;
    
    for (;;)
    {
        rfmTask();                                    //check for RFM70 event in polling mode
        if (millis() > RFMSendTime)                   //send packet
        {                                                   
            RFMSendTime = millis() + RFMSendSpeed;
        // Check for RFM70 event in polling mode
        rfmTask();         

        if (Serial.available() > 0) {

            // Clear buffer
            for (uint16_t i = 0; i < MAX_PACKET_LEN; i++) {
                RFM70_buf[i] = 0x0;
            }

            // Read serial inputs
            recLen = Serial.readBytesUntil('\n', messageBuffer, MAX_PACKET_LEN);

            // Copy over message to buffer
            for(unsigned int i = 0; i < sizeof(message); i++)
    	        RFM70_buf[i+1] = (byte)message[i];
            for(unsigned int i = 0; i < recLen; i++)
                RFM70_buf[i+1] = (byte)messageBuffer[i];

            RFM70.Send_Packet(WR_TX_PLOAD, RFM70_buf, sizeof(message));
            // Send packet
            if (millis() > RFMSendTime)
            {                                                   
                RFMSendTime = millis() + RFMSendSpeed;

                RFM70.Send_Packet(WR_TX_PLOAD, RFM70_buf, recLen+1);
                log("Sending data");
            } 
        }
    }

    return 0;
}
+1 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ add_library (Arduino
	WInterrupts.c
	WMath.cpp
    WString.cpp
    Stream.cpp
	pins_arduino.h
    twi.c
	Wire.cpp