Пример #1
0
void ds1820_error(uint8_t code){
  static char print_buf[80];
  switch(code)
  {
  case PRESENCE_ERROR:
    {
      sprintf(print_buf, "DS1820 No sensor present on Bus. Bus OK.\r\n\0");
      vConsolePrint(print_buf);
      break;
    }
  case BUS_ERROR:
    {
      sprintf(print_buf, "DS1820 Bus Fault\r\n\0");
      vConsolePrint(print_buf);
      break;
    }
  default:
    {

      sprintf(print_buf, "DS1820 Undefined error\r\n\0");
      vConsolePrint(print_buf);
      break;
    }
  }
}
Пример #2
0
void vBoilStateController(unsigned int uiTimerCompareValue)
{
  BoilLevel boil_level = uGetBoilLevel();// each loop iteration, get the level of the boiler.

  switch (uiBoilState)
  {
  case BOILING:
    {
      //if the boil level is low, ensure the elements are off and leave.
      if (boil_level == LOW)
        {
          uiBoilState = OFF;
          vConsolePrint("Boil level too low..Boil off.\r\n\0");
        }
      else
        {
          vStartBoilPWM(uiTimerCompareValue);
        }
      break;
    }
  case OFF:
    {
      vStopBoilPWM();
      uiBoilState = OFF;
      break;
    }
  default:
    {
      vStopBoilPWM();
      uiBoilState = OFF;
      break;
    }
  }
}
Пример #3
0
void vSerialHandlerTask ( void * pvParameters)
{
  char buf[BUFFER_SIZE];
  char line[BUFFER_SIZE];
  char index = 0;
  char c;

  // Take the semaphore before entering infinite loop to make sure it's empty.
  xSemaphoreTake(xSerialHandlerSemaphore, 0);

  // initialise buffer
  for (index = 0; index < BUFFER_SIZE; index++){
      buf[index] = 0;
      line[index] = 0;
  }
  index = 0;
  xCommandQueue = xQueueCreate(32, BUFFER_SIZE);

  for (;;)
    {
      xSemaphoreTake(xSerialHandlerSemaphore, portMAX_DELAY);

      //get char
      c = 0;
      c = comm_get();

      if (c != 0)
        {
          //printf("%c", c);

          //save in buffer and increment buffer index
          buf[index++] = c;
          portENTER_CRITICAL();
          //if newline or full, print it and copy the buffer to 'line' string
          if (c == '\r' || c == '\n' || index >= BUFFER_SIZE){
              buf[index] = '\0';
              strcpy(line, buf);
              printf("%s\r\n", buf);
              fflush(stdout);
              for (index = 0; index < BUFFER_SIZE; index++)
                buf[index] = 0;
              index = 0;
              printf("Contents of 'line':%s\r\n", line);
              xQueueSend(xCommandQueue, line, portMAX_DELAY);
          }
          portEXIT_CRITICAL();
        }
      else
        {
          vConsolePrint("Failed READING\r\n");
        }

    }

}
Пример #4
0
void vTaskBoil( void * pvParameters)
{
  // Generic message struct for message storage.

	BoilMessage xMessage;
  int iDefaultDuty = 0; // receive value from queue.
  int iDuty = 0; // duty in int type
  unsigned int uiADCDuty = 0;
  static unsigned int uiTimerCompareValue = 0; //value of the duty cycle when tranformed to timer units
  portBASE_TYPE xStatus; //queue receive status
  static char buf[50], buf1[50]; //text storage buffers
  for(;;)
    {
      // Receive message
      xStatus = xQueueReceive(xBoilQueue, &xMessage, 10); // check the queue and block for 10ms
      if (xStatus == pdPASS) // message received
        {
          //Validate the message contents
          iDefaultDuty = uiValidateIntegerPct(xMessage.iDutyCycle);
          sprintf(buf, "MSG, duty = %d, st=%d tsk = %d\r\n\0", iDefaultDuty, xMessage.iBrewStep, xMessage.ucFromTask);
          vConsolePrint(buf);
          if (iDefaultDuty > 0)
            {
              uiBoilState = BOILING;
            }
          else
            {
              uiBoilState = OFF;
            }
        }
      else //no message received (polls continually)
        {

          if  (uiBoilState == BOILING)
            {
              uiTimerCompareValue = uiTimerCompareController(xMessage.ucFromTask, iDefaultDuty);
              vBoilStateController(uiTimerCompareValue);
            }
          else
            {
              vBoilStateController(0);
            }
        }

      vTaskDelay(1000);
    }
}
Пример #5
0
void vSerialControlCentreTask( void * pvParameters){
int ii = 0;

static char brewStarted = FALSE;

  for(;;)
    {
      xQueueReceive(xCommandQueue, &buf, portMAX_DELAY);
      portENTER_CRITICAL();
      char * input = (char *)pvPortMalloc(strlen(buf)+1);
      strcpy (input, buf);
      result = (strcmp(input, "command\r\0"));
      vConsolePrint("got something\r\n");
      if (result == 0)
        {
          printf("command received\r\n");
          fflush(stdout);
        }
      if(strcmp(input, "sb\r\0") == 0)
        {
          printf("Command to start brew!\r\n");
          if (!brewStarted){
          menu_command(4);
          menu_command(-1);
          printf("Brew Applet entered\r\n");
          vBrewRemoteStart();
          brewStarted = TRUE;
          }
          else {
              printf("Already Started\r\n");
          }
        }
      portEXIT_CRITICAL();
      vTaskDelay(100);
    }


}
Пример #6
0
static unsigned int uiTimerCompareController(unsigned char ucMessageSource, int iDefaultDuty)
{
  static char buf[50];
  unsigned int uiADCDuty = 0;
  static unsigned int uiLastADCDuty = 0;
  int iDuty = 0;
  unsigned int uiTimerCompareValue = 0;
  static unsigned int uiLastTimerCompareValue = 0;

  switch (ucMessageSource)
  {
  case BREW_TASK:
    {
      uiADCDuty = uiGetADCBoilDuty();
      // Only print if there is a change
      if (uiLastADCDuty != uiADCDuty)
        {
          vConsolePrint("Boil: Msg rcvd from BREW TASK\r\n\0");
          sprintf(buf, "BrewBoil:ADC %d \r\n\0", uiADCDuty);
          vConsolePrint(buf);
        }
      uiLastADCDuty = uiADCDuty;

      // determine which duty cycle to accept
      if (uiADCDuty <= 20)
        {
          iDuty = iDefaultDuty;
        }
      else iDuty = uiADCDuty;

      uiTimerCompareValue = uiTimerCompare(iDuty); // set the timer value to the duty cycle %
      uiBoilDuty = iDuty;  // for UserInterface
      break;
    }
  case BREW_TASK_RESET:
    {
      sprintf(buf, "Boil: Received duty cycle of %d, from ID #%d\r\n\0", iDefaultDuty, ucMessageSource);
      vConsolePrint(buf);
      uiTimerCompareValue = 0;
      uiBoilDuty = 0;  // for UserInterface
      break;
    }
  case BREW_TASK_BRING_TO_BOIL:
    {
      uiTimerCompareValue = uiTimerCompare(100);
      uiBoilDuty = 100;  // for UserInterface
      if (uiLastTimerCompareValue != uiTimerCompareValue)
        {
          vConsolePrint("Message from B2B, setting 100\r\n\0");
        }
      uiLastTimerCompareValue = uiTimerCompareValue;
      break;
    }
  default:
    {
      uiTimerCompareValue = uiTimerCompare(iDefaultDuty); // set the timer value to the duty cycle %
      break;
    }

  }
  return uiTimerCompareValue;
}
Пример #7
0
////////////////////////////////////////////////////////////////////////////
// Interfacing Function
////////////////////////////////////////////////////////////////////////////
void vTaskDS1820Convert( void *pvParameters ){
    char buf[30];
    static char print_buf[80];
    int ii = 0;
    static float fTemp[NUM_SENSORS] = {0.0, 0.0}, fLastTemp[NUM_SENSORS] = {0.0, 0.0};

    // initialise the bus
    ds1820_init();
    if (ds1820_reset() ==PRESENCE_ERROR)
    {
        ds1820_error(PRESENCE_ERROR);
        vConsolePrint("Presence Error, Deleting DS1820 Task\r\n\0");
        vTaskDelete(NULL); // if this task fails... delete it
    }
  
    // Allocate memory for sensors
    b[HLT] = (char *) pvPortMalloc (sizeof(rom)+1);
    b[MASH] = (char *) pvPortMalloc (sizeof(rom)+1);
   // b[CABINET] = (char *) malloc (sizeof(rom)+1);



    // Copy default values
    memcpy(b[HLT], HLT_TEMP_SENSOR, sizeof(HLT_TEMP_SENSOR)+1);
    memcpy(b[MASH], MASH_TEMP_SENSOR, sizeof(MASH_TEMP_SENSOR)+1);
   // memcpy(b[CABINET], CABINET_TEMP_SENSOR, sizeof(CABINET_TEMP_SENSOR)+1);

    ds1820_search();

    //if (rom[0] == 0x10)
      if (rom[0] != 0)
      {
        sprintf(print_buf, "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x\r\n\0",rom[0],
            rom[1], rom[2], rom[3], rom[4], rom[5], rom[6], rom[7]);
        vConsolePrint(print_buf);
      }
    else
      {
        vConsolePrint("NO SENSOR\r\n\0");
      }

    for (;;)
    {
        ds1820_convert();
        vTaskDelay(850/portTICK_RATE_MS); // wait for conversion

        // save values in array for use by application
        for (ii = 0 ; ii < NUM_SENSORS; ii++)
        {
            fTemp[ii] = ds1820_read_device(b[ii]);
            if (fTemp[ii] < 105.0 && fTemp[ii] > 0.0)
              {
                if ((fTemp[ii] < (temps[ii] + 5.0)) || (fTemp[ii] > (temps[ii] - 5.0)) || (fTemp[ii] <= 85.0 && fTemp[ii] >= 86.0))
                  {
                    portENTER_CRITICAL(); // so that other task cannot access temps[] while we are saving.
                    temps[ii] = fTemp [ii];
                    portEXIT_CRITICAL();
                  }

              }
            if (fTemp[ii] == 0.0)
              {
                vConsolePrint("zero values. Temp Bus Resetting\r\n\0");
                ds1820_power_reset();
                ds1820_reset();
              }
        }
        taskYIELD();
    }
    
}
Пример #8
0
void menu_touch(int xx, int yy)
{
  //char c[15];
  vConsolePrint("Menu Touch Called\r\n");
  //sprintf(c, "x %d y %d\r\n", xx, yy);
   //vConsolePrint(c);


    if (g_menu_applet) {
    	if (g_menu_applet(xx, yy))
    		menu_back_after_applet();
        return;
    }

    menu_touch_y = yy;
    menu_touch_x = xx;    
    //menu_update();       
    char bb[30];
    int old = g_item;
    if (g_incoming_command == 1)
      {
       g_item = g_command_item;

      }
    else
      {
        g_item = menu_get_selected();
      }
      g_incoming_command=0;

   // sprintf(bb, "Item Selected is: %u\r\n", g_item);
  //  vConsolePrint(bb);
  //  fflush(stdout);
    lcd_lock();

    if (old != -1)
    	menu_paint_cell(old);
    if (g_item != -1)
    	menu_paint_cell(g_item);

    lcd_release();

    if (xx == -1 || yy == -1 || g_item == -1)
    {
    	if (old != -1)
    	{
    		if (g_menu[g_index][old].press_handler)
    		{
    			g_menu[g_index][old].press_handler(0);
    		}

    	    void (*callback)(int) = g_menu[g_index][old].activate;
    	    g_crumbs[g_index] = old;

    	    if (g_menu[g_index][old].next && g_index < MAX_DEPTH)
    	    {
    	        g_index++;
    	        g_menu[g_index] = g_menu[g_index-1][old].next;
    	        menu_update();
    	    }
    	    else if (g_menu[g_index][old].touch_handler)
    	    {
    	        g_menu_applet = g_menu[g_index][old].touch_handler;
    	        g_item = old;
    	        menu_clear();
    	    }
    	    else if (strcmp(g_menu[g_index][old].text, "Back") == 0)
    	    {
    	        menu_run_callback(0);    	

    	        if (g_index > 0)
    	            g_index--;
    	        menu_update();
    	        menu_run_callback(1);    	
    	    }
    	    
    	    // run the callback which should start the applet or update the display
    	    if (callback)
    	    {
    	        callback(1);
    	    }
    	}
    	return;
    }
    
    menu_touch_y = 0;
    menu_touch_x = 0;

    if (g_menu[g_index][g_item].press_handler)
    {
    	g_menu[g_index][g_item].press_handler(1);
    }
}
Пример #9
0
void vApplicationMallocFailedHook( void )
{
  vConsolePrint("MALLOC FAILED!");
  for(;;);
}
Пример #10
0
void vCheckTask(void *pvParameters)
{
  char buf[50];
  char pcBrewElapsedTime[50], pcStepElapsedTime[50];
  char pcBrewElapsedHours[50], pcBrewElapsedMinutes[50], pcBrewElapsedSeconds[50], pcBrewStep[50];
  char pcBrewStepElapsedHours[50], pcBrewStepElapsedMinutes[50], pcBrewStepElapsedSeconds[50], pcMashTemp[50], pcHLTTemp[50];
  char pcChillerPumpState[50], pcBoilState[50], pcHeapRemaining[50], pcBrewState[50], pcBoilDuty[50], pcLitresDelivered[50];
  int ii = 0;
  char upper_limit = 255, lower_limit = 255;
  unsigned int touch, hops, ds1820, timer, litres, check, low_level = 90, heap, print, serial, serialcontrol;
  unsigned int display_applet, stats_applet, res_applet, graph_applet, brew_task;
  static char cBuf[80];
  for (;;){

      touch = uxTaskGetStackHighWaterMark(xTouchTaskHandle);

      ds1820 =  uxTaskGetStackHighWaterMark(xDS1820TaskHandle);
      timer = uxTaskGetStackHighWaterMark(xTimerSetupHandle);
      litres = uxTaskGetStackHighWaterMark(xLitresToBoilHandle);
      print = uxTaskGetStackHighWaterMark(xPrintTaskHandle);
      hops = uxTaskGetStackHighWaterMark(xHopsTaskHandle);
      check = uxTaskGetStackHighWaterMark(NULL);
      serial = uxTaskGetStackHighWaterMark(xSerialHandlerTaskHandle);
      serialcontrol = uxTaskGetStackHighWaterMark(xSerialControlTaskHandle);
      heap = xPortGetFreeHeapSize();
      display_applet =  uiGetBrewAppletDisplayHWM();
      res_applet =  uiGetBrewResAppletHWM();
      stats_applet =  uiGetBrewStatsAppletHWM();
      graph_applet =  uiGetBrewGraphAppletHWM();
      brew_task =  uiGetBrewTaskHWM();



      sprintf(pcBrewElapsedHours, "4D51E338F02649DFA173631622024A90:%02u\r\n\0", ucGetBrewHoursElapsed());
      vConsolePrint(pcBrewElapsedHours);
      vTaskDelay(80);
      sprintf(pcBrewElapsedMinutes, "99A2038A62BF47E7BFB1922A43C0825C:%02u\r\n\0", ucGetBrewMinutesElapsed());
      vConsolePrint(pcBrewElapsedMinutes);
      vTaskDelay(80);
      sprintf(pcBrewElapsedSeconds, "E9C4FDDEDEBC41D7AC3A3F4C636759A2:%02u\r\n\0", ucGetBrewSecondsElapsed());
      vConsolePrint(pcBrewElapsedSeconds);
      vTaskDelay(80);
      sprintf(pcBrewStep, "1308CA31CAEE4A9A8AC5B353F5ACB594:%02u\r\n\0", ucGetBrewStep());
      vConsolePrint(pcBrewStep);
      vTaskDelay(80);
      sprintf(pcBrewStepElapsedSeconds, "02BA9C74C1384C069ECB648C3CEFFCBA:%02u\r\n\0", ucGetBrewStepSecondsElapsed());
      vConsolePrint(pcBrewStepElapsedSeconds);
      vTaskDelay(80);
      sprintf(pcBrewStepElapsedMinutes, "35C22A915227449C8F2A740F2C26B344:%02u\r\n\0", ucGetBrewStepMinutesElapsed());
      vConsolePrint(pcBrewStepElapsedMinutes);
      vTaskDelay(80);
      sprintf(pcMashTemp, "E21DFC36AFB24226A323D7931B6A1F30:%02u\r\n\0", (unsigned int)floor(ds1820_get_temp(MASH)));
      vConsolePrint(pcMashTemp);
      vTaskDelay(50);
      sprintf(pcHLTTemp, "81A73894E64546868F39EE1758D459AD:%02u\r\n\0", (unsigned int)floor(ds1820_get_temp(HLT)));
      vConsolePrint(pcHLTTemp);
      vTaskDelay(50);
      sprintf(pcChillerPumpState, "461F715060F5468883F6F8500CEAA4BC:%02u\r\n\0", ucGetChillerPumpState());
      vConsolePrint(pcChillerPumpState);
      vTaskDelay(80);
      sprintf(pcBoilState, "60140A1EB194439B8C9A198355FD93AA:%02u\r\n\0", ucGetBoilState());
      vConsolePrint(pcBoilState);
      vTaskDelay(80);
      sprintf(pcBrewState, "FB46F7E5DF914AF1816035EC02DEE0DC:%02u\r\n\0", ucGetBrewState());
      vConsolePrint(pcBrewState);
      vTaskDelay(80);
      sprintf(pcBoilDuty, "F066509116CA43F7B6845C8E2EBA69FA:%02u\r\n\0", uiGetBoilDuty());
      vConsolePrint(pcBoilDuty);
      vTaskDelay(80);
      sprintf(pcLitresDelivered, "3AEE6966D7664AA4BE05BBBBF48E2836:%02u\r\n\0", uiGetActualLitresDelivered());
            vConsolePrint(pcLitresDelivered);
            vTaskDelay(80);




      lower_limit = cI2cGetInput(CRANE_LOWER_LIMIT_PORT, CRANE_LOWER_LIMIT_PIN);
      upper_limit = cI2cGetInput(CRANE_UPPER_LIMIT_PORT, CRANE_UPPER_LIMIT_PIN);

      sprintf(buf, "BD52AA172CAE4F58A11EC35872EFEB99:%d \r \n", ii++%1024);
      sprintf(pcHeapRemaining, "*Heap:%u*low=%d,up=%d\r\n\0", heap, lower_limit, upper_limit);
      vConsolePrint(pcHeapRemaining);
      vTaskDelay(80);
      vConsolePrint(buf);

       if (touch < low_level ||
           timer < low_level ||
           litres < low_level||
           print < low_level ||
           hops < low_level ||
           check < low_level||
           display_applet < low_level ||
           res_applet < low_level ||
           stats_applet < low_level ||
           graph_applet < low_level ||
           brew_task < low_level)


        {
          //vTaskSuspendAll();
          vConsolePrint("=============================\r\n");
          sprintf(cBuf,"check task: idle ticks = %d\r\n", ulIdleCycleCount);
          vConsolePrint(cBuf);
          vTaskDelay(80);
          sprintf(cBuf, "touchwm = %d\r\n", touch);
          vConsolePrint(cBuf);
          vTaskDelay(80);
          sprintf(cBuf, "DS1820wm = %d\r\n", ds1820);
          vConsolePrint(cBuf);
          vTaskDelay(80);
          sprintf(cBuf, "TimerSetupwm = %d\r\n", timer);
          vConsolePrint(cBuf);
          vTaskDelay(80);
          sprintf(cBuf, "litreswm = %d\r\n", litres);
          vConsolePrint(cBuf);
          vTaskDelay(80);
          sprintf(cBuf, "hopswm = %d\r\n", hops);
          vConsolePrint(cBuf);
          vTaskDelay(80);
          sprintf(cBuf, "check = %d\r\n", check);
          vConsolePrint(cBuf);
          vTaskDelay(80);
          sprintf(cBuf, "serial = %d\r\n", serial);
          vConsolePrint(cBuf);
          vTaskDelay(80);
          sprintf(cBuf, "serialcontrol = %d\r\n", serialcontrol);
          vConsolePrint(cBuf);
          vTaskDelay(80);
          sprintf(cBuf, "brewtask = %d\r\n", brew_task);
          vConsolePrint(cBuf);
          vTaskDelay(80);
          sprintf(cBuf, "stats = %d\r\n", stats_applet);
          vConsolePrint(cBuf);
          vTaskDelay(80);
          sprintf(cBuf, "res = %d\r\n", res_applet);
          vConsolePrint(cBuf);
          vTaskDelay(80);
          sprintf(cBuf, "graph = %d\r\n", graph_applet);
          vConsolePrint(cBuf);
          vTaskDelay(80);
          sprintf(cBuf, "brew_display = %d\r\n", display_applet);
          vConsolePrint(cBuf);
          vTaskDelay(80);
          sprintf(cBuf, "print = %d\r\n", print);
          vConsolePrint(cBuf);
          vConsolePrint("=============================\r\n");
          //xTaskResumeAll();
          vTaskDelay(800);

        }
      vTaskDelay(800);
      taskYIELD();
  }
}