Exemplo n.º 1
0
	ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
		ListNode * result = new ListNode(0);
		ListNode * it=result;
		int remain = 0;
		while (l1!=NULL&&l2!=NULL) {
			handle(it,l1->val,l2->val,remain);
			l1 = l1->next;
			l2 = l2->next;
		}
		while (l1!=NULL) {
			handle2(it,l1->val,remain);
			l1 = l1->next;
		}
		while (l2!=NULL) {
			handle2(it,l2->val,remain);
			l2 = l2->next;
		}
		if (remain)
		{
			it->next = new ListNode(remain);
		}
		return result->next;
	}
Exemplo n.º 2
0
bool getKeyboardOrder(MotorOdom05& motor)
{
  char rep;
  read(0,&rep,1);
  switch (rep) {
    // motor
  case 27 : 
    read(0,&rep,1); 
    read(0,&rep,1);
    switch (rep) {
      case 'A' : handle8(); break;
      case 'B' : handle2(); break;
      case 'D' : handle4(); break;
      case 'C' : handle6(); break;
      }
    break;
  case '8' : handle8(); break;
  case '2' : handle2(); break;
  case '4' : handle4(); break;
  case '6' : handle6(); break;
    // emergency stop
  case '5' :
  case ' ' : 
    setEmergencyStopOrder();
    break; 
  case 'r' :
  case 'R' : 
    motor.reset();
    order.speedLeft=0;
    order.speedRight=0;
    return true;
  case 'p' :
  case 'P' :
      { 
    MotorPosition posLeft, posRight;
    CoderPosition codLeft, codRight;
    if (useCache_) {
        motor.getCacheMotorPosition(posLeft, posRight);
        motor.getCacheOdomPosition(codLeft, codRight);
    } else {
        motor.getMotorPosition(posLeft, posRight);
        motor.getOdomPosition(codLeft, codRight);
    }
    printf("Position: hctl: l=%d,\tr=%d\t odometer:l=%d,\tr=%d\n", 
           posLeft, posRight, codLeft, codRight);
      }
    break; 
  case 'w' :
  case 'W' :
    MotorPWM pwmLeft, pwmRight;
    if (useCache_) {
        motor.getCacheMotorPwm(pwmLeft, pwmRight); 
    } else {
        motor.getMotorPwm(pwmLeft, pwmRight); 
    }
    printf("PWM: left=%d,\tright=%d\n",pwmLeft, pwmRight);
    break;    
  case 'c' :
  case 'C' :
      useCache_=!useCache_;
      printf("useCache=%s\n", useCache_?"TRUE":"FALSE");
      break;    
  case 'h' :
  case 'H' : 
    showUsage();
    break;  
    // exit
  case 'q': 
  case 'Q':
  case '-':
    return false;
    break;
  default:
      break;
  }
  checkMotorOrder();
  if (useCache_) {
      motor.setSpeedAndCachePosition(order.speedLeft, order.speedRight);
  } else {
      motor.setSpeed(order.speedLeft, order.speedRight);
  }
  return true;
}
Exemplo n.º 3
0
	MojErr handle2Cancel(int val, const char* val2)
	{
		handle2(val, val2);
		m_slot2Cancel.cancel();
		return MojErrNone;
	}
