Browse Source

Merge pull request #261 from NosDE/master

mkblctrl: some small fixes
sbg
Lorenz Meier 12 years ago
parent
commit
890a6e5b49
  1. 57
      apps/drivers/mkblctrl/mkblctrl.cpp

57
apps/drivers/mkblctrl/mkblctrl.cpp

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
* *
* Copyright (C) 2012 PX4 Development Team. All rights reserved. * Copyright (C) 2012,2013 PX4 Development Team. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@ -219,7 +219,7 @@ struct MotorData_t
// the following bytes must be exactly in that order! // the following bytes must be exactly in that order!
unsigned int Current; // in 0.1 A steps, read back from BL unsigned int Current; // in 0.1 A steps, read back from BL
unsigned int MaxPWM; // read back from BL is less than 255 if BL is in current limit unsigned int MaxPWM; // read back from BL is less than 255 if BL is in current limit
unsigned int Temperature; // old BL-Ctrl will return a 255 here, the new version the temp. in °C unsigned int Temperature; // old BL-Ctrl will return a 255 here, the new version the temp. in
unsigned int RoundCount; unsigned int RoundCount;
}; };
@ -1355,28 +1355,26 @@ extern "C" __EXPORT int mkblctrl_main(int argc, char *argv[]);
int int
mkblctrl_main(int argc, char *argv[]) mkblctrl_main(int argc, char *argv[])
{ {
PortMode new_mode = PORT_MODE_UNSET; PortMode port_mode = PORT_FULL_PWM;
int pwm_update_rate_in_hz = UPDATE_RATE; int pwm_update_rate_in_hz = UPDATE_RATE;
int motorcount = 0; int motorcount = 8;
int bus = 1; int bus = 1;
bool motortest = false;
int px4mode = MAPPING_PX4; int px4mode = MAPPING_PX4;
int frametype = FRAME_PLUS; // + plus is default int frametype = FRAME_PLUS; // + plus is default
bool motortest = false;
new_mode = PORT_FULL_PWM; bool showHelp = false;
motorcount = 8; bool newMode = false;
/* /*
* Mode switches. * optional parameters
*
* XXX use getopt?
*/ */
for (int i = 1; i < argc; i++) { /* argv[0] is "mk" */ for (int i = 1; i < argc; i++) {
/* look for the optional i2c bus parameter */ /* look for the optional i2c bus parameter */
if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--bus") == 0) { if (strcmp(argv[i], "-b") == 0 || strcmp(argv[i], "--bus") == 0) {
if (argc > i + 1) { if (argc > i + 1) {
bus = atoi(argv[i + 1]); bus = atoi(argv[i + 1]);
newMode = true;
} else { } else {
errx(1, "missing argument for i2c bus (-b)"); errx(1, "missing argument for i2c bus (-b)");
return 1; return 1;
@ -1388,6 +1386,7 @@ mkblctrl_main(int argc, char *argv[])
if (argc > i + 1) { if (argc > i + 1) {
if(strcmp(argv[i + 1], "+") == 0 || strcmp(argv[i + 1], "x") == 0 || strcmp(argv[i + 1], "X") == 0) { if(strcmp(argv[i + 1], "+") == 0 || strcmp(argv[i + 1], "x") == 0 || strcmp(argv[i + 1], "X") == 0) {
px4mode = MAPPING_MK; px4mode = MAPPING_MK;
newMode = true;
if(strcmp(argv[i + 1], "+") == 0) { if(strcmp(argv[i + 1], "+") == 0) {
frametype = FRAME_PLUS; frametype = FRAME_PLUS;
} else { } else {
@ -1405,30 +1404,36 @@ mkblctrl_main(int argc, char *argv[])
/* look for the optional test parameter */ /* look for the optional test parameter */
if (strcmp(argv[i], "-t") == 0) { if (strcmp(argv[i], "-t") == 0) {
motortest = true; motortest = true;
newMode = true;
}
/* look for the optional -h --help parameter */
if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) {
showHelp == true;
} }
} }
if(new_mode == PORT_MODE_UNSET) { if(showHelp) {
fprintf(stderr, "mkblctrl: unrecognised command, try:\n"); fprintf(stderr, "mkblctrl: help:\n");
fprintf(stderr, " [-mkmode frame{+/x}] [-b i2c_bus_number] [-t motortest]\n"); fprintf(stderr, " [-mkmode frame{+/x}] [-b i2c_bus_number] [-t motortest] [-h / --help]\n");
exit(1); exit(1);
} }
if (mk_start(bus, motorcount) != OK)
errx(1, "failed to start the MK-BLCtrl driver");
if (g_mk == nullptr) {
if (mk_start(bus, motorcount) != OK) {
errx(1, "failed to start the MK-BLCtrl driver");
} else {
newMode = true;
}
}
/* was a new mode set? */
if (new_mode != PORT_MODE_UNSET) {
/* yes but it's the same mode */
//if (new_mode == g_port_mode)
//return OK;
/* switch modes */ /* parameter set ? */
fprintf(stderr, "[mkblctrl] %iHz Update Rate\n",pwm_update_rate_in_hz); if (newMode) {
return mk_new_mode(new_mode, pwm_update_rate_in_hz, motorcount, motortest, px4mode, frametype); /* switch parameter */
return mk_new_mode(port_mode, pwm_update_rate_in_hz, motorcount, motortest, px4mode, frametype);
} }
/* test, etc. here g*/ /* test, etc. here g*/

Loading…
Cancel
Save