Blog Image

guivi

About the blog

In this blog I will keep track of projects I develop though out this year and may be in the future. For now it is juts a testing ground for developing the blog itself but I hope as I put more material it will become a good place for me to hold information.

List Video and Audio capture devices

C/C++ Programming, OpenCV & C++ Posted on 30 Apr, 2021 12:47:35
static HRESULT EnumerateDevices(REFGUID category, IEnumMoniker **ppEnum)
{
	// Create the System Device Enumerator.
	ICreateDevEnum *pDevEnum;
	HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
		CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pDevEnum));

	if (SUCCEEDED(hr))
	{
		// Create an enumerator for the category.
		hr = pDevEnum->CreateClassEnumerator(category, ppEnum, 0);
		if (hr == S_FALSE)
		{
			hr = VFW_E_NOT_FOUND;  // The category is empty. Treat as an error.
		}
		pDevEnum->Release();
	}
	return hr;
}

std::vector<CString> UpdatecameraLists()
{
	IMoniker *pMoniker = NULL;
	CString str;
	LPCTSTR buf;
	HRESULT hr;
	IEnumMoniker *pEnum;
	IPropertyBag *pPropBag;
	VARIANT var;


	hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);

	hr = EnumerateDevices(CLSID_VideoInputDeviceCategory, &pEnum);
	std::vector<CString> _camlist;

	if (SUCCEEDED(hr))
	{
		while (pEnum->Next(1, &pMoniker, NULL) == S_OK)
		{
			hr = pMoniker->BindToStorage(0, 0, IID_PPV_ARGS(&pPropBag));
			if (FAILED(hr))
			{
				pMoniker->Release();
				continue;
			}

			VariantInit(&var);

			// Get description or friendly name.
			hr = pPropBag->Read(L"Description", &var, 0);
			if (FAILED(hr))
			{
				hr = pPropBag->Read(L"FriendlyName", &var, 0);
			}
			if (SUCCEEDED(hr))
			{
				str.Format(L"%ls\n", var.bstrVal);
				buf = str;
				_camlist.push_back(str);
				//m_cameras.AddString(buf);
				VariantClear(&var);
			}

			hr = pPropBag->Write(L"FriendlyName", &var);

			// WaveInID applies only to audio capture devices.
			hr = pPropBag->Read(L"WaveInID", &var, 0);
			if (SUCCEEDED(hr))
			{
				printf("WaveIn ID: %d\n", var.lVal);
				VariantClear(&var);
			}

			hr = pPropBag->Read(L"DevicePath", &var, 0);
			if (SUCCEEDED(hr))
			{
				// The device path is not intended for display.
				printf("Device path: %S\n", var.bstrVal);
				VariantClear(&var);
			}

			pPropBag->Release();
			pMoniker->Release();
		}
		pEnum->Release();
	}
	CoUninitialize();

	return _camlist;
}


Good links for FreeRTOS

AWS FreeRTOS, Digital Electronics Posted on 04 Mar, 2021 07:53:50

https://aws.amazon.com/blogs/publicsector/creating-a-serverless-gps-monitoring-and-alerting-solution/

https://docs.aws.amazon.com/freertos/latest/userguide/getting_started_espressif.html

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/hw-reference/esp32/get-started-devkitc.html

Not great but some explanation about AWS

https://github.com/aws/amazon-freertos



Check Available Serial Pots

