2012-12-20 3 views
2

Logitech LCD SDK에 문제가 있습니다. 모든 것은 작동하지만 2 가지 간단한 것은 작동하지 않습니다. 먼저 진행률 표시 줄을 작동시킬 수 없습니다. 매 초마다 progressbar 값을 업데이트하고 화면을 업데이트합니다. 아무 일도 없었어. 나는 0에서 100 사이의 값과 0에서 1까지 차이가없는 값을 테스트했다.Logitech LCD SDk (C++)

두 번째 문제점은 VS2012의 이미지입니다. C++ Dll에서 이미지를로드 할 수 없습니다. 아래 코드는 화면의 모든 데이터가 포함 된 Logitech 클래스입니다. 전체 소스는 BitBucket입니다.

누군가가 도와 주길 바랍니다.

편집 : 문제는 진행률 표시 줄에 있습니다. 나머지 모든 코드는 예를 들어 작동합니다. 그것은 로지텍 LCD 화면, 심지어 진행 표시 줄, 시간, 모든 것을 그립니다 ...하지만 실제 문제는 진행 표시 줄의 진행에 있습니다. 바의 배경이 완벽 해 보이지만 진행 표시 줄이 움직이지 않는다면 약 15 % 정도의 진행률로 고정 된 것처럼 보입니다. 일반적으로 진행 상황은 음악 시간에 링크되어야합니다. 예를 들어 음악 파일이 3 분이면 180 초가 100 % 진행으로 넘어 가야합니다. 하지만이 작품은 나던!

//----------------------------------------------------------------- 
// Logitech File 
// C++ Source - Logitech.cpp - version 2012 v1.0 
//----------------------------------------------------------------- 

//----------------------------------------------------------------- 
// Include Files 
//----------------------------------------------------------------- 
#include "stdafx.h" 
#include "Logitech.h" 

//----------------------------------------------------------------- 
// Logitech methods 
//----------------------------------------------------------------- 

//This LogitechObject is a instance of the Logitech class for using in the thread 
Logitech * Logitech::LogitechObject; 

Logitech::Logitech(): stopthread(false), firstTime(true), position(0), duration(0) 
{ 
    LogitechObject = this; 
} 

Logitech::~Logitech() 
{ 
    stopthread = true; 
    this->state = StatePlay::Undefined; 
    timerThread.detach(); 
} 

bool Logitech::getFirstTime() 
{ 
    return firstTime; 
} 

//Initialise Logitech LCD 
BOOL Logitech::OnInitDialog() 
{ 
    HRESULT hRes = m_lcd.Initialize(_T("MusicBee"), LG_DUAL_MODE, FALSE, TRUE); 

    if (hRes != S_OK) 
    { 
     return FALSE; 
    } 

    //Create home screen Logitech Color LCD 
    if(m_lcd.IsDeviceAvailable(LG_COLOR)) 
    { 
     m_lcd.ModifyDisplay(LG_COLOR); 
     logo = m_lcd.AddText(LG_STATIC_TEXT, LG_BIG, DT_CENTER, LGLCD_BW_BMP_WIDTH); 
     m_lcd.SetOrigin(logo, 0, 50); 
     m_lcd.SetText(logo, _T("MusicBee")); 
     m_lcd.Update(); 
    } 

    //Create home screen Logitech Monochrome LCD 
    else if(m_lcd.IsDeviceAvailable(LG_MONOCHROME)) 
    { 
     m_lcd.ModifyDisplay(LG_MONOCHROME); 
     logo = m_lcd.AddText(LG_STATIC_TEXT, LG_BIG, DT_CENTER, LGLCD_BW_BMP_WIDTH); 
     m_lcd.SetOrigin(logo, 0, 5); 
     m_lcd.SetText(logo, _T("MusicBee")); 
     m_lcd.Update(); 
    } 

    //Start thread 
    timerThread = thread(&Logitech::startThread); 

    return TRUE; // return TRUE unless you set the focus to a control 
} 

