Projet S5 Info - Beginner

Dependencies:   TextLCD XBeeLib mbed-rtos mbed

Fork of Coordinateur-Advanced by Vincent Belanger

main.cpp

Committer:
vinbel93
Date:
2016-04-04
Revision:
1:33b4a3b5cdb5
Parent:
0:3acd447c12c0
Child:
2:a7820185e9a8

File content as of revision 1:33b4a3b5cdb5:

#include "mbed.h"
#include "XBeeLib.h"
#include "SDFileSystem.h"
#include "wave_player.h"
 
using namespace XBeeLib;

SDFileSystem sd(p5, p6, p7, p8, "sd"); // MOSI, MISO, SCLK, SSEL
AnalogOut DACout(p18);
wave_player player(&DACout);
Serial pc(USBTX, USBRX);

bool capt_1;
bool capt_2;
bool capt_3;
bool capt_4;
bool capt_5;
bool capt_6;
 
/** Callback function, invoked at packet reception */
static void receive_cb(const RemoteXBeeZB& remote, bool broadcast, const uint8_t *const data, uint16_t len)
{
    const uint64_t remote_addr64 = remote.get_addr64();
 
    pc.printf("\r\nGot packet, len %d\r\nData: ", len);
 
    for (int i = 0; i < len; i++)
    {
        pc.printf("%02x ", data[i]);
    }
        
    capt_1 = (data[0] & 0b10000000);
    capt_2 = (data[0] & 0b01000000);
    capt_3 = (data[0] & 0b00100000);
    capt_4 = (data[0] & 0b00010000);
    capt_5 = (data[0] & 0b00001000);
    capt_6 = (data[0] & 0b00000100);
    
    pc.printf("\r\n%i ", capt_1);
    pc.printf("%i ", capt_2);
    pc.printf("%i ", capt_3);
    pc.printf("%i ", capt_4);
    pc.printf("%i ", capt_5);
    pc.printf("%i ", capt_6);

    pc.printf("\r\n");
}
 
int main()
{
    FILE *fp = fopen("/sd/Synth/A5.wav", "r");
    if(fp == NULL) {
        pc.printf("Could not open file for read\r\n");
    }
    else {
        player.play(fp);
    }
    fclose(fp);

    XBeeZB xbee = XBeeZB(p13, p14, p8, NC, NC, 9600);
 
    /* Register callbacks */
    xbee.register_receive_cb(&receive_cb);
 
    RadioStatus const radioStatus = xbee.init();
    MBED_ASSERT(radioStatus == Success);
 
    /* Wait until the device has joined the network */
    pc.printf("Waiting for device to join the network: ");
    while (!xbee.is_joined()) {
        wait_ms(1000);
    }
    pc.printf("OK\r\n");
 
    while (true) {
        xbee.process_rx_frames();
        wait_ms(100);
    }
}