示例#1
0
void compose_handle_keypress(uint8_t key) {
  if (state_ == COMPOSE_STATE_WRITING) {
    switch (key) {
      case KBACK:
        del_char();
        compose_draw();
        break;
      case '<':
        cursor_left();
        compose_draw();
        break;
      case '>':
        cursor_right();
        compose_draw();
        break;
      case ' ':
      case ',':
        add_char(key);
        compose_draw();
        break;
      case KALT:
        alt_on_ = !alt_on_;
        compose_draw();
        break;
      case KSPK:
        if (alt_on_) {
          add_char('0');
          compose_draw();
        }
        break;
      case '\n':
        state_ = COMPOSE_STATE_CONFIRM;
        compose_draw();
      default:
        if (key >= 'A' && key <= 'Z') {
          add_char(key);
          compose_draw();
        }
        break;
    }
  } else if (state_ == COMPOSE_STATE_CONFIRM) {
    switch (key) {
      case 'Y':
        state_ = COMPOSE_STATE_SENDING;
        compose_draw();
        send_message();
        break;
      case 'N':
        state_ = COMPOSE_STATE_WRITING;
        compose_draw();
        break;
    }
  }
}
示例#2
0
void switch_state(int8_t new_state) {
  state_ = new_state;
  switch (state_) {
    case STATE_VIEW: inbox_draw(); break;
    case STATE_COMPOSE: compose_draw(); break;
    case STATE_INFO: info_draw(); break;
  }
}
示例#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;
    }
  }
}