//Create playing screen for Logitech Monochrome LCD 
VOID Logitech::createMonochrome() 
{ 
    m_lcd.RemovePage(0); 
    m_lcd.AddNewPage(); 
    m_lcd.ShowPage(0); 

    if (logo != 0) 
    { 
     delete logo; 
     logo = 0; 
    } 

    artist = m_lcd.AddText(LG_SCROLLING_TEXT, LG_MEDIUM, DT_CENTER, LGLCD_BW_BMP_WIDTH); 
    m_lcd.SetOrigin(artist, 0, 0); 

    title = m_lcd.AddText(LG_SCROLLING_TEXT, LG_MEDIUM, DT_CENTER, LGLCD_BW_BMP_WIDTH); 
    m_lcd.SetOrigin(title, 0, 13); 

    progressbar = m_lcd.AddProgressBar(LG_FILLED); 
    m_lcd.SetProgressBarSize(progressbar, 136, 5); 
    m_lcd.SetOrigin(progressbar, 12, 38); 

    time = m_lcd.AddText(LG_STATIC_TEXT, LG_SMALL, DT_LEFT, 80); 
    m_lcd.SetOrigin(time, 12, 29); 

    time1 = m_lcd.AddText(LG_STATIC_TEXT, LG_SMALL, DT_LEFT, 80); 
    m_lcd.SetOrigin(time1, 125, 29); 

    /* playIcon = static_cast<HICON>(LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDB_PNG2), IMAGE_BITMAP, 16, 16, LR_MONOCHROME)); 
    playIconHandle = m_lcd.AddIcon(playIcon, 16, 16); 
    m_lcd.SetOrigin(playIconHandle, 2, 29);*/ 

    firstTime = false; 
    changeArtistTitle(this->artistString, this->albumString, this->titleString, this->durationString, this->position); 
} 

//Create playing screen for Logitech Color LCD 
VOID Logitech::createColor() 
{ 
    m_lcd.RemovePage(0); 
    m_lcd.AddNewPage(); 
    m_lcd.ShowPage(0); 

    if (logo != 0) 
    { 
     delete logo; 
     logo = 0; 
    } 

    artist = m_lcd.AddText(LG_SCROLLING_TEXT, LG_MEDIUM, DT_CENTER, 320); 
    m_lcd.SetOrigin(artist, 5, 5); 

    album = m_lcd.AddText(LG_SCROLLING_TEXT, LG_MEDIUM, DT_CENTER, 320); 
    m_lcd.SetOrigin(album, 5, 30); 

    title = m_lcd.AddText(LG_SCROLLING_TEXT, LG_MEDIUM, DT_CENTER, 320); 
    m_lcd.SetOrigin(title, 5, 55); 

    time = m_lcd.AddText(LG_STATIC_TEXT, LG_SMALL, DT_LEFT, 80); 
    m_lcd.SetOrigin(time, 5, 80); 

    time1 = m_lcd.AddText(LG_STATIC_TEXT, LG_SMALL, DT_LEFT, 80); 
    m_lcd.SetOrigin(time1, 275, 80); 

    progressbar = m_lcd.AddProgressBar(LG_DOT_CURSOR);//320×240 pixel color screen 
    m_lcd.SetProgressBarSize(progressbar, 310, 15); 
    m_lcd.SetOrigin(progressbar, 5, 100); 

    time1 = m_lcd.AddText(LG_STATIC_TEXT, LG_SMALL, DT_LEFT, 80); 
    m_lcd.SetOrigin(time1, 275, 80); 

    /*playIcon = static_cast<HICON>(LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_PNG1), IMAGE_ICON, 16, 16, LR_COLOR)); 
    playIconHandle = m_lcd.AddIcon(playIcon, 16, 16); 
    m_lcd.SetOrigin(playIconHandle, 5, 29);*/ 

    firstTime = false; 
    changeArtistTitle(this->artistString, this->albumString, this->titleString, this->durationString, this->position); 
} 

void Logitech::startThread() 
{ 
    while(!LogitechObject->stopthread) 
    { 
     this_thread::sleep_for(chrono::milliseconds(500)); 

     if(!LogitechObject->stopthread && LogitechObject->progressbar != NULL) 
     { 
      //Update progressbar and position time on the screen after 1 second of music. 
      if(LogitechObject->state == StatePlay::Playing) 
      { 
       this_thread::sleep_for(chrono::milliseconds(500)); 
       LogitechObject->position++; 

       LogitechObject->m_lcd.SetProgressBarPosition(LogitechObject->progressbar, static_cast<FLOAT>(((float)LogitechObject->position/LogitechObject->duration)*100)); 
       LogitechObject->m_lcd.SetText(LogitechObject->time, LogitechObject->getPositionString().c_str()); 
      } 

      //If music stopped then the progressbar and time must stop immediately 
      else if(LogitechObject->state == StatePlay::Stopped) 
      { 
       LogitechObject->position = 0; 
       LogitechObject->m_lcd.SetProgressBarPosition(LogitechObject->progressbar, 0); 
       LogitechObject->m_lcd.SetText(LogitechObject->time, LogitechObject->getPositionString().c_str()); 
      } 

      LogitechObject->m_lcd.Update(); 
     } 
    } 
} 