C/C++ Programming Posted on 30 Jan, 2021 23:02:24
void CDialog::SelectComPort()
{
	TCHAR lpTargetPath[5000]; // buffer to store the path of the COMPORTS
	DWORD test;
	bool gotPort = 0; // in case the port is not found
	m_serialList.ResetContent();

	for (int i = 0; i < 255; i++) // checking ports from COM0 to COM255
	{
		CString str;
		str.Format(_T("%d"), i);
		CString ComName = CString("COM") + CString(str); // converting to COM0, COM1, COM2

		test = QueryDosDevice(ComName, lpTargetPath, 5000);

		// Test the return value and error if any
		if (test != 0) //QueryDosDevice returns zero if it didn't find an object
		{
			m_serialList.AddString((CString)ComName); // add to the ComboBox
			
			gotPort = 1; // found port
		}

		if (::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
		{
			lpTargetPath[10000]; // in case the buffer got filled, increase size of the buffer.
			continue;
		}

	}

	if (!gotPort) // if not port
		m_serialList.AddString((CString)"No Active Ports Found"); // to display error message incase no ports found

}


On Device Arrived/Removed

C/C++ Programming Posted on 30 Jan, 2021 23:01:31
BEGIN_MESSAGE_MAP(CDialog, CDialogEx)
	ON_WM_DEVICECHANGE()
END_MESSAGE_MAP()

BOOL CDialog::OnDeviceChange( UINT wParam, DWORD_PTR  lParam)
{

}


cv::Mat paint in MFC

OpenCV & C++ Posted on 30 Jan, 2021 22:59:36
void CWnd::OnPaint()
{
    CPaintDC dc(this); // device context for painting
                       // TODO: Add your message handler code here
                       // Do not call CWnd::OnPaint() for painting messages

    if (!m_cvImage.empty()) {
        CRect rect;
        GetClientRect(&rect);
        BITMAPINFO bmi = { 0 };
        bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader);
        bmi.bmiHeader.biCompression = BI_RGB;
        bmi.bmiHeader.biWidth = m_cvImage.cols;
        // note that bitmaps default to bottom-up, use negative height to
        // represent top-down
        //
        bmi.bmiHeader.biHeight = m_cvImage.rows * -1;
        bmi.bmiHeader.biPlanes = 1;
        bmi.bmiHeader.biBitCount = 24; // 32 if you use RGBQUADs for the bits
        SetStretchBltMode(dc, STRETCH_HALFTONE);
        StretchDIBits(dc,
            0, 0,
            rect.Width(), rect.Height(),
            0, 0,
            bmi.bmiHeader.biWidth, abs(bmi.bmiHeader.biHeight),
            m_cvImage.data,
            &bmi,
            DIB_RGB_COLORS,
            SRCCOPY);
    }
}



Child Education

Education Posted on 14 Jan, 2021 19:21:43

https://www.k5learning.com



Adding folder to Dll in Visual studio Win32 apps

C/C++ Programming, Visual Studio Posted on 08 Jan, 2021 22:19:01
  1. Go to project properties (Alt+F7)
  2. Under Debugging, look to the right
  3. There’s an Environment field.
  4. Add your relative path there (relative to vcproj folder) i.e. ..\some-framework\lib by appending PATH=%PATH%;$(ProjectDir)\some-framework\lib or prepending to the path PATH=C:\some-framework\lib;%PATH%
  5. Hit F5 (debug) again and it should work.


Check last upgrade date of Debian base distros

Linux Posted on 05 Jan, 2021 22:25:02
#!/bin/bash
#####################################################################
# BRIEF DESCRIPTION
# This script looks for the keyword 'upgrade' in the log files
# then it compares the date of all occurrences of the key word and
# and prints to shell the most recent date.
#####################################################################

# Check numer of availabe log dpkg files 
mapfile -t files < <(ls /var/log/dpkg.log*)
# Debug print
# echo ${#files[@]}

# Iterate over all log files found
for ((i=0; i <${#files[@]}; i++))
do 
    # Debug print
    # echo ${files[i]}
    
    # grep a log file for upgrades store in an array.
    mapfile -t lines < <(grep upgrade ${files[i]})
    
    # Debug print
    # echo ${#lines[@]}
    
    # Store the number of lines on the last grep file
    leng=${#lines[@]}
    # loop through each line in thearray
    for ((j=0; j<leng;j++)) do
	# If length of $STRING is larger than one compare the new $DATE with the $STRING
        # If the date is more resent store the new date in $STRING 
        if [ -n $STRING ] 
        then
	    DATE=${lines[j]:0:10}
            # echo $DATE
	    if [[ "$STRING" < "$DATE" ]]; 
	    then
		STRING="$DATE"
	    fi
        else
	# Initialize the $STRING
            DATE=${lines[j]:0:10}
	    STRING="$DATE"
	fi
    done
done

# Output the most recent upgrade date of the system if any was found.
if [[ -n $STRING ]]
then
    echo "$STRING"
fi


Next »