AREXPORT ArSerialConnection::ArSerialConnection(bool is422)
{
  myPort = -1;
  myPortName = "none";
  myBaudRate = 9600;
  myHardwareControl = false;
  myStatus = STATUS_NEVER_OPENED;
  myTakingTimeStamps = false;
  myIs422 = is422;
  if (myIs422)
    setPortType("serial422");
  else
    setPortType("serial");
  buildStrMap();
}
Exemplo n.º 2
0
void BubbleHardwareManager::onComboBootPortNameChanged(wxCommandEvent &event)
{
    setPortType();
}
Exemplo n.º 3
0
BubbleHardwareManager::BubbleHardwareManager(   wxWindow* parent,
                                                wxWindowID id,
                                                Bubble *const bubble,
                                                const wxString& boardName,
                                                const wxColour& colour,
                                                const wxPoint& pos,
                                                const wxSize& size,
                                                long style,
                                                const wxString& name) : BubblePanel(parent,
                                                                                    id,
                                                                                    colour,
                                                                                    true,
                                                                                    pos,
                                                                                    size,
                                                                                    style,
                                                                                    name
                                                                                   ),
                                                                        parent(parent),
                                                                        bubble(bubble),
                                                                        boardName(boardName),
                                                                        currentBoardProperties(NULL),
                                                                        lblBootPortName(NULL),
                                                                        comboBootPortName(NULL),
                                                                        lblBoardName(NULL),
                                                                        comboBoardName(NULL),
                                                                        buttonReloadBlocks(NULL),
                                                                        buttonReloadHardware(NULL),
                                                                        lblURL0(NULL),
                                                                        lblURL1(NULL),
                                                                        buttonGoToDriversDir(NULL),
                                                                        buttonMainImage(NULL),
                                                                        emptyDummyString(wxString(""))
{
    if (bubble == NULL)
        return; //Nothing to do.

    currentBoardProperties = new BubbleBoardProperties();

    //Hide();

    //##The following line crashes the application when the BubbleHardwareManager is closed by the user, so
    //##don't delete it, because it may be possibly a wxAUI's bug, and I would like to document it:
    //SetSize(400, 450);

    lblBoardName = new wxStaticText(   this,
                                        wxNewId(), //##
                                        //##Future: Make configurable by the user if he want to see these
                                        //shorcuts on screen or not:
                                        _("Hardware (Alt+W):"), //##Load shorcuts from XML.
                                        wxPoint(10, 10),
                                        wxSize(150, 20),
                                        wxALIGN_CENTRE,
                                        wxString("lblBoardName")
                                   );

    comboBoardName = new BubbleCombo(   this,
                                        wxNewId(),
                                        wxImage(bubble->getThemePath() + wxString("/ComboSelectDefault.png")),
                                        wxImage(bubble->getThemePath() + wxString("/ComboSelectPressed.png")),
                                        wxImage(bubble->getThemePath() + wxString("/ComboSelectHover.png")),
                                        wxImage(bubble->getThemePath() + wxString("/ComboSelectDisabled.png")),
                                        false,
                                        wxPoint(10, 25), //##Make this automatic.
                                        wxSize(190, 16),
                                        //wxTAB_TRAVERSAL|
                                        //wxNO_BORDER|
                                        //wxBORDER_SIMPLE|
                                        //wxBORDER_RAISED|
                                        wxBORDER_SUNKEN|
                                        wxTRANSPARENT_WINDOW,
                                        //wxDefaultSize,
                                        //##wxALIGN_CENTRE,
                                        wxString("comboBoardName")
                                    );
    if (comboBoardName)
    {
        comboBoardName->setSorted(false);
        bubble->loadHardwareTargets(this);

        boardName = "DuinoBot.v2.3 HID";
        if (boardName == wxString(""))
        {
            selectFirstBoard();
        }
        else
        {
            BubbleBoardProperties *initialBoard = NULL;
            initialBoard = &(boardsProperties.Item(0));

            //Find board:
            bool found = false;
            BubbleBoardProperties *iterator = NULL;
            for (unsigned int i = 0; i < boardsProperties.GetCount(); i++)
            {
                iterator = &(boardsProperties.Item(i)); //##In theory, this is faster than the other index based form, but I'm not sure yet...
                if (iterator)
                {
                    if (iterator->getName() == boardName)
                    {
                        initialBoard = iterator;
                        currentBoardProperties->set(iterator);
                        comboBoardName->setSelection(boardName);
                        found = true;
                    }
                }
            }
            if (!found)
            {
                selectFirstBoard();
            }
        }
        comboBoardName->Connect(wxEVT_COMMAND_TEXT_UPDATED,
                                wxCommandEventHandler(BubbleHardwareManager::onComboBoardNameChanged),
                                NULL,
                                this
                               );
    }

    lblBootPortName = new wxStaticText( this,
                                        wxNewId(),
                                        //In the future there may be IP sockets, and other comm
                                        //channels, so here it's just "Port", not "Serial port":

                                        //##Future: Make configurable by the user if he want to see these
                                        //shorcuts on screen or not:
                                        _("Port (Alt+R):"), //##Load shorcuts from XML.
                                        wxPoint(210, 10),   //##Un-hardcode!
                                        wxSize(150, 20),    //##Un-hardcode!
                                        wxALIGN_CENTRE,
                                        wxString("lblBootSerialPortName")
                                       );
    comboBootPortName = new BubbleCombo(this,
                                        wxNewId(),
                                        wxImage(bubble->getThemePath() + wxString("/ComboSelectDefault.png")),
                                        wxImage(bubble->getThemePath() + wxString("/ComboSelectPressed.png")),
                                        wxImage(bubble->getThemePath() + wxString("/ComboSelectHover.png")),
                                        wxImage(bubble->getThemePath() + wxString("/ComboSelectDisabled.png")),
                                        false,
                                        wxPoint(210, 25),   //##Un-hardcode!
                                        wxSize(100, 16),    //##Un-hardcode!
                                        wxBORDER_SUNKEN|
                                        wxTRANSPARENT_WINDOW,
                                        wxString("comboBootSerialPortName")
                                       );
    if (comboBootPortName)
    {
        comboBootPortName->Connect( wxEVT_COMMAND_TOOL_CLICKED,
                                    wxCommandEventHandler(BubbleHardwareManager::onUpdatePorts),
                                    NULL,
                                    this
                                  );
        comboBootPortName->Connect( wxEVT_COMMAND_TEXT_UPDATED,
                                    wxCommandEventHandler(BubbleHardwareManager::onComboBootPortNameChanged),
                                    NULL,
                                    this
                                  );
        updatePorts();
        setPortType();

        if (getCurrentBoardProperties())
        {
            //This is necessary for the first time the system loads the boards:
            if ( (getCurrentBoardProperties()->getPortType() == wxString("HID")) ||
                 (getCurrentBoardProperties()->getPortType() == wxString("HID2"))
               )
            {
                setPortSelectorEnabled(false);
                setPortNameString((getCurrentBoardProperties())->getPortType());
            }
        }
//        comboBootPortName->setSelection(0); //##Un-hardcode and get the port from the config file...
//        wxString strCommRealName = wxString("//./") + comboBootPortName->getText();
//        bubble->setBootPortName(strCommRealName);
    }

    buttonReloadBlocks = new wxButton(  this,
                                        wxNewId(),
                                        _("Reload blocks"),
                                        wxPoint(10, 55), //##Un-hardcode!
                                        //wxDefaultSize,
                                        wxSize(160, 25), //##Future: The autosize (with the label) feature does now work. Make it work!
                                        wxBU_EXACTFIT
                                     ); //##

    if (buttonReloadBlocks)
    {
        buttonReloadBlocks->Connect(wxEVT_LEFT_UP,
                                    wxMouseEventHandler(BubbleHardwareManager::onButtonReloadBlocksLeftUp),
                                    NULL,
                                    this
                                   );
        //buttonReloadBlocks->Hide(); //##Testing.
//        wxMessageDialog dialog0(bubble->getParent(), bubble->getProfile(), wxString("profile")); //##Debug.
//        dialog0.ShowModal(); //##Debug.
//        buttonReloadBlocks->Show(bubble->getProfile() == wxString("developer"));
    }

    buttonReloadHardware = new wxButton(  this,
                                        wxNewId(),
                                        _("Reload hardware"),
                                        wxPoint(175, 55), //##Un-hardcode!
                                        //wxDefaultSize,
                                        wxSize(160, 25), //##Future: The autosize (with the label) feature does now work. Make it work!
                                        wxBU_EXACTFIT
                                     ); //##

    if (buttonReloadHardware)
    {
        buttonReloadHardware->Connect(wxEVT_LEFT_UP,
                                    wxMouseEventHandler(BubbleHardwareManager::onButtonButtonReloadHardwareLeftUp),
                                    NULL,
                                    this
                                   );
        //buttonReloadHardware->Show(bubble->getProfile() == wxString("developer"));
    }

    buttonGoToDriversDir = new wxButton(  this,
                                        wxNewId(),
                                        _("Open folder with drivers"),
                                        wxPoint(10, 85), //##Un-hardcode!
                                        //wxDefaultSize,
                                        wxSize(160, 25), //##Future: autosize.
                                        wxBU_EXACTFIT
                                     );
    if (buttonGoToDriversDir)
    {
        buttonGoToDriversDir->Connect(  wxEVT_LEFT_UP,
                                        wxMouseEventHandler(BubbleHardwareManager::onButtonGoToDriversDirLeftUp),
                                        NULL,
                                        this
                                     );

        if (getCurrentBoardProperties())
        {
            buttonGoToDriversDir->Enable(getCurrentBoardProperties()->getDriverPath() != wxString(""));
            lblURL0 = new wxHyperlinkCtrl(  this,
                                            wxNewId(),
                                            getCurrentBoardProperties()->getUrl0(),
                                            getCurrentBoardProperties()->getUrl0(),
                                            wxPoint(buttonGoToDriversDir->GetPosition().x,
                                                    buttonGoToDriversDir->GetPosition().y +
                                                    buttonGoToDriversDir->GetSize().GetHeight() + 10),
                                            wxDefaultSize,
                                            wxHL_ALIGN_LEFT
                                         );
            if (lblURL0)
            {
                lblURL0->SetVisitedColour(lblURL0->GetNormalColour());
                //wxHyperlinkCtrl Bug: the first time, it should be created big.
                if (buttonReloadHardware)
                {
                    lblURL0->SetSize(wxSize(buttonReloadHardware->GetPosition().x +
                                            buttonReloadHardware->GetSize().GetWidth() -
                                            buttonGoToDriversDir->GetPosition().x,
                                            lblURL0->GetSize().GetHeight()
                                           )
                                    );
                }
                lblURL1 = new wxHyperlinkCtrl(  this,
                                                wxNewId(),
                                                getCurrentBoardProperties()->getUrl1(),
                                                getCurrentBoardProperties()->getUrl1(),
                                                wxPoint(lblURL0->GetPosition().x,
                                                        lblURL0->GetPosition().y +
                                                        lblURL0->GetSize().GetHeight() + 10),
                                                wxDefaultSize,
                                                wxHL_ALIGN_LEFT
                                             );
                if (lblURL1)
                {
                    lblURL1->SetVisitedColour(lblURL1->GetNormalColour());
                    if (lblURL0)
                        lblURL1->SetSize(lblURL0->GetSize());
                }
            }
        }
    }

    buttonMainImage = new BubbleButton( this,
                                        wxNewId(),
                                        wxPoint(0, 0),  //##Un-hardcode!
                                        wxSize(32, 32)  //##Un-hardcode!
                                      );
    //##buttonIcon->SetValidator(wxDefaultValidator);

    changeImage();

    //SetBackgroundColour(colour);
    SetBackgroundColourAndRefresh(colour);
}