void Logitech::changeArtistTitle(wstring artistStr, wstring albumStr, wstring titleStr, wstring duration, int position) 
{ 
    this->artistString = artistStr; 
    this->albumString = albumStr; 
    this->titleString = titleStr; 
    this->durationString = duration; 
    this->position = position; 
    this->duration = getDuration(duration); 

    if(!firstTime) 
    { 
     if(m_lcd.IsDeviceAvailable(LG_COLOR)) 
     { 
      m_lcd.SetText(album, albumStr.c_str()); 
     } 


     m_lcd.SetText(artist, artistStr.c_str()); 
     m_lcd.SetText(title, titleStr.c_str()); 
     m_lcd.SetText(time, getPositionString().c_str()); 

     string s(duration.begin(), duration.end()); 

     if(s.size() < 5) 
     { 
      s = "0" + s; 
     } 

     wstring ws(s.begin(), s.end()); 

     m_lcd.SetText(time1, ws.c_str()); 
     ws.clear(); 

     ///*playIcon = static_cast<HICON>(LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_PNG1), IMAGE_ICON, 16, 16, LR_COLOR)); 
     //playIconHandle = m_lcd.AddIcon(playIcon, 16, 16); 
     //m_lcd.SetOrigin(playIconHandle, 5, 29);*/ 

     m_lcd.Update(); 
     artistStr.clear(); 
     albumStr.clear(); 
     titleStr.clear(); 
     duration.clear(); 
    } 
} 

//Set current playing position 
void Logitech::setPosition(int pos) 
{ 
    this->position = pos/1000; 
    m_lcd.SetText(time, getPositionString().c_str()); 
    m_lcd.Update(); 
} 

//Change play state of the current playing song 
void Logitech::changeState(StatePlay state) 
{ 
    this->state = state; 

    if(state == StatePlay::Playing && firstTime) 
    { 
     if(m_lcd.IsDeviceAvailable(LG_COLOR)) 
     { 
      createColor(); 
     } 

     else if(m_lcd.IsDeviceAvailable(LG_MONOCHROME)) 
     { 
      createMonochrome(); 
     } 
    } 
} 

//Gets the music duration 
int Logitech::getDuration(wstring duration) 
{ 
    string s(duration.begin(), duration.end()); 

    int position = s.find(":"); 
    string minutes = s.substr(0, s.size() -position); 
    string seconds = s.substr(position); 
    int minutesInt = atoi(minutes.c_str()); 
    int secondsInt = atoi(seconds.c_str()); 

    return (minutesInt *60) + secondsInt; 
} 

//Change current position in string 
wstring Logitech::getPositionString() 
{ 
    string minutes = to_string((int)position /60); 
    string seconds = to_string((int)position%60); 

    if(minutes.size() < 2) 
    { 
     minutes = "0" + minutes; 
    } 

    if(seconds.size() < 2) 
    { 
     seconds = "0" + seconds; 
    } 

    string time = minutes + ":" + seconds; 

    return wstring(time.begin(), time.end()); 
} 
+0

당신이 올린 내용은 당신을 도울만큼 많은 것을 제공하지 않습니다. 당신은 "모든 것이 효과가 있지만 2 가지 간단한 것은 효과가 없습니다"라고 말하지만 그것이 "모든 것"이 효과가 있다는 것은 분명하지 않습니다. 디스플레이에 아무 것도 인쇄하지 않습니까? 진행률 표시 줄이 처음 인쇄되지만 후속 인쇄는 수행하지 않습니까? 도움이 필요하면 문제를 설명 할 수있는 약간의 일을해야합니다. – phonetagger

+0

더 나은 내 문제를 설명했다 (첫 번째 게시물에서 EDIT 참조) –

+0

코드에서'if (object-> state == 7)'와 같은 코드가 있지만 heck '7'의 의미에 대한 설명이 없습니다. 유효한 상태를 영어로 설명하는 enum을 추가하고'object-> state'를 enum 유형으로 만듭니다. 그런 다음,'object'를 의미있는 이름으로 바꾸거나 주석에서'object'가 무엇인지 설명하십시오. 이에 따라 게시물의 코드를 수정하면 다시 한 번 살펴 보겠습니다. 열거 형 이름으로 명확하지 않다면, 왜'object-> state == 3'이 추가 0.5 초의 sleep을 갖는'Logitech :: startThread()'에서 궁금합니다. 7 '은 그렇지 않습니다. 일반적으로 댓글을 추가하십시오. – phonetagger

답변

2

코드의 문제점을 파악하기 전에 SDK가 예상대로 작동하는지 확인해야합니다.

