Example #1
0
static void REF_StateMachine(void) {
  int i;

  switch (refState) {
    case REF_STATE_INIT:
      SHELL_SendString((unsigned char*)"INFO: No calibration data present.\r\n");
      refState = REF_STATE_NOT_CALIBRATED;
      break;
      

      // SW1 pressen, dann kommt er da rein.
    case REF_STATE_NOT_CALIBRATED:
      REF_MeasureRaw(SensorRaw);
      /*! \todo Add a new event to your event module...*/
      if (EVNT_EventIsSet(EVNT_REF_START_STOP_CALIBRATION)) {
        EVNT_ClearEvent(EVNT_REF_START_STOP_CALIBRATION);
        refState = REF_STATE_START_CALIBRATION;
        break;
      }
      break;
    
    case REF_STATE_START_CALIBRATION:
      SHELL_SendString((unsigned char*)"start calibration...\r\n");
      for(i=0;i<REF_NOF_SENSORS;i++) {
        SensorCalibMinMax.minVal[i] = MAX_SENSOR_VALUE;
        SensorCalibMinMax.maxVal[i] = 0;
        SensorCalibrated[i] = 0;
      }
      refState = REF_STATE_CALIBRATING;
      break;
    
    case REF_STATE_CALIBRATING:
      REF_CalibrateMinMax(SensorCalibMinMax.minVal, SensorCalibMinMax.maxVal, SensorRaw);
      if (EVNT_EventIsSet(EVNT_REF_START_STOP_CALIBRATION)) {
        EVNT_ClearEvent(EVNT_REF_START_STOP_CALIBRATION);
        refState = REF_STATE_STOP_CALIBRATION;
      }
      break;
    
    case REF_STATE_STOP_CALIBRATION:
      SHELL_SendString((unsigned char*)"...stopping calibration.\r\n");
      refState = REF_STATE_READY;
      break;
        
    case REF_STATE_READY:
      REF_Measure();
      if (EVNT_EventIsSet(EVNT_REF_START_STOP_CALIBRATION)) {
        EVNT_ClearEvent(EVNT_REF_START_STOP_CALIBRATION);
        refState = REF_STATE_START_CALIBRATION;
      }
      break;
  } /* switch */
}
Example #2
0
static void REF_CalibrateMinMax(SensorTimeType min[REF_NOF_SENSORS], SensorTimeType max[REF_NOF_SENSORS], SensorTimeType raw[REF_NOF_SENSORS]) {
  int i;
  
  REF_MeasureRaw(raw);
  for(i=0;i<REF_NOF_SENSORS;i++) {
    if (raw[i] < min[i]) {
      min[i] = raw[i];
    }
    if (raw[i]> max[i]) {
      max[i] = raw[i];
    }
  }
}
Example #3
0
static void ReadCalibrated(SensorTimeType calib[REF_NOF_SENSORS], SensorTimeType raw[REF_NOF_SENSORS]) {
  int i;
  int32_t x, denominator;
  REF_MeasureRaw(raw);
  for(i=0;i<REF_NOF_SENSORS;i++) {
    x = 0;
    denominator = SensorCalibMinMax.maxVal[i]-SensorCalibMinMax.minVal[i];
    if (denominator!=0) {
      x = (((int32_t)raw[i]-SensorCalibMinMax.minVal[i])*1000)/denominator;
    }
    if (x<0) {
      x = 0;
    } else if (x>1000) {
      x = 1000;
    }
    calib[i] = x;
  }
}
Example #4
0
void REF_CalibrateAverage(SensorTimeType values[NOF_SENSORS], SensorTimeType raw[NOF_SENSORS]) {
  uint32_t sum[NOF_SENSORS];
  #define CALIB_NOF_MEASUREMENT 8
  int i, j;
  
  for(i=0;i<NOF_SENSORS;i++) {
    sum[i] = 0; /* init */
  }
  for(j=0;j<CALIB_NOF_MEASUREMENT;j++) {
    REF_MeasureRaw(raw);
    for(i=0;i<NOF_SENSORS;i++) {
      sum[i]+=raw[i];
    }
  }
  /* build average */
  for(i=0;i<NOF_SENSORS;i++) {
    values[i] = sum[i]/CALIB_NOF_MEASUREMENT;
  }
}
Example #5
0
static void ReadCalibrated(SensorTimeType calib[NOF_SENSORS], SensorTimeType raw[NOF_SENSORS]) {
  int i;
  int32_t x, denominator;
  
  REF_MeasureRaw(raw);
  if (!isCalibrated) {
    return;
  }
  for(i=0;i<NOF_SENSORS;i++) {
    denominator = SensorBlack[i]-SensorWhite[i];
    if (denominator!=0) {
      x = (((int32_t)SensorRaw[i]-SensorWhite[i])*1000)/denominator;
    }
    if (x<0) {
      x = 0;
    } else if (x>1000) {
      x = 1000;
    }
    calib[i] = x;
  }
}
Example #6
0
static void REF_StateMachine(void) {
  int i;

  switch (refState) {
    case REF_STATE_INIT:
#if PL_HAS_CONFIG_NVM
    	/* If Calibration Data are saved, read it */
    	for (i = 0; i<REF_NOF_SENSORS;i++){
    		SensorCalibMinMax.minVal[i] = *((uint16_t*)NVMC_GetReflectanceData()+i);
    		SensorCalibMinMax.minVal[i+REF_NOF_SENSORS] = *((uint16_t*)NVMC_GetReflectanceData()+(i+REF_NOF_SENSORS));
    	}
      SHELL_SendString((unsigned char*)"INFO: Loaded calibration data from FLASH...Gordon.\r\n");
      refState = REF_STATE_READY;
#else
      SHELL_SendString((unsigned char*)"INFO: No calibration data present.\r\n");
      refState = REF_STATE_NOT_CALIBRATED;
      break;
#endif
    case REF_STATE_NOT_CALIBRATED:

      REF_MeasureRaw(SensorRaw);

      if (EVNT_EventIsSet(EVNT_REF_START_STOP_CALIBRATION)) {
        EVNT_ClearEvent(EVNT_REF_START_STOP_CALIBRATION);
        refState = REF_STATE_START_CALIBRATION;
        break;
      }
      break;

    case REF_STATE_START_CALIBRATION:
      SHELL_SendString((unsigned char*)"start calibration...\r\n");
      for(i=0;i<REF_NOF_SENSORS;i++) {
        SensorCalibMinMax.minVal[i] = MAX_SENSOR_VALUE;
        SensorCalibMinMax.maxVal[i] = 0;
        SensorCalibrated[i] = 0;
      }
      refState = REF_STATE_CALIBRATING;
      break;

    case REF_STATE_CALIBRATING:
      REF_CalibrateMinMax(SensorCalibMinMax.minVal, SensorCalibMinMax.maxVal, SensorRaw);
      if (EVNT_EventIsSet(EVNT_REF_START_STOP_CALIBRATION)) {
        EVNT_ClearEvent(EVNT_REF_START_STOP_CALIBRATION);
        refState = REF_STATE_STOP_CALIBRATION;
      }
      break;
    
    case REF_STATE_STOP_CALIBRATION:

    	/* Save Calibration Data */
      NVMC_SaveReflectanceData(&SensorCalibMinMax, sizeof(SensorCalibMinMax));


      SHELL_SendString((unsigned char*)"...stopping calibration. Files written to Flash\r\n");
      refState = REF_STATE_READY;
      break;
        
    case REF_STATE_READY:
      REF_Measure();
      if (EVNT_EventIsSet(EVNT_REF_START_STOP_CALIBRATION)) {
        EVNT_ClearEvent(EVNT_REF_START_STOP_CALIBRATION);
        refState = REF_STATE_START_CALIBRATION;
      }
      break;
  } /* switch */
}
Example #7
0
static void REF_StateMachine(void) {
  int i;

  switch (refState) {
    case REF_STATE_INIT:
    #if PL_CONFIG_EST
    {
      SensorCalibT *ptr;

      ptr = (SensorCalibT*)NVMC_GetReflectanceData();
      if (ptr!=NULL) { /* valid data */
        SensorCalibMinMax = *ptr;
        refState = REF_STATE_READY;
      } else {
        refState = REF_STATE_NOT_CALIBRATED;
      }
    }
    #else
      SHELL_SendString((unsigned char*)"INFO: No calibration data present.\r\n");
      refState = REF_STATE_NOT_CALIBRATED;
    #endif
      break;
      
    case REF_STATE_NOT_CALIBRATED:
      REF_MeasureRaw(SensorRaw);
      /*! \todo Add a new event to your event module...*/
#if REF_START_STOP_CALIB
      if (FRTOS1_xSemaphoreTake(REF_StartStopSem, 0)==pdTRUE) {
        refState = REF_STATE_START_CALIBRATION;
      }
#endif
      break;
    
    case REF_STATE_START_CALIBRATION:
      SHELL_SendString((unsigned char*)"start calibration...\r\n");
      for(i=0;i<REF_NOF_SENSORS;i++) {
        SensorCalibMinMax.minVal[i] = MAX_SENSOR_VALUE;
        SensorCalibMinMax.maxVal[i] = 0;
        SensorCalibrated[i] = 0;
      }
      refState = REF_STATE_CALIBRATING;
      break;
    
    case REF_STATE_CALIBRATING:
      REF_CalibrateMinMax(SensorCalibMinMax.minVal, SensorCalibMinMax.maxVal, SensorRaw);
#if PL_CONFIG_HAS_BUZZER
      startBuzzer(Middle,200);
#endif
#if REF_START_STOP_CALIB
      if (FRTOS1_xSemaphoreTake(REF_StartStopSem, 0)==pdTRUE) {
        refState = REF_STATE_STOP_CALIBRATION;
      }
#endif
      break;
    
    case REF_STATE_STOP_CALIBRATION:
      SHELL_SendString((unsigned char*)"...stopping calibration.\r\n");
#if PL_CONFIG_EST
      if (NVMC_SaveReflectanceData(&SensorCalibMinMax, sizeof(SensorCalibMinMax))!=ERR_OK) {
        SHELL_SendString((unsigned char*)"Flashing calibration data FAILED!\r\n");
      } else {
        SHELL_SendString((unsigned char*)"Stored calibration data.\r\n");
      }
#endif
      refState = REF_STATE_READY;
      break;
        
    case REF_STATE_READY:
      REF_Measure();
#if REF_START_STOP_CALIB
      if (FRTOS1_xSemaphoreTake(REF_StartStopSem, 0)==pdTRUE) {
        refState = REF_STATE_START_CALIBRATION;
      }
#endif
      break;
  } /* switch */
}
Example #8
0
static void REF_StateMachine(void) {
  int i;

  switch (refState) {
    case REF_STATE_INIT:
#if NVM_ENABLED
    refState = REF_GetCalibData();
#else
    refState = REF_STATE_NOT_CALIBRATED;
    SHELL_SendString("INFO: Sensor not calibrated");
#endif
    break;

      
    case REF_STATE_NOT_CALIBRATED:
      REF_MeasureRaw(SensorRaw);
      /*! \todo Add a new event to your event module...*/
#if REF_START_STOP_CALIB
      if (FRTOS1_xSemaphoreTake(REF_StartStopSem, 0)==pdTRUE) {
        refState = REF_STATE_START_CALIBRATION;
      }
#endif
      break;
    
    case REF_STATE_START_CALIBRATION:
      SHELL_SendString((unsigned char*)"start calibration...\r\n");
      for(i=0;i<REF_NOF_SENSORS;i++) {
        SensorCalibMinMax.minVal[i] = MAX_SENSOR_VALUE;
        SensorCalibMinMax.maxVal[i] = 0;
        SensorCalibrated[i] = 0;
      }
      refState = REF_STATE_CALIBRATING;
      break;
    
    case REF_STATE_CALIBRATING:
      REF_CalibrateMinMax(SensorCalibMinMax.minVal, SensorCalibMinMax.maxVal, SensorRaw);
#if PL_CONFIG_HAS_BUZZER
     (void)BUZ_Beep(300, 20);
#endif
#if REF_START_STOP_CALIB
      if (FRTOS1_xSemaphoreTake(REF_StartStopSem, 0)==pdTRUE) {
        refState = REF_STATE_STOP_CALIBRATION;
      }
#endif
      break;
    
    case REF_STATE_STOP_CALIBRATION:
      SHELL_SendString((unsigned char*)"...stopping calibration.\r\n");
#if NVM_ENABLED
      SHELL_SendString((unsigned char*)"saving calib data...\r\n");
      REF_SaveCalibData();
#endif
      refState = REF_STATE_READY;
      break;
        
    case REF_STATE_READY:
      REF_Measure();
#if REF_START_STOP_CALIB
      if (FRTOS1_xSemaphoreTake(REF_StartStopSem, 0)==pdTRUE) {
        refState = REF_STATE_START_CALIBRATION;
      }
#endif
      break;
  } /* switch */
}