Permalink
Browse files

cleanup auto-detection and rendering of COM ports

  • Loading branch information...
1 parent 3f40dba commit 116e71dfcc76acb22bcf9436aff8b914adcba423 Michael Meeks committed Jul 19, 2010
Showing with 43 additions and 35 deletions.
  1. +6 −11 Makefile
  2. +31 −13 ModelViewController.cpp
  3. +2 −1 ModelViewController.h
  4. +3 −9 ProcessController.cpp
  5. +1 −1 RepSnapper.cpp
View
17 Makefile
@@ -9,19 +9,14 @@ UNAME := $(shell uname)
ifeq ($(TARGET),)
TARGET=RELEASE
endif
-ifeq ($(UNAME),Darwin)
- WARNING_FLAGS = -Wall
-else
- WARNING_FLAGS = -Wall -Wno-pragmas
-endif
EXEC=repsnapper
EXEC_DEBUG=repsnapper_debug
ifeq ($(TARGET),RELEASE)
- CFLAGS = -c -O2 $(WARNING_FLAGS)
+ CFLAGS ?= -O2 -Wall
EXECUTABLE=$(EXEC)
else
- CFLAGS = -c -g -O0 $(WARNING_FLAGS)
+ CFLAGS ?= -g -O0 -Wall
EXECUTABLE=$(EXEC_DEBUG)
endif
@@ -40,7 +35,7 @@ endif
ifeq ($(UNAME),Darwin)
# assumes you have installed MacPorts from http://www.macports.org and run:
# sudo port install boost fltk lua
- # assumes you have built boost as in the Readme.MacOsx.txt
+ # assumes you have built boost as in the Readme.MacOsx.txt
BOOST_HOME=../Libraries/boost-darwin
BOOST_INC=-I$(BOOST_HOME)/include/boost-1_43
@@ -95,11 +90,11 @@ unittest : poly_lib $(TEST_OBJECTS)
rm -f $@ # fluid doesn't remove on failure.
fluid -c $<
%.o:%.cxx
- $(CXX) ${INC} $(CFLAGS) $< -o $@
+ $(CXX) ${INC} -c $(CFLAGS) $< -o $@
%.o:%.cpp
- $(CXX) ${INC} $(CFLAGS) $< -o $@
+ $(CXX) ${INC} -c $(CFLAGS) $< -o $@
%.o:%.c
- $(CC) ${INC} $(CFLAGS) $< -o $@
+ $(CC) ${INC} -c $(CFLAGS) $< -o $@
poly_lib:
make -C $(LIB_DIR)/polylib/ all
View
44 ModelViewController.cpp
@@ -156,23 +156,21 @@ ModelViewController::ModelViewController(int x,int y,int w,int h,const char *l)
ThisRot.M[3]=0.0f;ThisRot.M[4]=1.0f;ThisRot.M[5]=0.0f; // NEW: Last Rotation
ThisRot.M[6]=0.0f;ThisRot.M[7]=0.0f;ThisRot.M[8]=1.0f; // NEW: Last Rotation
- ProcessControl.LoadXML();
- serial->SetReceivingBufferSize(ProcessControl.ReceivingBufferSize);
- serial->SetValidateConnection(ProcessControl.m_bValidateConnection);
- CopySettingsToGUI();
-
m_bExtruderDirection = true;
m_iExtruderSpeed = 3000;
m_iExtruderLength = 150;
m_fTargetTemp = 63.0f;
-
- Fl::add_timeout(0.25, Static_Timer_CB, (void*)this);
}
void ModelViewController::Init(GUI *_gui)
{
gui = _gui;
- CheckComPorts (true);
+ DetectComPorts (true);
+ ProcessControl.LoadXML();
+ serial->SetReceivingBufferSize(ProcessControl.ReceivingBufferSize);
+ serial->SetValidateConnection(ProcessControl.m_bValidateConnection);
+ CopySettingsToGUI();
+ Fl::add_timeout(0.25, Static_Timer_CB, (void*)this);
}
void ModelViewController::Static_Timer_CB(void *userdata) {
@@ -188,7 +186,7 @@ void ModelViewController::Timer_CB()
{
static uint count = 0;
if ((count++ % 4) == 0) /* every second */
- CheckComPorts();
+ DetectComPorts();
}
if( gui->Tabs->value() == gui->PrintTab )
{
@@ -201,13 +199,11 @@ void ModelViewController::resize(int x,int y, int width, int height) // Resh
Fl_Gl_Window::resize(x,y,width,height);
}
-vector<string> ModelViewController::CheckComPorts(bool init)
+void ModelViewController::DetectComPorts(bool init)
{
bool bDirty = init;
vector<std::string> currentComports;
- fprintf (stderr, "Check ports !\n");
-
#ifdef WIN32
int highestCom = 0;
for(int i = 1; i <=9 ; i++ )
@@ -280,6 +276,8 @@ vector<string> ModelViewController::CheckComPorts(bool init)
{0,0,0,0,0,0,0,0,0}
};
+ bool bWasEmpty = !comports.size();
+
gui->portInputSimple->menu(emptyList);
gui->portInput->menu(emptyList);
comports.clear();
@@ -290,10 +288,30 @@ vector<string> ModelViewController::CheckComPorts(bool init)
gui->portInputSimple->add(strdup(menuLabel.c_str()));
comports.push_back(currentComports[indx]);
}
+
+ // auto-select a new com-port
+ if (bWasEmpty && comports.size()) {
+ ProcessControl.m_sPortName = ValidateComPort(comports[0]);
+ CopySettingsToGUI();
+ }
}
#endif
+}
+
+string ModelViewController::ValidateComPort (const string &port)
+{
+ DetectComPorts();
- return currentComports;
+ // is it a valid port ?
+ for (uint i = 0; i < comports.size(); i++) {
+ if (port == comports[i])
+ return port;
+ }
+
+ if (comports.size())
+ return comports[0];
+ else
+ return "No ports found";
}
void ModelViewController::setSerialSpeed(int s )
View
3 ModelViewController.h
@@ -85,7 +85,8 @@ class ModelViewController : public Fl_Gl_Window
// Callback functions
vector<string> comports; // list of available usb serial ports
void resize (int x,int y, int width, int height); // Reshape The Window When It's Moved Or Resized
- vector<string> CheckComPorts(bool init = false);
+ void DetectComPorts(bool init = false);
+ string ValidateComPort (const string &port);
static void Static_Timer_CB(void *userdata);
void Timer_CB();
View
12 ProcessController.cpp
@@ -670,15 +670,9 @@ void ProcessController::LoadXML(XMLElement *e)
"M104 S0.0 ;Heater off\n");
m_sPortName = getXMLString (x, "m_sPortName", "");
- if (m_sPortName.length() == 0)
- {
- std::ostringstream port;
- if ( gui->MVC ) {
- fprintf (stderr, "LOAD Com-Port ! '%s'\n", m_sPortName.c_str());
- vector<string> comportlist = gui->MVC->CheckComPorts (true);
- m_sPortName = comportlist.size() > 0 ? comportlist[comportlist.size()-1] : "";
- }
- }
+ if ( gui && gui->MVC )
+ m_sPortName = gui->MVC->ValidateComPort( m_sPortName );
+
y = getVariable (x, "ValidateConnection", "1");
if(y) m_bValidateConnection = (bool)y->GetValueInt();
View
2 RepSnapper.cpp
@@ -115,9 +115,9 @@ int main(int argc, char **argv)
Fl::visual(FL_DOUBLE|FL_INDEX);
+ MVC->ProcessControl.gui = gui;
MVC->Init(gui);
MVC->serial->setGUI(gui);
- MVC->ProcessControl.gui = gui;
if (!opts.use_gui) {
if (opts.stl_input_path.size() > 0) {

0 comments on commit 116e71d

Please sign in to comment.