Exemplo n.º 4
0
// Save icon referenced by handle 'hIcon' as file with name 'szPath'.
// The generated ICO file has the color depth specified in 'nColorBits'.
//
bool SaveIcon(HICON hIcon, DWORD& szSize ,int nColorBits, const TCHAR* szPath)
{
    ASSERT(nColorBits == 4 || nColorBits == 8 || nColorBits == 24 || nColorBits == 32);

    if (offsetof(ICONDIRENTRY, nOffset) != 12)
    {
       return false;
    }

    CDC dc;
    dc.Attach(::GetDC(NULL)); // ensure that DC is released when function ends
    // Open file for writing:
    CFile file;
    if (!file.Open(szPath, CFile::modeWrite | CFile::modeCreate))
    {
        return false;
    }
    // Write header:
    UCHAR icoHeader[6] = { 0, 0, 1, 0, 1, 0 }; // ICO file with 1 image
    file.Write(icoHeader, sizeof(icoHeader));
    // Get information about icon:
    ICONINFO iconInfo;
    GetIconInfo(hIcon, &iconInfo);
    CGdiHandle handle1(iconInfo.hbmColor), handle2(iconInfo.hbmMask); // free bitmaps when function ends
    BITMAPINFO bmInfo = { 0 };
    bmInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmInfo.bmiHeader.biBitCount = 0;    // don't get the color table     
    if (!GetDIBits(dc, iconInfo.hbmColor, 0, 0, NULL, &bmInfo, DIB_RGB_COLORS))
    {
        return false;
    }
    // Allocate size of bitmap info header plus space for color table:
    int nBmInfoSize = sizeof(BITMAPINFOHEADER);
    if (nColorBits < 24)
    {
        nBmInfoSize += sizeof(RGBQUAD) * (int)(1 << nColorBits);
    }
    CAutoVectorPtr<UCHAR> bitmapInfo;
    bitmapInfo.Allocate(nBmInfoSize);
    BITMAPINFO* pBmInfo = (BITMAPINFO*)(UCHAR*)bitmapInfo;
    memcpy(pBmInfo, &bmInfo, sizeof(BITMAPINFOHEADER));

    // Get bitmap data:
    ASSERT(bmInfo.bmiHeader.biSizeImage != 0);
    CAutoVectorPtr<UCHAR> bits;
    bits.Allocate(bmInfo.bmiHeader.biSizeImage);
    pBmInfo->bmiHeader.biBitCount = nColorBits;
    pBmInfo->bmiHeader.biCompression = BI_RGB;
    if (!GetDIBits(dc, iconInfo.hbmColor, 0, bmInfo.bmiHeader.biHeight, (UCHAR*)bits, pBmInfo, DIB_RGB_COLORS))
    {
         return false;
    }
    // Get mask data:
    BITMAPINFO maskInfo = { 0 };
    maskInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    maskInfo.bmiHeader.biBitCount = 0;  // don't get the color table     
    if (!GetDIBits(dc, iconInfo.hbmMask, 0, 0, NULL, &maskInfo, DIB_RGB_COLORS))
    {
        return false;
    }
    ASSERT(maskInfo.bmiHeader.biBitCount == 1);
    CAutoVectorPtr<UCHAR> maskBits;
    maskBits.Allocate(maskInfo.bmiHeader.biSizeImage);
    CAutoVectorPtr<UCHAR> maskInfoBytes;
    maskInfoBytes.Allocate(sizeof(BITMAPINFO) + 2 * sizeof(RGBQUAD));
    BITMAPINFO* pMaskInfo = (BITMAPINFO*)(UCHAR*)maskInfoBytes;
    memcpy(pMaskInfo, &maskInfo, sizeof(maskInfo));
    if (!GetDIBits(dc, iconInfo.hbmMask, 0, maskInfo.bmiHeader.biHeight, (UCHAR*)maskBits, pMaskInfo, DIB_RGB_COLORS))
    {
        return false;
    }
    // Write directory entry:
    ICONDIRENTRY dir;
    dir.nWidth = (UCHAR)pBmInfo->bmiHeader.biWidth;
    dir.nHeight = (UCHAR)pBmInfo->bmiHeader.biHeight;
    dir.nNumColorsInPalette = (nColorBits == 4 ? 16 : 0);
    dir.nReserved = 0;
    dir.nNumColorPlanes = 0;
    dir.nBitsPerPixel = pBmInfo->bmiHeader.biBitCount;
    dir.nDataLength = pBmInfo->bmiHeader.biSizeImage + pMaskInfo->bmiHeader.biSizeImage + nBmInfoSize;
    dir.nOffset = sizeof(dir) + sizeof(icoHeader);
    file.Write(&dir, sizeof(dir));
    // Write DIB header (including color table):
    int nBitsSize = pBmInfo->bmiHeader.biSizeImage;
    pBmInfo->bmiHeader.biHeight *= 2; // because the header is for both image and mask
    pBmInfo->bmiHeader.biCompression = 0;
    pBmInfo->bmiHeader.biSizeImage += pMaskInfo->bmiHeader.biSizeImage; // because the header is for both image and mask
    file.Write(&pBmInfo->bmiHeader, nBmInfoSize);
    // Write image data:
    file.Write((UCHAR*)bits, nBitsSize);

    // Write mask data:
    file.Write((UCHAR*)maskBits, pMaskInfo->bmiHeader.biSizeImage);
	szSize = file.GetLength();
    file.Close();
    return true;
}