コード例 #1
0
ファイル: main.c プロジェクト: arsoft/ChibiOS
/*
 * Application entry point.
 */
int main(void) {

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

  palSetLineMode(LINE_ARD_D14, PAL_MODE_ALTERNATE(4) | PAL_STM32_OSPEED_HIGH);
  palSetLineMode(LINE_ARD_D15, PAL_MODE_ALTERNATE(4) | PAL_STM32_OSPEED_HIGH);

  /*
   * Activates the serial driver 2 using the driver default configuration.
   */
  sdStart(&SD2, NULL);

  /*
   * L3GD20 Object Initialization
   */
  lsm6ds0ObjectInit(&LSM6DS0D1);

  lsm6ds0Start(&LSM6DS0D1, &lsm6ds0cfg);

  while (TRUE) {
    palToggleLine(LINE_LED_GREEN);
    sensorReadRaw(&LSM6DS0D1, rawdata);
    sensorReadCooked(&LSM6DS0D1, cookeddata);
    gyroscopeGetTemp(&LSM6DS0D1, &temp);
    chprintf(chp, "ACCELEROMETER DATA\r\n");
    for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++)
      chprintf(chp, "RAW-%c:%d\t\t", axesID[i], rawdata[i]);
    chprintf(chp, "\r\n");
    for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++)
      chprintf(chp, "COOKED-%c:%.3f g\t", axesID[i], cookeddata[i]);

    chprintf(chp, "\r\nGYROSCOPE DATA\r\n");
    for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++)
      chprintf(chp, "RAW-%c:%d\t\t", axesID[i], rawdata[i + 3]);
    chprintf(chp, "\r\n");
    for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++)
      chprintf(chp, "COOKED-%c:%.3f dps\t", axesID[i], cookeddata[i + 3]);
    chprintf(chp, "\r\n");
    chprintf(chp, "TEMPERATURE DATA\r\n");
    chprintf(chp, "LSM6DS0:%.3f C°\t", temp);
  chprintf(chp, "\r\n");
    chThdSleepMilliseconds(100);
#if CHPRINTF_USE_ANSI_CODE
    chprintf(chp, "\033[2J\033[1;1H");
