示例#1
0
static uint8_t MeasureCm(void) {
  uint16_t us, cm;
  uint8_t buf[8];

  us = US_Measure_us();
  UTIL1_Num16uToStrFormatted(buf, sizeof(buf), us, ' ', 5);
  //LCD1_GotoXY(1,5);
  //LCD1_WriteString((char*)buf);

  cm = US_usToCentimeters(us, 22);
  UTIL1_Num16uToStrFormatted(buf, sizeof(buf), cm, ' ', 5);
  //LCD1_GotoXY(2,5);
  //LCD1_WriteString((char*)buf);
  
  LEDR_Put(cm>0 && cm<10); /* red LED if object closer than 10 cm */
//  LEDB_Put(cm>=10&&cm<=100); /* blue LED if object is in 10..100 cm range */
  LEDG_Put(cm>=10); /* blue LED if object is in 10..100 cm range */
  return cm;
}
示例#2
0
static portTASK_FUNCTION(Hoval, pvParameters) {
  /* LED status:
   * Green: 1 Hz Heartbeat
   * Red: On: pump is on
   *      1 Hz: Scheduler enabled
   *      Off: no scheduler
   */
  CLS1_ConstStdIOType *io = CLS1_GetStdio();
  bool isEnabled = SW1_GetVal()==0; /* initial SW1 status */
  uint16_t secondsOn; /* number of seconds turned on */
  
  (void)pvParameters; /* parameter not used */
  if (GetRTCData(&mySchedule)!=ERR_OK) {
    CLS1_SendStr((unsigned char*)"*** Failed getting RTC data\r\n", io->stdErr);
    for(;;); /* cannot operate like this! */
  }
  isPumpOn = FALSE;
  for(;;) {
    /* check mode switch: turns scheduler on/off */
    if (!isEnabled && SW1_GetVal()==0) {
      Log((unsigned char*)"Switch changed to ON position", io);
    } else if (isEnabled && SW1_GetVal()!=0) {
      Log((unsigned char*)"Switch changed to OFF position", io);
    }
    isEnabled = SW1_GetVal()==0; /* Switch in ON position */

    /* check schedule */
    if (isEnabled && mySchedule.isSchedulerOn) {
      if (!isPumpOn) { /* pump is off, check if we need to turn it on */
        if (isInRange(&mySchedule.on, &mySchedule.off)) {
          SetCooling(TRUE, io);
        }
      } else { /* pump is on, check if we have to turn it off */
        if (!isInRange(&mySchedule.on, &mySchedule.off)) {
          SetCooling(FALSE, io);
        }
      }
    }
    if (isPumpOn) { /* check if we need to toggle the button on the Hoval to avoid timeout */
      secondsOn++;
      if (secondsOn>HOVAL_CYCLE_TIME_SECONDS) {
        Log((unsigned char*)"Toggle manual button to avoid timeout...", io);
        SetCooling(FALSE, io);
        FRTOS1_vTaskDelay(5000/portTICK_RATE_MS); /* wait some time until re-enable manual mode again */
        SetCooling(TRUE, io);
        secondsOn = 0; /* restart counter */
      }
    }
    /* show status LED */
    SD_GreenLed_Neg(); /* 1 Hz heartbeat LED */
    if (isPumpOn) { /* steady red LED if pump is on for cooling */
      SD_RedLed_On();
      LEDR_On();
    } else if (isEnabled && mySchedule.isSchedulerOn) { /* blinking red LED for enabled scheduler */
      SD_RedLed_Put(SD_GreenLed_Get()); /* blink red led in sync with green one */
      LEDR_Put(SD_GreenLed_Get());
    } else {
      SD_RedLed_Off(); /* no red LED if not cooling and no schedule */
      LEDR_Off();
    }
    FRTOS1_vTaskDelay(1000/portTICK_RATE_MS);
  }
}