Skip to content

Commit

Permalink
Code reorg. Had duplicate functions in some files. Also, added commen…
Browse files Browse the repository at this point in the history
…ts to ppm-decode.cpp detailing the origina of the code
  • Loading branch information
0xjairo committed Dec 3, 2011
1 parent 9bf6e9d commit 7a9d01f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ PRODUCT_ID := 0003
SRCS= main.cpp \
utils.cpp \
esc-control.cpp \
# ppm-decode.cpp
ppm-decode.cpp

INCLUDES=${SRCS:.cpp=.h}
OBJS=$(addprefix $(APP_OBJ_PATH)/, $(SRCS:.cpp=.o))
Expand Down
41 changes: 4 additions & 37 deletions esc-control.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#include "wirish.h"
#include "utils.h"
#include "esc-control.h"

// ASCII escape character
#define ESC ((uint8)27)

// Default USART baud rate
#define BAUD 9600

// Servo constants
#define SERVO_MIN 3430
Expand Down Expand Up @@ -45,7 +41,7 @@ void ppm_decode(void){
time_start = micros();

}else{
#ifdef VERBOSE
#ifdef USB_VERBOSE
SerialUSB.print(i);
SerialUSB.print(":");
SerialUSB.print(time_elapsed);
Expand All @@ -65,12 +61,12 @@ void ppm_decode(void){
}
channels[i++] = time_elapsed;
}else{
#ifdef VERBOSE
#ifdef USB_VERBOSE
SerialUSB.println("");
#endif
i=0;
}
#ifdef VERBOSE
#ifdef USB_VERBOSE
SerialUSB.print("\t");
#endif

Expand Down Expand Up @@ -140,32 +136,3 @@ void cmd_servo_sweep(void) {
enable_usarts();
}

void cmd_board_info(void) { // TODO print more information
SerialUSB.println("Board information");
SerialUSB.println("=================");

SerialUSB.print("* Clock speed (MHz): ");
SerialUSB.println(CYCLES_PER_MICROSECOND);

SerialUSB.print("* BOARD_LED_PIN: ");
SerialUSB.println(BOARD_LED_PIN);

SerialUSB.print("* BOARD_BUTTON_PIN: ");
SerialUSB.println(BOARD_BUTTON_PIN);

SerialUSB.print("* GPIO information (BOARD_NR_GPIO_PINS = ");
SerialUSB.print(BOARD_NR_GPIO_PINS);
SerialUSB.println("):");
print_board_array("ADC pins", boardADCPins, BOARD_NR_ADC_PINS);
print_board_array("PWM pins", boardPWMPins, BOARD_NR_PWM_PINS);
print_board_array("Used pins", boardUsedPins, BOARD_NR_USED_PINS);
}

// -- Helper functions --------------------------------------------------------

static uint16 init_all_timers_prescale = 0;

static void set_prescale(timer_dev *dev) {
timer_set_prescaler(dev, init_all_timers_prescale);
}

7 changes: 0 additions & 7 deletions esc-control.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
#include "wirish.h"

// Commands
void cmd_print_help(void);
void cmd_servo_sweep(void);
void cmd_board_info(void);
void ppm_decode(void);
void set_servo_angle(float angle);

// Helper functions
void init_all_timers(uint16 prescale);
void enable_usarts(void);
void disable_usarts(void);
void print_board_array(const char* msg, const uint8 arr[], int len);

4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Comment out to disable USB printouts
#define USB_VERBOSE


// Include files
#include "wirish.h"
Expand Down Expand Up @@ -87,6 +86,7 @@ int main(void) {
SerialUSB.print("Unexpected byte: 0x");
SerialUSB.print((int)input, HEX);
SerialUSB.println(", press h for help.");
break;
}

SerialUSB.print("> ");
Expand Down
3 changes: 3 additions & 0 deletions ppm-decode.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Original code from http://pastebin.com/NQtbVCFh
// Posted on the leaflabs.com forum by Dweller:
// http://forums.leaflabs.com/topic.php?id=1170
///**********************************************************************
// Various Maple tests.. including timer capture to memory via dma =)
// */
Expand Down
23 changes: 23 additions & 0 deletions utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,26 @@ boolean isConnected(){
return (SerialUSB.isConnected() && (SerialUSB.getDTR() || SerialUSB.getRTS()));
}

void cmd_board_info(void) { // TODO print more information
SerialUSB.println("Board information");
SerialUSB.println("=================");

SerialUSB.print("* Clock speed (MHz): ");
SerialUSB.println(CYCLES_PER_MICROSECOND);

SerialUSB.print("* BOARD_LED_PIN: ");
SerialUSB.println(BOARD_LED_PIN);

SerialUSB.print("* BOARD_BUTTON_PIN: ");
SerialUSB.println(BOARD_BUTTON_PIN);

SerialUSB.print("* GPIO information (BOARD_NR_GPIO_PINS = ");
SerialUSB.print(BOARD_NR_GPIO_PINS);
SerialUSB.println("):");
print_board_array("ADC pins", boardADCPins, BOARD_NR_ADC_PINS);
print_board_array("PWM pins", boardPWMPins, BOARD_NR_PWM_PINS);
print_board_array("Used pins", boardUsedPins, BOARD_NR_USED_PINS);
}



6 changes: 6 additions & 0 deletions utils.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#include "wirish.h"

// Comment out to disable USB printouts
#define USB_VERBOSE

// ASCII escape character
#define ESC ((uint8)27)

// Default USART baud rate
#define BAUD 9600


void cmd_print_help(void);
void cmd_board_info(void);
void set_prescale(timer_dev *dev);
void init_all_timers(uint16 prescale);
void enable_usarts(void);
Expand Down

0 comments on commit 7a9d01f

Please sign in to comment.