/*********************************************************************
*
*          MainTask
*/
void MainTask(void) {
  int Index;

  GUI_Init();
  //
  // Check if recommended memory for the sample is available
  //
  if (GUI_ALLOC_GetNumFreeBytes() < RECOMMENDED_MEMORY) {
    GUI_ErrorOut("Not enough memory available."); 
    return;
  }
  #if GUI_SUPPORT_MEMDEV
    WM_SetCreateFlags(WM_CF_MEMDEV);
  #endif
  WM_SetDesktopColor(GUI_BLACK);
  //
  // Initialize the temperature arrays
  //
  _InitRandomData(_aTemp1, GUI_COUNTOF(_aTemp1));
  _InitRandomData(_aTemp2, GUI_COUNTOF(_aTemp2));
  //
  // Execute the intro dialog
  //
  GUI_ExecDialogBox(_aDialogIntro, GUI_COUNTOF(_aDialogIntro), _cbDialogIntro, WM_HBKWIN, 0, 0);
  //
  // Execute the color and the temperature dialog
  //
  _hDialogColor = GUI_CreateDialogBox(_aDialogColor, GUI_COUNTOF(_aDialogColor), _cbDialogColor, WM_HBKWIN, 0, 0);
  _hDialogMain  = GUI_CreateDialogBox(_aDialogMain,  GUI_COUNTOF(_aDialogMain),  _cbDialogMain,  WM_HBKWIN, 0, 0);
  //
  // Add new temperatures...
  //
  Index = GUI_COUNTOF(_aTemp1) - 1;
  while (1) {
    WM_HWIN hItem;
    GUI_Delay(100); // Wait a while
    //
    // Shift the color arrays
    //
    memmove(_aTemp1, _aTemp1 + 1, sizeof(_aTemp1) - 2);
    memmove(_aTemp2, _aTemp2 + 1, sizeof(_aTemp2) - 2);
    //
    // Add new values
    //
    _aTemp1[Index] = _GetRandomValue(_aTemp1[Index - 1]);
    _aTemp2[Index] = _GetRandomValue(_aTemp2[Index - 1]);
    //
    // Update windows
    //
    hItem = WM_GetClientWindow(WM_GetDialogItem(_hDialogMain, ID_TEMPERATURE));
    WM_InvalidateWindow(hItem);
    _SetProgbarValue(GUI_ID_PROGBAR0, _aTemp1[Index]);
    _SetProgbarValue(GUI_ID_PROGBAR1, _aTemp2[Index]);
  }
}
/*********************************************************************
*
*          MainTask
*/
void MainTask(void) {
  int Index;

  GUI_Init();
  #if GUI_SUPPORT_MEMDEV
    WM_SetCreateFlags(WM_CF_MEMDEV);
  #endif
  WM_SetDesktopColor(GUI_BLACK);
  //
  // Initialize the temperature arrays
  //
  _InitRandomData(_aTemp1, GUI_COUNTOF(_aTemp1));
  _InitRandomData(_aTemp2, GUI_COUNTOF(_aTemp2));
  //
  // Execute the intro dialog
  //
  GUI_ExecDialogBox(_aDialogIntro, GUI_COUNTOF(_aDialogIntro), _cbDialogIntro, WM_HBKWIN, 0, 0);
  //
  // Execute the color and the temperature dialog
  //
  _hDialogColor = GUI_CreateDialogBox(_aDialogColor, GUI_COUNTOF(_aDialogColor), _cbDialogColor, WM_HBKWIN, 0, 0);
  _hDialogMain  = GUI_CreateDialogBox(_aDialogMain,  GUI_COUNTOF(_aDialogMain),  _cbDialogMain,  WM_HBKWIN, 0, 0);
  //
  // Add new temperatures...
  //
  Index = GUI_COUNTOF(_aTemp1) - 1;
  while (1) {
    WM_HWIN hItem;
    GUI_Delay(100); // Wait a while
    //
    // Shift the color arrays
    //
    memmove(_aTemp1, _aTemp1 + 1, sizeof(_aTemp1) - 2);
    memmove(_aTemp2, _aTemp2 + 1, sizeof(_aTemp2) - 2);
    //
    // Add new values
    //
    _aTemp1[Index] = _GetRandomValue(_aTemp1[Index - 1]);
    _aTemp2[Index] = _GetRandomValue(_aTemp2[Index - 1]);
    //
    // Update windows
    //
    hItem = WM_GetClientWindow(WM_GetDialogItem(_hDialogMain, ID_TEMPERATURE));
    WM_InvalidateWindow(hItem);
    _SetProgbarValue(GUI_ID_PROGBAR0, _aTemp1[Index]);
    _SetProgbarValue(GUI_ID_PROGBAR1, _aTemp2[Index]);
  }
}
/*********************************************************************
*
*       _InitRandomData
*/
static void _InitRandomData(I16 * paY, int n) {
  int i;
  int MaxValue;

  MaxValue = _TempMax - _TempMin;
  for (i = 0; i < n; i++) {
    if (!i) {
      paY[i] = rand() % MaxValue;
    } else {
      paY[i] = _GetRandomValue(paY[i-1]);
    }
  }
}