⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 housecontrol.c

📁 uc/os下的gui,友好的交互界面可以使你的产品更有吸引力
💻 C
📖 第 1 页 / 共 4 页
字号:
    }    Ptr = strrchr(pStr, ' ');    if (Ptr != NULL) {      v2 = v1;      v1 = _ConvStrToInt(Ptr + 1);      *Ptr = 0;    }    if (_pfcbReceiveCommand) {      (*_pfcbReceiveCommand)(pStr, v1, v2);    }  }  /*********************************************************************  *  *       _ReceivedChar  */  static void _ReceivedChar(char c) {    if (c == EOL) {      _pString = _acString;      _ReceivedString(_acString);    } else {      if (_pString < (_acString + STRING_SIZE)) {        if (c >= 'a' && c <= 'z') {          c -= 'a' - 'A';        }        *_pString++     = c;        *(_pString + 1) = 0;      }    }  }#endif  /* #ifndef WIN32 *//***********************************************************************       static code, serial interface************************************************************************//***********************************************************************       _SerialSendCommand*/static void _SerialSendCommand(const char* pStr, int v1, int v2) {  #ifndef WIN32    char Str1[STRING_SIZE + 2];    char Str2[5];    int Len, i, v;    Str1[STRING_SIZE] = 0;    strncpy(Str1, pStr, STRING_SIZE);    for (i = 0; i < 2; i++) {      v = (i == 0) ? v1 : v2;      if (v >= 0 && v <= 999) {        _ConvIntToStr(Str2, v);        if ((strlen(Str1) + strlen(Str2) + 1) <= STRING_SIZE) {          strcat(Str1, " ");          strcat(Str1, Str2);        }      }    }    Len = strlen(Str1);    Str1[Len]   = EOL;    Str1[Len+1] = 0;    _SendString(Str1);  #endif}/***********************************************************************       _SerialExec*/static void _SerialExec(void) {  #ifndef WIN32    OS_U8 Data;    while (_RxBuffer.pRead != _RxBuffer.pWrite) {      Data = *(_RxBuffer.pRead)++;      if (_RxBuffer.pRead == _RxBuffer.pDataEnd) {        _RxBuffer.pRead -= _RxBuffer.Size;      }      _ReceivedChar((char)Data);    }  #endif}/***********************************************************************       _SerialInit*/static void _SerialInit(SERIAL_Callback* cb) {  #ifndef WIN32    OS_SetRxCallback(&_cbReceiveData);    _pfcbReceiveCommand = cb;  #endif}/***********************************************************************       static code, helper functions************************************************************************//***********************************************************************       _SetSliderValue*/static void _SetSliderValue(WM_HWIN hWin, int Id, int Min, int Max, int Value) {  WM_HWIN hItem;  hItem = WM_GetDialogItem(hWin, Id);  SLIDER_SetRange(hItem, Min, Max);  SLIDER_SetValue(hItem, Value);}/***********************************************************************       _GetSliderValue*/static int _GetSliderValue(WM_HWIN hDlg, int Id) {  return SLIDER_GetValue(WM_GetDialogItem(hDlg, Id));}/***********************************************************************       _AddDialog*/static WM_HWIN _AddDialog(const char* pText, const GUI_WIDGET_CREATE_INFO* pDialog, int NumItems,                          WM_CALLBACK* cb, WM_HWIN hMultiPage) {  WM_HWIN hWin;  hWin = GUI_CreateDialogBox(pDialog, NumItems, cb, WM_GetClientWindow(hMultiPage), 0, 0);  MULTIPAGE_AddPage(hMultiPage, 0, pText);  return hWin;}/***********************************************************************       _SetDialogLight*/static void _SetDialogLight(void) {  if (_hDialogLight) {    _InitDialog = 1;    _SetSliderValue(_hDialogLight, GUI_ID_SLIDER0, 0, 100, _Level[0].Light.ActV);    _SetSliderValue(_hDialogLight, GUI_ID_SLIDER1, 0, 100, _Level[1].Light.ActV);    _SetSliderValue(_hDialogLight, GUI_ID_SLIDER2, 0, 100, _Level[2].Light.ActV);    _SetSliderValue(_hDialogLight, GUI_ID_SLIDER3, 0, 100, _Level[3].Light.ActV);    _SetSliderValue(_hDialogLight, GUI_ID_SLIDER4, 0, 100, _Level[4].Light.ActV);    _InitDialog = 0;  }}/***********************************************************************       _InvalidateObject*/static void _InvalidateObject(WM_HWIN hWin, GUI_RECT r) {  r.y0 -= _Scroll.ActV;  r.y1 -= _Scroll.ActV;  WM_InvalidateRect(hWin, &r);}/***********************************************************************       _InvalidateObject2*/static void _InvalidateObject2(WM_HWIN hWin, GUI_RECT r) {  WM_InvalidateRect(hWin, &r);}/***********************************************************************       _InvalidateRect*/static void _InvalidateRect(WM_HWIN hWin, GUI_RECT r, int xOff, int yOff) {  r.x0 += xOff;  r.x1 += xOff;  r.y0 += yOff;  r.y1 += yOff;  WM_InvalidateRect(hWin, &r);}/***********************************************************************       _AlertOn*/static void _AlertOn(int Index) {  if (_hAlert[Index] == 0) {    BUTTON_Handle hBut;    WM_HWIN hClient;    int Off = Index * 10;    _hAlert[Index] = FRAMEWIN_Create(_acAlertText[Index], 0, WM_CF_SHOW, 100 + Off, 85 + Off, 110, 60);    FRAMEWIN_SetMoveable(_hAlert[Index], 1);    FRAMEWIN_SetActive(_hAlert[Index], 1);    FRAMEWIN_SetBarColor(_hAlert[Index], 0, Index ? GUI_BLUE : GUI_RED);    hClient = WM_GetClientWindow(_hAlert[Index]);    WM_SetCallback(hClient, &_cbWinAlert);    hBut = BUTTON_CreateAsChild(20, 10, 65, 20, hClient, 1, WM_CF_SHOW);    BUTTON_SetText(hBut, "OK");    _AlertCnt[Index] = 250;  }}/***********************************************************************       _AlertOff*/static void _AlertOff(int Index) {  if (_hAlert[Index]) {    WM_DeleteWindow(_hAlert[Index]);    _hAlert[Index]   = 0;    _AlertCnt[Index] = 0;  }}/***********************************************************************       _SlideValue*/static int _SlideValue(OBJECT* pObj, int Step) {  int DiffY = pObj->NewV - pObj->ActV;  if (DiffY != 0) {    if (DiffY < 0) {      pObj->ActV -= Step;      DiffY = -DiffY;    } else {      pObj->ActV += Step;    }    if ((DiffY - Step) < 0) {      pObj->ActV = pObj->NewV;    }    return 1;  }  return 0;}/***********************************************************************       _SlideStatus*/static void _SlideStatus() {  int Step = ((GUI_GetTime() - _SlidePrevTime) * 5) >> 7;  if (Step != 0) {    _SlidePrevTime = GUI_GetTime();    if (_SlideValue(&_Garage, Step << 1)) {      _InvalidateObject(_hWinHouse, _Garage.Rect);      _InvalidateObject2(_hWinMap, _GarageSmall.Rect);    }    if (_SlideValue(&_Jalousie1, Step)) {      _InvalidateObject(_hWinHouse, _Jalousie1.Rect);      _InvalidateObject2(_hWinMap, _Jalousie1Small.Rect);    }    if (_SlideValue(&_Jalousie2, Step)) {      _InvalidateObject(_hWinHouse, _Jalousie2.Rect);      _InvalidateObject2(_hWinMap, _Jalousie2Small.Rect);    }    if (_SlideValue(&_Marquee1, Step)) {      _InvalidateObject(_hWinHouse, _Marquee1.Rect);      _InvalidateObject2(_hWinMap, _Marquee1Small.Rect);    }    if (_SlideValue(&_Marquee2, Step)) {      _InvalidateObject(_hWinHouse, _Marquee2.Rect);      _InvalidateObject2(_hWinMap, _Marquee2Small.Rect);    }    if (_SlideValue(&_Elevator.Itself, Step)) {      _InvalidateObject(_hWinHouse, _Elevator.Itself.Rect);      _InvalidateObject2(_hWinMap, _ElevatorSmall.Rect);    }    if (_SlideValue(&_Elevator.Door, Step << 1)) {      _InvalidateRect(_hWinHouse, _Elevator.Door.Rect, 0, _Elevator.Itself.ActV - _Scroll.ActV);    }    if (_AlertCnt[0]) {      _AlertCnt[0] -= Step;      if (_AlertCnt[0] <= 0) _AlertOff(0);    }    if (_AlertCnt[1]) {      _AlertCnt[1] -= Step;      if (_AlertCnt[1] <= 0) _AlertOff(1);    }  }  Step = GUI_GetTime() - _ScrollPrevTime;  if (Step != 0) {    _ScrollPrevTime = GUI_GetTime();    if (_SlideValue(&_Scroll, Step << 1)) {      SCROLLBAR_SetValue(_hScroll, _Scroll.ActV);      _InvalidateObject(_hWinHouse, _Scroll.Rect);    }  }}/***********************************************************************       _Clip*/static int _Clip(int Value) {  Value = (Value < 100) ? Value : 100;  Value = (Value >   0) ? Value :   0;  return Value;}/***********************************************************************       static code, drawing functions************************************************************************//***********************************************************************       _DrawRect*/static void _DrawRect(int x0, int y0, int x1, int y1, int PenSize) {  GUI_SetPenSize(PenSize);  GUI_DrawRect(x0, y0, x1, y1 + PenSize - 1);}/***********************************************************************       _DrawElevator2*/static void _DrawElevator2(int x,  int y,  int w,  int h,                           int x0, int y0, int x1, int y1,                           int Index, GUI_COLOR Color) {  if (y0 <= y1 && x0 <= x1) {    GUI_RECT ClipRect;    const GUI_RECT* OldClipRect;    int Door = (w - 2) * (100 - _Elevator.Door.ActV) / 100;    ClipRect.x0 = x + x0;    ClipRect.y0 = y + y0;    ClipRect.x1 = x + x1;    ClipRect.y1 = y + y1;    OldClipRect = WM_SetUserClipRect(&ClipRect);    /* Draw elevator car */    GUI_SetColor(LCD_MixColors256(Color, GUI_GRAY, Index ? 150 : 0));    GUI_FillRect(x, y, x + w, y + h);    /* Draw door frame (inside) */    GUI_SetColor(LCD_MixColors256(Color, GUI_WHITE, Index ? 150 : 0));    _DrawRect(x, y, x + w, y + h, 1);    /* Draw elevator door (inside) */    GUI_SetColor(LCD_MixColors256(Color, GUI_LIGHTGRAY, Index ? 150 : 0));    GUI_FillRect(x + 1, y + 1, x + 1 + Door, y + h - 1);    WM_SetUserClipRect(OldClipRect);  }}/***********************************************************************       _DrawElevator*/static void _DrawElevator(int x, int y, int w, int h, int Level) {  GUI_COLOR Color1, Color2;  int yPos, yStart, yEnd, y0, y1;  int Light = _Level[Level].Light.ActV;  /* Draw elevator shaft */  Color1  = (0x8F * Light / 100 + 0x60) << 16;  Color1 += (0x7F * Light / 100 + 0x0) << 8;  Color1 += (0x6F * Light / 100 + 0x20);  GUI_SetColor(Color1);  GUI_FillRect(x, y, x + w, y + h);  /* Draw elevator door (outside) */  Color2 = 0x5F * Light / 100 + 0xA0;  Color2 = (Color2 << 16 | Color2 << 8 | Color2);  GUI_SetColor(Color2);  GUI_FillRect(x + 2, y + 80, x + w - 2, y + h - 2);  /* Draw elevator car */  yPos   = _Elevator.Itself.ActV - (5 - Level) * 130 + 80;  yStart = (yPos < 0) ? -yPos : 0;  yEnd   = (yPos > 82) ? 125 - yPos : 43;  if (yPos != 80) {    y0 = (yPos > 80) ? yStart + 44 - (yPos - 80) : yStart;    y1 = (yPos > 80) ? yEnd : 79 - yPos;    _DrawElevator2(x + 2, y + yPos, w - 4, 43, 0, y0, w - 4, y1, 1, Color1);  }  y0 = (yPos < 80) ? yStart + (80 - yPos) : yStart;  y1 = (yPos > 80) ? 43 - (yPos - 80) : 43;  if (_Elevator.Move) {    GUI_SetColor(Color2);    GUI_FillRect(x + 2, y + 80, x + w - 2, y + h - 2);    _DrawElevator2(x + 2, y + yPos, w - 4, 43, 0, y0, w - 4, y1, 1, Color2);  } else {    int Door = (w - 4) * (100 - _Elevator.Door.ActV) / 100;    _DrawElevator2(x + 2, y + yPos, w - 4, 43, 0, y0, Door, y1, 1, Color2);    _DrawElevator2(x + 2, y + yPos, w - 4, 43, Door + 1, y0, w - 4, y1, 0, Color2);  }  /* Draw door frame (outside) */  Color2 = 0x7F * Light / 100 + 0x50;  GUI_SetColor(Color2 << 16);  _DrawRect(x + 1, y + 79, x + w - 1, y + h - 1, 1);  /* Draw level number */  if (_Elevator.Itself.ActV == _Elevator.Itself.NewV &&      _Elevator.Itself.ActV == ((5 - Level) * 130)) {    GUI_SetColor(0x00FF40);  } else {    Color2 = 0x3F * Light / 100 + 0xC0;    GUI_SetColor(Color2 << 8 | Color2);  }  GUI_SetFont(&GUI_Font8x8);  GUI_SetTextMode(GUI_TM_TRANS);  GUI_DispCharAt(Level + 1 + '0', x + (w / 2) - 3, y + 70);}/***********************************************************************       _DrawWindow*/static void _DrawWindow(int x, int y, int w, int h, int dy, int Light) {  GUI_COLOR Color;  int i;  Color = 0x80 * Light / 100 + 0x7F;  GUI_SetColor(Color << 16);  GUI_FillRect(x, y, x + w, y + h);  Color = 0x60 * Light / 100 + 0x9F;  GUI_SetColor(Color << 16 | Color << 8 | Color);  GUI_DrawVLine(x, y, y + h);  GUI_DrawVLine(x + w / 2, y, y + h);  GUI_DrawVLine(x + w, y, y + h);  for (i = 0; i < h; i += dy) {    GUI_DrawHLine(y + i, x, x + w);  }  GUI_DrawHLine(y + h, x, x + w);}/***********************************************************************       _DrawFrame*/static void _DrawFrame(int x, int y, int w, int h, int Light) {  GUI_COLOR Color;  Color = 0x88 * Light / 100 + 0x48;  GUI_SetColor(Color << 16 | Color << 8 | Color);  GUI_FillRect(x, y, x + w - 1, y + h - 1);  GUI_SetColor(GUI_WHITE);  _DrawRect(x, y, x + w - 1, y + h - 1, 2);  Color = 0xA0 * Light / 100 + 0x5F;  GUI_SetColor(Color << 16 | Color << 8 | Color);  GUI_SetPenSize(1);  GUI_DrawLine(x + 2, y + 2, x + w - 2, y + h - 2);  GUI_DrawLine(x + w - 2, y + 2, x + 2, y + h - 2);}/***********************************************************************       _DrawMarquee*/static void _DrawMarquee(int x, int y, int w, int h, int d, int Status) {  GUI_RECT ClipRect;  const GUI_RECT* OldClipRect;  ClipRect.x0 = (d < 0) ? (x - w - 2) : (x + 1);  ClipRect.y0 = y - 1;  ClipRect.x1 = (d < 0) ? (x - 1) : (x + w + 2);  ClipRect.y1 = y + 61;  OldClipRect = WM_SetUserClipRect(&ClipRect);  GUI_AA_SetFactor(4);  GUI_AA_EnableHiRes();  x <<= 2;  y <<= 2;  w = (w - 2) * (100 - Status) / 25 + 12;  w = (d > 0) ? w : -w;  h = h * (100 - Status) / 25 + 4;  GUI_SetPenSize(3);  GUI_SetPenShape(GUI_PS_ROUND);  GUI_SetColor(0xA08080);  GUI_AA_DrawLine(x + (60 * d), y + 240, x, y + 240);   GUI_SetPenShape(GUI_PS_FLAT);  GUI_SetColor(0x00C0FF);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -