Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile generalisation, Unicode support #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 21 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,48 +1,47 @@
OS = LINUX
#OS = MACOSX
#OS = WINDOWS
OS ?= LINUX
#OS ?= MACOSX
#OS ?= WINDOWS

PROG = firmata_test

ifeq ($(OS), LINUX)
TARGET = $(PROG)
FINAL_TARGET = $(TARGET)
CXX = g++
STRIP = strip
WXCONFIG = ~/wxwidgets/2.8.10.gtk2.teensy/bin/wx-config
CPPFLAGS = -O2 -Wall -Wno-strict-aliasing `$(WXCONFIG) --cppflags` -D$(OS)
LIBS = `$(WXCONFIG) --libs`
WXCONFIG ?= ~/wxwidgets/2.8.10.gtk2.teensy/bin/wx-config
else ifeq ($(OS), MACOSX)
TARGET = $(PROG)
FINAL_TARGET = $(PROG).dmg
SDK = /Developer/SDKs/MacOSX10.5.sdk
CXX = g++
STRIP = strip
WXCONFIG = ~/wxwidgets/2.8.10.mac.teensy/bin/wx-config
CPPFLAGS = -O2 -Wall -Wno-strict-aliasing -isysroot $(SDK) `$(WXCONFIG) --cppflags` -D$(OS) -arch ppc -arch i386
LIBS = -Xlinker -syslibroot -Xlinker $(SDK) `$(WXCONFIG) --libs`
WXCONFIG ?= ~/wxwidgets/2.8.10.mac.teensy/bin/wx-config
PLATFORM_CPPFLAGS = -isysroot $(SDK) -arch ppc -arch i386
PLATFORM_LIBS = -Xlinker -syslibroot -Xlinker $(SDK)
else ifeq ($(OS), WINDOWS)
TARGET = $(PROG).exe
FINAL_TARGET = $(TARGET)
CXX = i586-mingw32msvc-g++
STRIP = i586-mingw32msvc-strip
WINDRES = i586-mingw32msvc-windres
CROSS ?= i586-mingw32msvc-
WINDRES = $(CROSS)windres
KEY_SPC = ~/bin/cert/mykey.spc
KEY_PVK = ~/bin/cert/mykey.pvk
KEY_TS = http://timestamp.comodoca.com/authenticode
WXCONFIG = ~/wxwidgets/2.8.10.mingw.teensy/bin/wx-config
CPPFLAGS = -O2 -Wall -Wno-strict-aliasing `$(WXCONFIG) --cppflags` -D$(OS)
LIBS = `$(WXCONFIG) --libs`
WXCONFIG ?= ~/wxwidgets/2.8.10.mingw.teensy/bin/wx-config
endif

WXCONFIG := $(shell if [ -x $(WXCONFIG) ]; then echo $(WXCONFIG); else echo `which wx-config`; fi)

TARGET ?= $(PROG)
FINAL_TARGET ?= $(TARGET)
CXX ?= $(CROSS)g++
STRIP ?= $(CROSS)strip
OPT ?= -O2
LIBS = $(PLATFORM_LIBS) `$(WXCONFIG) --libs`
CPPFLAGS = $(PLATFORM_CPPFLAGS) $(OPT) -Wall -Wno-strict-aliasing `$(WXCONFIG) --cppflags` -D$(OS)

MAKEFLAGS = --jobs=4

OBJS = firmata_test.o serial.o

all: $(FINAL_TARGET)

$(PROG): $(OBJS)
$(CXX) $(OBJS) -o $@ $(LIBS)
$(CXX) $(LDFLAGS) $(OBJS) -o $@ $(LIBS)

$(PROG).exe: $(PROG)
cp $(PROG) $@
Expand Down
79 changes: 40 additions & 39 deletions firmata_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ wxMenu *port_menu;
#define ANALOG_MAPPING_RESPONSE 0x6A
#define REPORT_FIRMWARE 0x79 // report name and version of the firmware

const wxString S_HIGH = _("High");
const wxString S_LOW = _("Low");

BEGIN_EVENT_TABLE(MyFrame,wxFrame)
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
Expand All @@ -86,10 +88,10 @@ MyFrame::MyFrame( wxWindow *parent, wxWindowID id, const wxString &title,
port.Set_baud(57600);
wxMenuBar *menubar = new wxMenuBar;
wxMenu *menu = new wxMenu;
menu->Append( wxID_EXIT, "Quit", "");
menubar->Append(menu, "File");
menu->Append( wxID_EXIT, _("Quit"), wxEmptyString);
menubar->Append(menu, _("File"));
menu = new wxMenu;
menubar->Append(menu, "Port");
menubar->Append(menu, _("Port"));
SetMenuBar(menubar);
port_menu = menu;
CreateStatusBar(1);
Expand Down Expand Up @@ -122,7 +124,7 @@ void MyFrame::init_data(void)
pin_info[i].value = 0;
}
tx_count = rx_count = 0;
firmata_name = "";
firmata_name = wxEmptyString;
UpdateStatus();
new_size();
}
Expand All @@ -145,7 +147,7 @@ void MyFrame::add_item_to_grid(int row, int col, wxWindow *item)
while (num_row < row + 1) {
printf(" add %d static text\n", num_col);
for (int i=0; i<num_col; i++) {
grid->Add(new wxStaticText(scroll, -1, ""));
grid->Add(new wxStaticText(scroll, -1, wxEmptyString));
}
num_row++;
}
Expand All @@ -172,24 +174,24 @@ void MyFrame::add_item_to_grid(int row, int col, wxWindow *item)
void MyFrame::add_pin(int pin)
{
wxString *str = new wxString();
str->Printf("Pin %d", pin);
str->Printf(_("Pin %d"), pin);
wxStaticText *pin_name = new wxStaticText(scroll, -1, *str);
add_item_to_grid(pin, 0, pin_name);

wxArrayString list;
if (pin_info[pin].supported_modes & (1<<MODE_INPUT)) list.Add("Input");
if (pin_info[pin].supported_modes & (1<<MODE_OUTPUT)) list.Add("Output");
if (pin_info[pin].supported_modes & (1<<MODE_ANALOG)) list.Add("Analog");
if (pin_info[pin].supported_modes & (1<<MODE_PWM)) list.Add("PWM");
if (pin_info[pin].supported_modes & (1<<MODE_SERVO)) list.Add("Servo");
if (pin_info[pin].supported_modes & (1<<MODE_INPUT)) list.Add(_("Input"));
if (pin_info[pin].supported_modes & (1<<MODE_OUTPUT)) list.Add(_("Output"));
if (pin_info[pin].supported_modes & (1<<MODE_ANALOG)) list.Add(_("Analog"));
if (pin_info[pin].supported_modes & (1<<MODE_PWM)) list.Add(_("PWM"));
if (pin_info[pin].supported_modes & (1<<MODE_SERVO)) list.Add(_("Servo"));
wxPoint pos = wxPoint(0, 0);
wxSize size = wxSize(-1, -1);
wxChoice *modes = new wxChoice(scroll, 8000+pin, pos, size, list);
if (pin_info[pin].mode == MODE_INPUT) modes->SetStringSelection("Input");
if (pin_info[pin].mode == MODE_OUTPUT) modes->SetStringSelection("Output");
if (pin_info[pin].mode == MODE_ANALOG) modes->SetStringSelection("Analog");
if (pin_info[pin].mode == MODE_PWM) modes->SetStringSelection("PWM");
if (pin_info[pin].mode == MODE_SERVO) modes->SetStringSelection("Servo");
if (pin_info[pin].mode == MODE_INPUT) modes->SetStringSelection(_("Input"));
if (pin_info[pin].mode == MODE_OUTPUT) modes->SetStringSelection(_("Output"));
if (pin_info[pin].mode == MODE_ANALOG) modes->SetStringSelection(_("Analog"));
if (pin_info[pin].mode == MODE_PWM) modes->SetStringSelection(_("PWM"));
if (pin_info[pin].mode == MODE_SERVO) modes->SetStringSelection(_("Servo"));
printf("create choice, mode = %d (%s)\n", pin_info[pin].mode,
(const char *)modes->GetStringSelection());
add_item_to_grid(pin, 1, modes);
Expand All @@ -203,11 +205,11 @@ void MyFrame::UpdateStatus(void)
{
wxString status;
if (port.Is_open()) {
status.Printf(port.get_name() + " " +
firmata_name + " Tx:%u Rx:%u",
status.Printf(port.get_name() + _(" ") +
firmata_name + _(" Tx:%u Rx:%u"),
tx_count, rx_count);
} else {
status = "Please choose serial port";
status = _("Please choose serial port");
}
SetStatusText(status);
}
Expand All @@ -223,11 +225,11 @@ void MyFrame::OnModeChange(wxCommandEvent &event)
printf("Mode Change, id = %d, pin=%d, ", id, pin);
printf("Mode = %s\n", (const char *)sel);
int mode = 255;
if (sel.IsSameAs("Input")) mode = MODE_INPUT;
if (sel.IsSameAs("Output")) mode = MODE_OUTPUT;
if (sel.IsSameAs("Analog")) mode = MODE_ANALOG;
if (sel.IsSameAs("PWM")) mode = MODE_PWM;
if (sel.IsSameAs("Servo")) mode = MODE_SERVO;
if (sel.IsSameAs(_("Input"))) mode = MODE_INPUT;
if (sel.IsSameAs(_("Output"))) mode = MODE_OUTPUT;
if (sel.IsSameAs(_("Analog"))) mode = MODE_ANALOG;
if (sel.IsSameAs(_("PWM"))) mode = MODE_PWM;
if (sel.IsSameAs(_("Servo"))) mode = MODE_SERVO;
if (mode != pin_info[pin].mode) {
// send the mode change message
uint8_t buf[4];
Expand All @@ -242,20 +244,20 @@ void MyFrame::OnModeChange(wxCommandEvent &event)
// create the 3rd column control for this mode
if (mode == MODE_OUTPUT) {
wxToggleButton *button = new wxToggleButton(scroll, 7000+pin,
pin_info[pin].value ? "High" : "Low");
pin_info[pin].value ? S_HIGH : S_LOW);
button->SetValue(pin_info[pin].value);
add_item_to_grid(pin, 2, button);
} else if (mode == MODE_INPUT) {
wxStaticText *text = new wxStaticText(scroll, 5000+pin,
pin_info[pin].value ? "High" : "Low");
pin_info[pin].value ? S_HIGH : S_LOW);
wxSize size = wxSize(128, -1);
text->SetMinSize(size);
text->SetWindowStyle(wxALIGN_CENTRE);
add_item_to_grid(pin, 2, text);

} else if (mode == MODE_ANALOG) {
wxString val;
val.Printf("%d", pin_info[pin].value);
val.Printf(_("%d"), pin_info[pin].value);
wxStaticText *text = new wxStaticText(scroll, 5000+pin, val);
wxSize size = wxSize(128, -1);
text->SetMinSize(size);
Expand All @@ -280,7 +282,7 @@ void MyFrame::OnToggleButton(wxCommandEvent &event)
wxToggleButton *button = (wxToggleButton *)FindWindowById(id, scroll);
int val = button->GetValue() ? 1 : 0;
printf("Toggle Button, id = %d, pin=%d, val=%d\n", id, pin, val);
button->SetLabel(val ? "High" : "Low");
button->SetLabel(val ? S_HIGH : S_LOW);
pin_info[pin].value = val;
int port_num = pin / 8;
int port_val = 0;
Expand Down Expand Up @@ -350,7 +352,7 @@ void MyFrame::OnPort(wxCommandEvent &event)
port.Set_baud(57600);
if (port.Is_open()) {
printf("port is open\n");
firmata_name = "";
firmata_name = wxEmptyString;
rx_count = tx_count = 0;
parse_count = 0;
parse_command_len = 0;
Expand Down Expand Up @@ -471,7 +473,7 @@ void MyFrame::DoMessage(void)
FindWindowById(5000 + pin, scroll);
if (text) {
wxString val;
val.Printf("A%d: %d", analog_ch, analog_val);
val.Printf(_("A%d: %d"), analog_ch, analog_val);
text->SetLabel(val);
}
return;
Expand All @@ -491,7 +493,7 @@ void MyFrame::DoMessage(void)
printf("pin %d is %d\n", pin, val);
wxStaticText *text = (wxStaticText *)
FindWindowById(5000 + pin, scroll);
if (text) text->SetLabel(val ? "High" : "Low");
if (text) text->SetLabel(val ? S_HIGH : S_LOW);
pin_info[pin].value = val;
}
}
Expand All @@ -514,7 +516,7 @@ void MyFrame::DoMessage(void)
name[len++] = '.';
name[len++] = parse_buf[3] + '0';
name[len++] = 0;
firmata_name = name;
firmata_name = wxString::FromAscii(name);
// query the board's capabilities only after hearing the
// REPORT_FIRMWARE message. For boards that reset when
// the port open (eg, Arduino with reset=DTR), they are
Expand Down Expand Up @@ -591,8 +593,8 @@ void MyFrame::DoMessage(void)

void MyFrame::OnAbout( wxCommandEvent &event )
{
wxMessageDialog dialog( this, wxT("Firmata Test 1.0\nCopyright Paul Stoffregen"),
wxT("About Firmata Test"), wxOK|wxICON_INFORMATION );
wxMessageDialog dialog( this, _("Firmata Test 1.0\nCopyright Paul Stoffregen"),
_("About Firmata Test"), wxOK|wxICON_INFORMATION );
dialog.ShowModal();
}

Expand All @@ -619,11 +621,10 @@ void MyFrame::OnSize( wxSizeEvent &event )
MyMenu::MyMenu(const wxString& title, long style) : wxMenu(title, style)
{
}

void MyMenu::OnShowPortList(wxMenuEvent &event)
{
wxMenu *menu;
wxMenuItem *item;
int num, any=0;

menu = event.GetMenu();
Expand All @@ -635,12 +636,12 @@ void MyMenu::OnShowPortList(wxMenuEvent &event)
for (int i = old_items.GetCount() - 1; i >= 0; i--) {
menu->Delete(old_items[i]);
}
menu->AppendRadioItem(9000, " (none)");
menu->AppendRadioItem(9000, _(" (none)"));
wxArrayString list = port.port_list();
num = list.GetCount();
for (int i=0; i < num; i++) {
//printf("%d: port %s\n", i, (const char *)list[i]);
item = menu->AppendRadioItem(9001 + i, list[i]);
menu->AppendRadioItem(9001 + i, list[i]);
if (port.Is_open() && port.get_name().IsSameAs(list[i])) {
menu->Check(9001 + i, true);
any = 1;
Expand All @@ -666,7 +667,7 @@ MyApp::MyApp()

bool MyApp::OnInit()
{
MyFrame *frame = new MyFrame( NULL, -1, "Firmata Test", wxPoint(20,20), wxSize(400,640) );
MyFrame *frame = new MyFrame( NULL, -1, _("Firmata Test"), wxPoint(20,20), wxSize(400,640) );
frame->Show( true );

return true;
Expand Down
2 changes: 1 addition & 1 deletion firmata_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class MyFrame: public wxFrame
class MyMenu: public wxMenu
{
public:
MyMenu(const wxString& title = "", long style = 0);
MyMenu(const wxString& title = wxEmptyString, long style = 0);
void OnShowPortList(wxMenuEvent &event);
void OnHighlight(wxMenuEvent &event);
};
Expand Down
34 changes: 17 additions & 17 deletions serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,41 +80,41 @@ int Serial::Open(const wxString& name)
#if defined(LINUX)
struct serial_struct kernel_serial_settings;
int bits;
port_fd = open(name.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
port_fd = open(name.mb_str(wxConvUTF8), O_RDWR | O_NOCTTY | O_NONBLOCK);
if (port_fd < 0) {
if (errno == EACCES) {
error_msg = "Unable to access " + name + ", insufficient permission";
error_msg = _("Unable to access ") + name + wxT(", insufficient permission");
// TODO: we could look at the permission bits and owner
// to make a better message here
} else if (errno == EISDIR) {
error_msg = "Unable to open " + name +
", Object is a directory, not a serial port";
error_msg = _("Unable to open ") + name +
_(", Object is a directory, not a serial port");
} else if (errno == ENODEV || errno == ENXIO) {
error_msg = "Unable to open " + name +
", Serial port hardware not installed";
error_msg = _("Unable to open ") + name +
_(", Serial port hardware not installed");
} else if (errno == ENOENT) {
error_msg = "Unable to open " + name +
", Device name does not exist";
error_msg = _("Unable to open ") + name +
_(", Device name does not exist");
} else {
error_msg = "Unable to open " + name +
", " + strerror(errno);
error_msg = _("Unable to open ") + name +
_(", ") + wxString::FromAscii(strerror(errno));
}
return -1;
}
if (ioctl(port_fd, TIOCMGET, &bits) < 0) {
close(port_fd);
error_msg = "Unable to query serial port signals";
error_msg = _("Unable to query serial port signals");
return -1;
}
bits &= ~(TIOCM_DTR | TIOCM_RTS);
if (ioctl(port_fd, TIOCMSET, &bits) < 0) {
close(port_fd);
error_msg = "Unable to control serial port signals";
error_msg = _("Unable to control serial port signals");
return -1;
}
if (tcgetattr(port_fd, &settings_orig) != 0) {
close(port_fd);
error_msg = "Unable to query serial port settings (perhaps not a serial port)";
error_msg = _("Unable to query serial port settings (perhaps not a serial port)");
return -1;
}
memset(&settings, 0, sizeof(settings));
Expand Down Expand Up @@ -257,7 +257,7 @@ int Serial::Open(const wxString& name)

wxString Serial::get_name(void)
{
if (!port_is_open) return "";
if (!port_is_open) return wxString();
return port_name;
}

Expand All @@ -281,7 +281,7 @@ void Serial::Close(void)
Output_flush();
Input_discard();
port_is_open = 0;
port_name = "";
port_name = wxEmptyString;
#if defined(LINUX) || defined(MACOSX)
tcsetattr(port_fd, TCSANOW, &settings_orig);
close(port_fd);
Expand Down Expand Up @@ -778,7 +778,7 @@ wxArrayString Serial::port_list()
// (otherwise the port will be invisible to the user
// and we won't have a to alert them to the permssion
// problem)
if (errno == EACCES) list.Add(s);
if (errno == EACCES) list.Add(wxString::FromAscii(s));
// any other error, assume it's not a real device
continue;
}
Expand All @@ -804,7 +804,7 @@ wxArrayString Serial::port_list()
// not nice! Every serial port is going to get DTR raised
// and then lowered. I wish there were a way to prevent this,
// but it seems impossible.
list.Add(s);
list.Add(wxString::FromAscii(s));
}
closedir(dir);
#elif defined(MACOSX)
Expand Down