TEST

Dependencies:   TMRh20_v2 mbed-dev ssRadio WakeUp

main.cpp

Committer:
gume
Date:
2017-10-06
Revision:
0:827df48824f9
Child:
1:499ddde5f76c

File content as of revision 0:827df48824f9:

#include "ssRadio.h"

SPI spi(SPI_MOSI, SPI_MISO, SPI_SCK);
SSRadio *radio;
//Serial pc(SERIAL_TX, SERIAL_RX);

void onData(uint8_t *data, uint16_t type, uint8_t size) {
  //pc.printf("Data received.\n");
  //pc.printf("Type: %d\n", type);
  //pc.printf("Size: %d", size);
}

void loop();

int main() {
  //pc.baud(115200);
  //Serial.println(F("Hello World!"));

  spi.frequency(8000000);
  spi.format(8, 0);

  NodeConfig nc(PA_1, PA_2);
  //nc.setSyncAddress(0x3333333333L);
  //nc.setNodeAddress(0x424D451110L); // This is stored in EEPROM or uinqID
  nc.setSyncAddress(0x424D452AD2L);
  nc.setGwId(0x2AE1);
  nc.setChannel(112);

  //Serial.println("I'm " + String(nc.getNodeId()));
  //Serial.flush();

  radio = new SSRadio(&spi, &nc);
  radio->init();

  radio->setOnReceiveData(&onData);
  
  if (!radio->isRunning()) {
    //pc.printf("Error Radio is not working!");
  } else {
    //pc.printf("Working.");
  }
  
  while (1) { loop(); }
}

long last = 0;

void loop() {
  // put your main code here, to run repeatedly:
  
  long now = us_ticker_read() / 1000;
  if (now - last > 1000) {
    //pc.printf("Hello");
    radio->sendData((uint8_t*)"Hello", 6, 6);
    last = now;
  }
  
  radio->loop();
}