台灣最大程式設計社群網站
線上人數
1945
 
會員總數:245979
討論主題:189557
歡迎您免費加入會員
討論區列表 >> Linux / Unix >> 嵌入式系統程式大問題
[]  
[我要回覆]
1
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
嵌入式系統程式大問題
價值 : 100 QP  點閱數:4616 回應數:2
樓主

阿雍
門外漢
0 2
8 0
發送站內信

DMA-2440XP教學平台

是使用Visual Studio 2005的MFC智慧型裝置應用程式來寫程式

想請問如何撰寫一個程式,利用觸控式面板來控制平台上面的LED8X8來動作


下面是觸控式面板對LED控制的程式


#include "stdafx.h"
#include "Led.h"
#include "LedDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CLedDlg K

CLedDlg::CLedDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLedDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

m_bitmap = 134;
m_on1 = false;
m_on2 = false;
m_on3 = false;
m_on4 = false;

m_control1 = 0;
m_control2 = 1;
m_control3 = 2;
m_control4 = 3;
}

void CLedDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CLedDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
ON_WM_SIZE()
#endif
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_CANCEL, &CLedDlg::OnBnClickedCancel)
ON_WM_PAINT()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_LED1, &CLedDlg::OnBnClickedLed1)
ON_BN_CLICKED(IDC_LED2, &CLedDlg::OnBnClickedLed2)
ON_BN_CLICKED(IDC_LED3, &CLedDlg::OnBnClickedLed3)
ON_BN_CLICKED(IDC_LED4, &CLedDlg::OnBnClickedLed4)
// ON_WM_ENDSESSION()
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()


// CLedDlg

BOOL CLedDlg::OnInitDialog()
{
CDialog::OnInitDialog();
I
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);

this->MoveWindow(0, 0, 800, 480);

m_btncancel.SubclassDlgItem(IDC_CANCEL, this);
m_btncancel.LoadBitmaps(IDB_CANCEL1, IDB_CANCEL2);
m_btncancel.MoveWindow(2, 0, 73, 43);

m_btnled1.SubclassDlgItem(IDC_LED1, this);
m_btnled1.LoadBitmaps(IDB_LED_M, IDB_LED_L);
m_btnled1.MoveWindow(278, 202, 57, 63);

m_btnled2.SubclassDlgItem(IDC_LED2, this);
m_btnled2.LoadBitmaps(IDB_LED_M, IDB_LED_L);
m_btnled2.MoveWindow(341, 202, 57, 63);

m_btnled3.SubclassDlgItem(IDC_LED3, this);
m_btnled3.LoadBitmaps(IDB_LED_M, IDB_LED_L);
m_btnled3.MoveWindow(405, 202, 57, 63);
m_btnled4.SubclassDlgItem(IDC_LED4, this);
m_btnled4.LoadBitmaps(IDB_LED_M, IDB_LED_L);
m_btnled4.MoveWindow(468, 202, 57, 63);

m_stacartoon.SubclassDlgItem(IDC_CARTOON, this);
m_bitcartoon.LoadBitmapW(IDB_LED1);
m_stacartoon.SetBitmap(m_bitcartoon);
m_stacartoon.MoveWindow(0, 163, 224,187);



this->ShowWindow(SW_SHOW);
this->UpdateWindow();

m_btncancel.ShowWindow(SW_SHOW);
m_btnled1.ShowWindow(SW_SHOW);
m_btnled2.ShowWindow(SW_SHOW);
m_btnled3.ShowWindow(SW_SHOW);
m_btnled4.ShowWindow(SW_SHOW);
m_stacartoon.ShowWindow(SW_SHOW);

m_timer = SetTimer(1, 800, NULL);

m_hled = CreateFile(TEXT("LED1:"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);
if(m_hled == INVALID_HANDLE_VALUE )
{
::MessageBox(NULL,L"Open LED Driver error!",NULL,MB_OK);
}

m_hopen = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, _T("LED_OPEN"));
VERIFY(NULL != m_hopen);
m_hclose = ::OpenEvent(EVENT_ALL_ACCESS, FALSE, _T("LED_CLOSE"));
VERIFY(NULL != m_hclose);
if(m_hopen)
{
SetEvent(m_hopen);
}

return TRUE; c
}

#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CLedDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
if (AfxIsDRAEnabled())
{
DRA::RelayoutDialog(
AfxGetResourceHandle(),
this->m_hWnd,
DRA::GetDisplayMode() != DRA::Portrait ?
MAKEINTRESOURCE(IDD_LED_DIALOG_WIDE) :
MAKEINTRESOURCE(IDD_LED_DIALOG));
}
}
#endif


void CLedDlg::OnBnClickedCancel()
{
// TODO: Add your control notification handler code here
if(m_hclose)
{
SetEvent(m_hclose);
CloseHandle(m_hclose);
}
if(m_hopen)
{
CloseHandle(m_hopen);
}
if(m_hled)
{
CloseHandle(m_hled);
}
CDialog::OnCancel();
}

void CLedDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rClient;
GetClientRect(&rClient);
HDC hdc = ::GetDC(this->GetSafeHwnd());
HDC mdc = CreateCompatibleDC(hdc);
HBITMAP bmpmdc = CreateCompatibleBitmap(hdc, rClient.right, rClient.bottom);
HBITMAP oldmdc = (HBITMAP)SelectObject(mdc, bmpmdc);
CBitmap bg ;
bg.LoadBitmapW(IDB_BACKGROUND);
HDC bgdc = CreateCompatibleDC(hdc);
SelectObject(bgdc, (HBITMAP)bg);
BitBlt(mdc, 0, 0, rClient.right, rClient.bottom, bgdc, 0, 0, SRCCOPY);
BitBlt(hdc, 0, 0, rClient.right, rClient.bottom, mdc, 0, 0, SRCCOPY);
SelectObject(mdc, oldmdc);
DeleteObject(bmpmdc);
::ReleaseDC(this->GetSafeHwnd(), hdc);
DeleteDC(mdc);
DeleteDC(bgdc);
// Do not call CDialog::OnPaint() for painting messages
}

void CLedDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent == m_timer)
{
if(m_bitmap == 137)
m_bitmap = 133;
m_bitmap++;
m_bitcartoon.LoadBitmapW(m_bitmap);
m_stacartoon.SetBitmap(m_bitcartoon);
}
CDialog::OnTimer(nIDEvent);
}

void CLedDlg::OnBnClickedLed1()
{
// TODO: Add your control notification handler code here
if(m_on1)
{
::DeviceIoControl(m_hled, LED_OFF, &m_control1, NULL, NULL, NULL, NULL, NULL);
m_btnled1.LoadBitmaps(IDB_LED_M, IDB_LED_L);
m_btnled1.RedrawWindow();
m_on1 = false;
}
else
{
::DeviceIoControl(m_hled, LED_ON, &m_control1, NULL, NULL, NULL, NULL, NULL);
m_btnled1.LoadBitmaps(IDB_LED_L, IDB_LED_M);
m_btnled1.RedrawWindow();
m_on1 = true;;
}
}

void CLedDlg::OnBnClickedLed2()
{
// TODO: Add your control notification handler code here
if(m_on2)
{
::DeviceIoControl(m_hled, LED_OFF, &m_control2, NULL, NULL, NULL, NULL, NULL);
m_btnled2.LoadBitmaps(IDB_LED_M, IDB_LED_L);
m_btnled2.RedrawWindow();
m_on2 = false;
}
else
{
::DeviceIoControl(m_hled, LED_ON, &m_control2, NULL, NULL, NULL, NULL, NULL);
m_btnled2.LoadBitmaps(IDB_LED_L, IDB_LED_M);
m_btnled2.RedrawWindow();
m_on2 = true;;
}
}

void CLedDlg::OnBnClickedLed3()
{
// TODO: Add your control notification handler code here
if(m_on3)
{
::DeviceIoControl(m_hled, LED_OFF, &m_control3, NULL, NULL, NULL, NULL, NULL);
m_btnled3.LoadBitmaps(IDB_LED_M, IDB_LED_L);
m_btnled3.RedrawWindow();
m_on3 = false;
}
else
{
::DeviceIoControl(m_hled, LED_ON, &m_control3, NULL, NULL, NULL, NULL, NULL);
m_btnled3.LoadBitmaps(IDB_LED_L, IDB_LED_M);
m_btnled3.RedrawWindow();
m_on3 = true;;
}
}

void CLedDlg::OnBnClickedLed4()
{
// TODO: Add your control notification handler code here
if(m_on4)
{
::DeviceIoControl(m_hled, LED_OFF, &m_control4, NULL, NULL, NULL, NULL, NULL);
m_btnled4.LoadBitmaps(IDB_LED_M, IDB_LED_L);
m_btnled4.RedrawWindow();
m_on4 = false;
}
else
{
::DeviceIoControl(m_hled, LED_ON, &m_control4, NULL, NULL, NULL, NULL, NULL);
m_btnled4.LoadBitmaps(IDB_LED_L, IDB_LED_M);
m_btnled4.RedrawWindow();
m_on4 = true;;
}
}

//void CLedDlg::OnEndSession(BOOL bEnding)
//{
// CDialog::OnEndSession(bEnding);
//
// // TODO: Add your message handler code here
//}

BOOL CLedDlg::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default

return true;
}


『請各位幫個忙,我已經研究一個多禮拜也想不出到底該怎麼寫』

搜尋相關Tags的文章: [ 嵌入式系統、C++、WinCE ] ,
本篇文章發表於2009-06-26 11:56
1樓
回應

Star-o-0
檢舉此回應
這個範例碼我也有
他的裝置控制是靠以下兩行來驅動
m_hled = CreateFile(TEXT("LED1:"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0);

::DeviceIoControl(m_hled, LED_OFF, &m_control2, NULL, NULL, NULL, NULL, NULL);

問題就出在開啟的裝置有問題
也就是LED1
這個是設好的
你可以去找找看他的驅動程式裡
本篇文章回覆於2009-07-30 02:47
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
2樓
回應

艾鍗學院
檢舉此回應
最近在網路找到好多嵌入式Linux設計、Linux程式設計、C程式設計、Linux 驅動程式設計、USB韌體設計 相關的免費線上教學網站,
講解的滿專業.聽完有滿有收穫,你可以在這邊找找看你需要的答案!

http://www.powercam.cc/home.php?user=ittraining&f=slide&v=list&fid=5564

•覺得不錯也可以分享給別人,知識大家起分享!

本篇文章回覆於2010-10-05 20:21
== 簽名檔 ==
--未登入的會員無法查看對方簽名檔--
   
1

回覆
如要回應,請先登入.