예제 #1
0
void CdynControlDlg::OnLbnDblclkList1()
{
    // TODO: Add your control notification handler code here
    int idx = m_predefined.GetCurSel();

    CString str;
    m_predefined.GetText(idx, str);
    str = _T("Run: ") + str;
    
    if (MessageBox(str, NULL, MB_OKCANCEL | MB_ICONWARNING) != IDOK)
        return;

    cJSON *action = cJSON_GetObjectItem(m_actionJSON, actions[idx]);
    
    int num = cJSON_GetArraySize(action);

    log(_T("\n-- start action %s with %d steps --\n"), str, num);
    for (int i = 0; i < num; i++) {
        cJSON *cmd = cJSON_GetArrayItem(action, i);
        SetServo(cJSON_GetObjectItem(cmd, "id")->valueint, 
                 cJSON_GetObjectItem(cmd, "deg")->valueint);
        SendServo(cJSON_GetObjectItem(cmd, "id")->valueint);
        Sleep(1000);
    }

    log(_T("-- end action --\n\n"), str, num);
}
예제 #2
0
void CdynControlDlg::OnEnKillFocus(UINT id)
{
    int idx = id - VIEW_ID_OFFSET;

    UpdateData(true);
    if (m_syncMode)
        SendServo(idx);
}
예제 #3
0
void CdynControlDlg::OnBnClickedButton1()
{
    // TODO: Add your control notification handler code here
    UpdateData(true);

    CSliderCtrl *slider = NULL;    
    CButton *check = NULL;
    for (int i = 0; i < ids.size(); i++) {
        SendServo(ids[i]);
    }
}
예제 #4
0
void CdynControlDlg::OnNMReleasedcaptureSlider(UINT id, NMHDR *pNMHDR, LRESULT *pResult)
{
    int idx = id - SLIDER_ID_OFFSET;
    CSliderCtrl *slider = (CSliderCtrl*)GetDlgItem(id);    
    CEdit *edit = (CEdit*)GetDlgItem(idx + VIEW_ID_OFFSET);    
    CString str;
    str.Format(_T("%d"), slider->GetPos());
    edit->SetWindowText(str);

    UpdateData(true);
    if (m_syncMode)
        SendServo(idx);
}
예제 #5
0
void UARTIntHandler(void)
{
  uint32_t ui32Status;
  ui32Status = UARTIntStatus(UART0_BASE, 1); //get interrupt status
  UARTIntClear(UART0_BASE, ui32Status); //clear the asserted interrupts
  while(UARTCharsAvail(UART0_BASE)) //loop while there are chars
  {
    CharUART=UARTCharGet(UART0_BASE);
    if((CharUART>=48 && CharUART<=57)||CharUART == 32 || CharUART == 13)
    {
      UARTprintf("%c",CharUART);
      if(CharUART == 32)
      { 
        switch(inc)
        {
          case 0:
            aux_sel = 0;
          break;
          case 1: 
            aux_sel = (CharSel[0]-48);
          break; 
          case 2:
            aux_sel = ((CharSel[1]-48)+(CharSel[0]-48)*10);
          break;
          case 3:
            aux_sel = ((CharSel[0]-48)*100+(CharSel[1]-48)*10+(CharSel[2]-48));
          break;
          default:
            aux_sel = 0;
          break; 
        }
        inc = 0;
        sel = 1;
      }
      else  if(CharUART != 13)
            {
              if(!sel)
              {
                if(inc<3)
                {
                  CharSel[inc] = CharUART;
                  inc++;
                }
                else
                {
                  for(aux_sel=0;aux_sel<3;aux_sel++) CharSel[aux_sel] = '0';
                  for(aux_val=0;aux_val<3;aux_val++) CharVal[aux_val] = '0'; 
                  RefreshUART = 0;
                  inc = 0;
                  sel = 0;
                  UARTprintf("\nCaracteres excedem o limite maximo!");
                }
              }
              else
              {
                if(inc<3)
                {
                  CharVal[inc] = CharUART;
                  inc++;
                }
                else
                {
                  for(aux_sel=0;aux_sel<3;aux_sel++) CharSel[aux_sel] = '0';
                  for(aux_val=0;aux_val<3;aux_val++) CharVal[aux_val] = '0'; 
                  RefreshUART = 0;
                  inc = 0;
                  sel = 0;
                  UARTprintf("\nCaracteres excedem o limite maximo!");
                }
              }
            }
            else
            {
              switch(inc)
              {
                case 0:
                  aux_val = 0;
                break;
                case 1: 
                   aux_val = (CharVal[0]-48);
                break; 
                case 2:
                   aux_val = ((CharVal[0]-48)*10+(CharVal[1]-48));
                break;
                case 3:
                  aux_val = ((CharVal[0]-48)*100+(CharVal[1]-48)*10+(CharVal[2]-48));
                break;
                default:
                  aux_val = 0;
                break; 
              }
              SendServo(aux_sel, aux_val);
              inc = 0;
              sel = 0;
              for(aux_sel=0;aux_sel<3;aux_sel++) CharSel[aux_sel] = '0';
              for(aux_val=0;aux_val<3;aux_val++) CharVal[aux_val] = '0'; 
              RefreshUART = 0;
              aux_val = 0;
              aux_sel = aux_val;
            }
    }
    else
    {
      UARTprintf("\nCaracter Invalido");
      RefreshUART = 0;
    }
    // //echo character
    
    // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2); //blink LED
    // delay_ms(20);
    // GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0); //turn off LED
    // Switch
    // SendServo();
  }
}