示例#1
0
/* Repeater mode, for use with a standalone dev board */
void repeater_mode() {
  CLKCON = (1<<7) | (0<<6) | (0<<3) | (0<<0); //26MHz crystal oscillator for cpu and timer
  while (CLKCON & CLKCON_OSC);  //wait for clock stability
  
  P1DIR=0x03;   //LEDs on P1.1 and P1.0

#define LEDR P1_1
#define LEDG P1_0
  clock_delayms(100);

  radio_init();
  
  clock_delayms(100);

//    clear();
  while (1) {
    LEDR = 1; LEDG = 0;
  //  print_message(" ",2,0);
  //  print_message(" ",3,0);
  //  print_message("* Listening...        ",0,0);
    radio_listen();
    while (!radio_receive_poll(buf)) {
      clock_delayms(100);
      LEDG ^= 1;
  //    SSN = LOW;
  //    setCursor(0, 15*5);
  //    printf("%d %d %d", rf_packet_ix, rf_packet_n, rf_packet[0]); 
  //    SSN = HIGH;
    }
    buf[21]='\0';
 //   print_message("                                       ",1,0);
 //   print_message(buf, 1, 0);

    LEDR = 0; LEDG = 0;

    RFST = RFST_SIDLE;
    clock_delayms(3000);

    LEDR = 0; LEDG = 1;
 //   print_message("* Sending...",2,0);

    radio_send_packet(buf, strlen(buf) + 1);
    while (radio_still_sending()) {          
      clock_delayms(100);
 //     SSN = LOW;
 //     setCursor(2, 15*5);
 //     printf("%d %d %d", rf_packet_ix, rf_packet_n, rf_packet[0]); 
 //     SSN = HIGH;
    }
 //   print_message("* SENT!", 3, 0);
    RFST = RFST_SIDLE;
    clock_delayms(100);

  }
}
示例#2
0
static void send_message() {

//  while(1) {

  SSN = LOW;
  setDisplayStart(0);
  setCursor(6, 0);
  printf("Transmitting!");

  radio_send_packet(compose_buffer_);
  setCursor(7, 0);
  putchar('8');
  SSN = HIGH;
  
  while (radio_still_sending()) {
    clock_delayms(400);
    SSN = LOW;
    putchar('=');
    SSN = HIGH;
  }
  radio_listen(); // go back into receive mode

  clock_delayms(500);
  SSN = LOW;
  putchar('D');
  SSN = HIGH;
  clock_delayms(500);

//  }

  /* Reset the compose view. */
  state_ = COMPOSE_STATE_WRITING;
  compose_new_message();


  /* Switch back to the inbox view. */
  switch_state(STATE_VIEW);
}
示例#3
0
void main(void) {
  bit test_radio = 0;
  bit bounce_radio = 0;

  /* Initialize app modules. Not reinitialized upon reset. */
  message_init();
  compose_init();
  inbox_init();
  info_init();
  
reset:
  sleepy_ = 0;
  state_ = STATE_VIEW;
  
  if (bounce_radio) {
    repeater_mode();
  }
  
  /* Initialize system modules. */
  clock_init();
  setIOPorts();
  configureSPI();
  LCDReset();
  radio_init();
  random_init();
  
  inbox_draw();

  if (test_radio) {
    run_test_radio();
  }

  /* Main loop. */
  radio_listen();
  while (1) {
    poll_keyboard();

    /* Send and receive messages. */
    message_tick();

    /* Handle background tasks (like progress bar) */
    if (compose_tick() && state_ == STATE_COMPOSE) {
      compose_draw();
    }
    if (info_tick() && state_ == STATE_INFO) {
      info_draw();
    }

    /* go to sleep (more or less a shutdown) if power button pressed */
    if (sleepy_) {
      clear();
      clock_delayms(1000);
      SSN = LOW;
      LCDPowerSave();
      SSN = HIGH;
      sleep();
      /* reset on wake */
      goto reset;
    }
  }
}