#endif
  }
}
コード例 #2
0
ファイル: main.c プロジェクト: igor-stoppa/ChibiOS
static void cmd_read(BaseSequentialStream *chp, int argc, char *argv[]) {
  (void)argv;
  if (argc != 2) {
    chprintf(chp, "Usage: read [acc|gyro|both] [raw|cooked]\r\n");
    return;
  }

  while (chnGetTimeout((BaseChannel *)chp, 150) == Q_TIMEOUT) {
    if (!strcmp (argv[0], "acc")) {
      if (!strcmp (argv[1], "raw")) {
#if CHPRINTF_USE_ANSI_CODE
        chprintf(chp, "\033[2J\033[1;1H");
#endif
        accelerometerReadRaw(&LSM6DS0D1, rawdata);
        chprintf(chp, "LSM6DS0 Accelerometer raw data...\r\n");
        for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++) {
          chprintf(chp, "%c-axis: %d\r\n", axisID[i], rawdata[i]);
        }
      }
      else if (!strcmp (argv[1], "cooked")) {
#if CHPRINTF_USE_ANSI_CODE
        chprintf(chp, "\033[2J\033[1;1H");
#endif
        accelerometerReadCooked(&LSM6DS0D1, cookeddata);
        chprintf(chp, "LSM6DS0 Accelerometer cooked data...\r\n");
        for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++) {
          chprintf(chp, "%c-axis: %.4f mG\r\n", axisID[i], cookeddata[i]);
        }
      }
      else {
        chprintf(chp, "Usage: read [acc|gyro|both] [raw|cooked]\r\n");
        return;
      }
    }
    else if (!strcmp (argv[0], "gyro")) {
      if (!strcmp (argv[1], "raw")) {
#if CHPRINTF_USE_ANSI_CODE
        chprintf(chp, "\033[2J\033[1;1H");
#endif
        gyroscopeReadRaw(&LSM6DS0D1, rawdata);
        chprintf(chp, "LSM6DS0 Gyroscope raw data...\r\n");
        for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++) {
          chprintf(chp, "%c-axis: %d\r\n", axisID[i], rawdata[i]);
        }
      }
      else if (!strcmp (argv[1], "cooked")) {
#if CHPRINTF_USE_ANSI_CODE
        chprintf(chp, "\033[2J\033[1;1H");
#endif
        gyroscopeReadCooked(&LSM6DS0D1, cookeddata);
        chprintf(chp, "LSM6DS0 Gyroscope cooked data...\r\n");
        for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++) {
          chprintf(chp, "%c-axis: %.4f DPS\r\n", axisID[i], cookeddata[i]);
        }
      }
      else {
        chprintf(chp, "Usage: read [acc|gyro|both] [raw|cooked]\r\n");
        return;
      }
    }
    else if (!strcmp (argv[0], "both")) {
      if (!strcmp (argv[1], "raw")) {
#if CHPRINTF_USE_ANSI_CODE
        chprintf(chp, "\033[2J\033[1;1H");
#endif
        sensorReadRaw(&LSM6DS0D1, rawdata);
        chprintf(chp, "LSM6DS0 Accelerometer raw data...\r\n");
        for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++) {
          chprintf(chp, "%c-axis: %d\r\n", axisID[i], rawdata[i]);
        }
        chprintf(chp, "LSM6DS0 Gyroscope raw data...\r\n");
        for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++) {
          chprintf(chp, "%c-axis: %d\r\n", axisID[i],
                   rawdata[i + LSM6DS0_ACC_NUMBER_OF_AXES]);
        }
      }
      else if (!strcmp (argv[1], "cooked")) {
#if CHPRINTF_USE_ANSI_CODE
        chprintf(chp, "\033[2J\033[1;1H");
#endif
        sensorReadCooked(&LSM6DS0D1, cookeddata);
        chprintf(chp, "LSM6DS0 Accelerometer cooked data...\r\n");
        for(i = 0; i < LSM6DS0_ACC_NUMBER_OF_AXES; i++) {
          chprintf(chp, "%c-axis: %.4f mG\r\n", axisID[i], cookeddata[i]);
        }
        chprintf(chp, "LSM6DS0 Gyroscope cooked data...\r\n");
        for(i = 0; i < LSM6DS0_GYRO_NUMBER_OF_AXES; i++) {
          chprintf(chp, "%c-axis: %.4f DPS\r\n", axisID[i],
                   cookeddata[i + LSM6DS0_ACC_NUMBER_OF_AXES]);
        }
      }
      else {
        chprintf(chp, "Usage: read [acc|gyro|both] [raw|cooked]\r\n");
        return;
      }
    }
    else {
      chprintf(chp, "Usage: read [acc|gyro|both] [raw|cooked]\r\n");
      return;
    }
  }
  chprintf(chp, "Stopped\r\n");
}
コード例 #3
0
ファイル: main.c プロジェクト: mabl/ChibiOS
static void cmd_read(BaseSequentialStream *chp, int argc, char *argv[]) {
  (void)argv;
  if (argc != 2) {
    chprintf(chp, "Usage: read [baro|thermo|both] [raw|cooked]\r\n");
    return;
  }

  while (chnGetTimeout((BaseChannel *)chp, 150) == Q_TIMEOUT) {
    if (!strcmp (argv[0], "baro")) {
      if (!strcmp (argv[1], "raw")) {
#if CHPRINTF_USE_ANSI_CODE
        chprintf(chp, "\033[2J\033[1;1H");
#endif
        barometerReadRaw(&BMP085D1, rawdata);
        chprintf(chp, "BMP085 Barometer raw data...\r\n");
        chprintf(chp, "Raw pressure: %d\r\n", *rawdata);
      }
      else if (!strcmp (argv[1], "cooked")) {
#if CHPRINTF_USE_ANSI_CODE
        chprintf(chp, "\033[2J\033[1;1H");
#endif
        barometerReadCooked(&BMP085D1, cookeddata);
        chprintf(chp, "BMP085 Barometer cooked data...\r\n");
        chprintf(chp, "Cooked pressure: %.2f %%\r\n", *cookeddata);
      }
      else {
        chprintf(chp, "Usage: read [baro|thermo|both] [raw|cooked]\r\n");
        return;
      }
    }
    else if (!strcmp (argv[0], "thermo")) {
      if (!strcmp (argv[1], "raw")) {
#if CHPRINTF_USE_ANSI_CODE
        chprintf(chp, "\033[2J\033[1;1H");
#endif
        thermometerReadRaw(&BMP085D1, rawdata);
        chprintf(chp, "BMP085 Thermometer raw data...\r\n");
        chprintf(chp, "Raw temperature: %d\r\n", *rawdata);
      }
      else if (!strcmp (argv[1], "cooked")) {
#if CHPRINTF_USE_ANSI_CODE
        chprintf(chp, "\033[2J\033[1;1H");
#endif
        thermometerReadCooked(&BMP085D1, cookeddata);
        chprintf(chp, "BMP085 Thermometer cooked data...\r\n");
        chprintf(chp, "Cooked temperature: %.2f °C\r\n", *cookeddata);
      }
      else {
        chprintf(chp, "Usage: read [baro|thermo|both] [raw|cooked]\r\n");
        return;
      }
    }
    else if (!strcmp (argv[0], "both")) {
      if (!strcmp (argv[1], "raw")) {
#if CHPRINTF_USE_ANSI_CODE
        chprintf(chp, "\033[2J\033[1;1H");
#endif
        sensorReadRaw(&BMP085D1, rawdata);
        chprintf(chp, "BMP085 Barometer raw data...\r\n");
        chprintf(chp, "Raw pressure: %d\r\n", rawdata[0]);
        chprintf(chp, "BMP085 Thermometer raw data...\r\n");
        chprintf(chp, "Raw temperature: %d\r\n", rawdata[1]);
      }
      else if (!strcmp (argv[1], "cooked")) {
#if CHPRINTF_USE_ANSI_CODE
        chprintf(chp, "\033[2J\033[1;1H");
#endif
        sensorReadCooked(&BMP085D1, cookeddata);
        chprintf(chp, "BMP085 Barometer cooked data...\r\n");
        chprintf(chp, "Cooked pressure: %.2f %%\r\n", cookeddata[0]);
        chprintf(chp, "BMP085 Thermometer cooked data...\r\n");
        chprintf(chp, "Cooked temperature: %.2f °C\r\n", cookeddata[1]);
      }
      else {
        chprintf(chp, "Usage: read [baro|thermo|both] [raw|cooked]\r\n");
        return;
      }
    }
    else {
      chprintf(chp, "Usage: read [baro|thermo|both] [raw|cooked]\r\n");
      return;
    }
  }
  chprintf(chp, "Stopped\r\n");
}