당신의 Logitech::startThread()의 상단에이 코드를 추가하고 내가 무슨 일을 알려 주시기 바랍니다 :

LogitechObject->m_lcd.SetText(LogitechObject->time, "ProgressBar TEST SEQUENCE"); 
this_thread::sleep_for(chrono::milliseconds(2000)); 
LogitechObject->m_lcd.SetText(LogitechObject->time, "ProgressBar TEST 0%"); 
LogitechObject->m_lcd.SetProgressBarPosition(LogitechObject->progressbar, 0); 
this_thread::sleep_for(chrono::milliseconds(2000)); 
LogitechObject->m_lcd.SetText(LogitechObject->time, "ProgressBar TEST 10%"); 
LogitechObject->m_lcd.SetProgressBarPosition(LogitechObject->progressbar, 10); 
this_thread::sleep_for(chrono::milliseconds(2000)); 
LogitechObject->m_lcd.SetText(LogitechObject->time, "ProgressBar TEST 20%"); 
LogitechObject->m_lcd.SetProgressBarPosition(LogitechObject->progressbar, 20); 
this_thread::sleep_for(chrono::milliseconds(2000)); 
LogitechObject->m_lcd.SetText(LogitechObject->time, "ProgressBar TEST 30%"); 
LogitechObject->m_lcd.SetProgressBarPosition(LogitechObject->progressbar, 30); 
this_thread::sleep_for(chrono::milliseconds(2000)); 
LogitechObject->m_lcd.SetText(LogitechObject->time, "ProgressBar TEST 40%"); 
LogitechObject->m_lcd.SetProgressBarPosition(LogitechObject->progressbar, 40); 
this_thread::sleep_for(chrono::milliseconds(2000)); 
LogitechObject->m_lcd.SetText(LogitechObject->time, "ProgressBar TEST 50%"); 
LogitechObject->m_lcd.SetProgressBarPosition(LogitechObject->progressbar, 50); 
this_thread::sleep_for(chrono::milliseconds(2000)); 
LogitechObject->m_lcd.SetText(LogitechObject->time, "ProgressBar TEST 60%"); 
LogitechObject->m_lcd.SetProgressBarPosition(LogitechObject->progressbar, 60); 
this_thread::sleep_for(chrono::milliseconds(2000)); 
LogitechObject->m_lcd.SetText(LogitechObject->time, "ProgressBar TEST 70%"); 
LogitechObject->m_lcd.SetProgressBarPosition(LogitechObject->progressbar, 70); 
this_thread::sleep_for(chrono::milliseconds(2000)); 
LogitechObject->m_lcd.SetText(LogitechObject->time, "ProgressBar TEST 80%"); 
LogitechObject->m_lcd.SetProgressBarPosition(LogitechObject->progressbar, 80); 
this_thread::sleep_for(chrono::milliseconds(2000)); 
LogitechObject->m_lcd.SetText(LogitechObject->time, "ProgressBar TEST 90%"); 
LogitechObject->m_lcd.SetProgressBarPosition(LogitechObject->progressbar, 90); 
this_thread::sleep_for(chrono::milliseconds(2000)); 
LogitechObject->m_lcd.SetText(LogitechObject->time, "ProgressBar TEST 100%"); 
LogitechObject->m_lcd.SetProgressBarPosition(LogitechObject->progressbar, 100); 
this_thread::sleep_for(chrono::milliseconds(2000)); 
LogitechObject->m_lcd.SetText(LogitechObject->time, "ProgressBar TEST COMPLETE"); 
this_thread::sleep_for(chrono::milliseconds(2000)); 

이상적으로 당신이 있는지 확인 할 수 있도록, 한 번에 2 초 동안 각 비율에 진행 표시 줄을 설정합니다 진행 막대가 예상대로 작동합니다. 이것이 작동하지 않는다면, 여러분 자신의 코드에 무엇이 잘못되었는지 알아 내려고 노력하는 데는별로 중요하지 않습니다. SDK에 문제가 있거나 SDK의 제어 매개 변수에 대한 이해가 SDK의 요구 사항과 일치하지 않습니다.

결과를 알려주십시오.

+0

Tnx. 우리는 문제를 발견했습니다. 테스트 코드 덕분에 문제는 Logitech SDK에서 파일로 추적되었습니다. 문제가 해결되었습니다. –

+0

@TestJef - 좋습니다! 그래서 실제 문제는 무엇입니까? – phonetagger

+0

Logitech SDK의 SetProgressBarPosition의 일부 코드가 주석에있었습니다. 우리는이 코드의 주석 처리를 제거하고 이제는 작동합니다. –