Esempio n. 1
0
// do something...
void dispatchCommand() {
  int commandNumber = atoi(commandBuffer);
  if (DEBUG) {
    Serial.print("command buffer is: "); Serial.println(commandBuffer);
    Serial.println("accumulated data:"); Serial.println(dataBuffer);
  }

  int dataAsInt;
  switch (commandNumber) {
  case CLEAR:
    clearLineHistory();
    lcd.clear();
    break;
  case ROW_ONE_TEXT:
    writeLine(1, dataBuffer);
    break;
  case ROW_TWO_TEXT:
    writeLine(2, dataBuffer);
    break;
  case PLACE_STRING:
    writeString(dataBuffer);
    break;
  case WRITE_ASCII:
    writeAscii(dataBuffer);
    break;
  case SCROLL_LEFT:
    dataAsInt = atoi(dataBuffer);
    dataAsInt > 0 ? dataAsInt : DEFAULT_SCROLL_DELAY;
    lcd.leftScroll(LINE_SIZE, 
		   dataAsInt > 0 ? dataAsInt : DEFAULT_SCROLL_DELAY);
    lcd.clear();		// should i or not?
    break;
  case SCROLL_UP:
    writeLine(1, lineHistory[2]);
    writeLine(2, dataBuffer);
    break;
  case MAKE_CHAR:
    recvCharData();
    break;
  case SET_GAUGE:
    setGauge();
    break;
  case SEND_CMD:
    lcd.commandWrite(atoi(dataBuffer));
    break;
  case PRINT:
    lcd.print(atoi(dataBuffer));
    break;
  case RESET:
    clearLineHistory();
    resetGauges();
    lcd.clear();
    break;
  default: 
    lcd.clear();
    lcd.printIn("Undef'd Command");
  }
}
/**
 * Reset the contents of this dialog.
 * 
 * @param img image component
 * @param gaugeBounds [0] and [1] are return-out values for gauge's (X, Y)
 *		      [2] and [3] are pass-in value for gauge's width and height
 * @param text message text
 * @return status of this call
 */
MidpError
Alert::setContents(QPixmap* img, int* gaugeBounds, QString text) {
    MidpError err;

    int y = 0;
    int i;
    int hspace;

    int new_x = 0;
    int new_y = mscreen->getAlertHeight()
	    // - ALERT_CELL_SPACING // space to dialog frame
	    - ALERT_BUTTON_HEIGHT; // button fixed height

    int maxImgHeight = mscreen->getAlertHeight()
			// - ALERT_CELL_SPACING // button space to frame
			- ALERT_BUTTON_HEIGHT // buttons
			- ALERT_CELL_SPACING // text space to buttons
			- 16 // minimum one text line
			- (gaugeBounds == NULL
			    ? 0
			    : gaugeBounds[3]+ALERT_CELL_SPACING); // gaugeHeight

    // Image first, centered
    err = setImage(y, maxImgHeight, img);
    if (err != KNI_OK) return err;

    // Gauge in the middle, centered
    err = setGauge(y, gaugeBounds);
    if (err != KNI_OK) return err;

    hspace = (mscreen->getAlertWidth() - ALERT_BUTTON_WIDTH*numButtons)/(numButtons + 1);

    for (i = 0; i < ALERT_NUM_OF_BUTTONS; i++) {

        if (buttons[i] != NULL) {
            new_x += hspace;
            buttons[i]->setGeometry(new_x, new_y,
                    ALERT_BUTTON_WIDTH, ALERT_BUTTON_HEIGHT);
            new_x += ALERT_BUTTON_WIDTH;
        }
    }
    
    
    // Text last
    return setText(y, text);
}