Skip to content

Commit

Permalink
Merge branch 'feature/83' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidZemon committed Apr 7, 2016
2 parents 06c7ced + 1334a4a commit 69de51b
Show file tree
Hide file tree
Showing 25 changed files with 395 additions and 749 deletions.
4 changes: 2 additions & 2 deletions Examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ add_subdirectory(GettingStarted)
add_subdirectory(Hello)
add_subdirectory(Libpropeller_Pwm32)
add_subdirectory(PropWare_Blinky)
add_subdirectory(PropWare_DuplexUART)
add_subdirectory(PropWare_Eeprom)
add_subdirectory(PropWare_FileReader)
add_subdirectory(PropWare_FileWriter)
Expand All @@ -20,13 +19,14 @@ add_subdirectory(PropWare_Ping)
add_subdirectory(PropWare_Queue)
add_subdirectory(PropWare_Runnable)
add_subdirectory(PropWare_Scanner)
add_subdirectory(PropWare_SimplexUART)
add_subdirectory(PropWare_Simple_Hybrid)
add_subdirectory(PropWare_SPI)
add_subdirectory(PropWare_Spin2Dat)
add_subdirectory(PropWare_Stepper)
add_subdirectory(PropWare_StringBuilder)
add_subdirectory(PropWare_SynchronousPrinter)
add_subdirectory(PropWare_UARTRX)
add_subdirectory(PropWare_UARTTX)
add_subdirectory(PropWare_Utility)
add_subdirectory(PropWare_WatchDog)
add_subdirectory(PropWare_WS2812)
Expand Down
1 change: 0 additions & 1 deletion Examples/GettingStarted/GettingStarted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ int main () {
pwOut << "Hello, world!";
return 0;
}

6 changes: 0 additions & 6 deletions Examples/PropWare_DuplexUART/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion Examples/PropWare_L3G/L3G_Demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
// Includes
#include <PropWare/PropWare.h>
#include <PropWare/sensor/gyroscope/l3g.h>
#include <PropWare/serial/uart/simplexuart.h>

/** Pin number for MOSI (master out - slave in) */
const PropWare::Port::Mask MOSI = PropWare::Port::P0;
Expand Down
7 changes: 3 additions & 4 deletions Examples/PropWare_Scanner/Scanner_Demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ int main () {
char name[64];
unsigned int age;

pwOut.printf("Hello! I'd like to teach you how to use PropWare to read from the terminal!\n");
pwOut << "Hello! I'd like to teach you how to use PropWare to read from the terminal!\n";

do {
pwOut << "First, what's your name?\n>>> ";
pwIn.gets(userInput, sizeof(userInput));
strcpy(name, userInput);
pwIn >> name;

pwOut << "And how old are you?\n>>> ";
pwIn >> age;
Expand All @@ -63,7 +62,7 @@ int main () {
YES_NO_COMP);
} while (isAnswerNo(userInput));

pwOut.printf("Hello, %s!\n", name);
pwOut << "Hello, " << name << "!\n";
return 0;
}

Expand Down
6 changes: 6 additions & 0 deletions Examples/PropWare_UARTRX/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.3)
find_package(PropWare REQUIRED)

project(UARTRX_Demo)

create_simple_executable(${PROJECT_NAME} UARTRX_Demo.cpp)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file DuplexUART_Demo.cpp
* @file UARTTX_Demo.cpp
*
* @author David Zemon
*
Expand All @@ -25,7 +25,8 @@

#include <PropWare/utility/runnable.h>
#include <PropWare/PropWare.h>
#include <PropWare/serial/uart/halfduplexuart.h>
#include <PropWare/serial/uart/uartrx.h>
#include <PropWare/serial/uart/uarttx.h>
#include <PropWare/hmi/output/synchronousprinter.h>

// Create the test string - useful when testing with a terminal
Expand All @@ -35,35 +36,58 @@ const PropWare::Port::Mask TX_PIN = PropWare::Port::P12;
const PropWare::Port::Mask RX_PIN = PropWare::Port::P13;
const PropWare::UART::Parity PARITY = PropWare::UART::NO_PARITY;

void error (const PropWare::ErrorCode err);

class Listener : public PropWare::Runnable {
public:
template<size_t N>
Listener (const uint32_t (&stack)[N])
: Runnable(stack) {
}

void run ();
void run () {
PropWare::ErrorCode err;
int32_t receivedLength;

this->init();
pwSyncOut.printf("Ready to receive!\n");

while (1) {
receivedLength = sizeof(this->m_buffer);
if ((err = this->m_listener.fgets(this->m_buffer, &receivedLength)))
error(err);

pwSyncOut.printf("Data (%d chars): \"%s\"\n", receivedLength, this->m_buffer);
}
}

void init () {
this->m_listener.set_rx_mask(RX_PIN);
this->m_listener.set_baud_rate(BAUD_RATE);
this->m_listener.set_parity(PARITY);
//memset(m_buffer, 0, sizeof(m_buffer));

void init ();
// A very short wait to ensure the main cog has finished printing its "I'm ready" statement before we start
// printing ours
waitcnt(20 * MILLISECOND + CNT);
}

private:
PropWare::HalfDuplexUART m_listener;
char m_buffer[sizeof(TEST_STRING)];
PropWare::UARTRX m_listener;
char m_buffer[sizeof(TEST_STRING)];
};

void error (const PropWare::ErrorCode err);

/**
* @example DuplexUART_Demo.cpp
*
* Write "Hello world!" out via UART protocol and receive an echo
*
* @include PropWare_DuplexUART/CMakeLists.txt
* @include PropWare_UARTRX/CMakeLists.txt
*/
int main () {
uint32_t threadStack[256];
Listener listener(threadStack);
PropWare::SimplexUART speaker(TX_PIN);
uint32_t threadStack[256];
Listener listener(threadStack);
PropWare::UARTTX speaker(TX_PIN);

// Start our new cog and initialize the speaking UART
speaker.set_baud_rate(BAUD_RATE);
Expand All @@ -88,30 +112,3 @@ void error (const PropWare::ErrorCode err) {
waitcnt(100 * MILLISECOND);
}
}

void Listener::run () {
PropWare::ErrorCode err;
int32_t receivedLength;

this->init();
pwSyncOut.printf("Ready to receive!\n");

while (1) {
receivedLength = sizeof(this->m_buffer);
if ((err = this->m_listener.fgets(this->m_buffer, &receivedLength)))
error(err);

pwSyncOut.printf("Data (%d chars): \"%s\"\n", receivedLength, this->m_buffer);
}
}

void Listener::init () {
this->m_listener.set_rx_mask(RX_PIN);
this->m_listener.set_baud_rate(BAUD_RATE);
this->m_listener.set_parity(PARITY);
memset(m_buffer, 0, sizeof(m_buffer));

// A very short wait to ensure the main cog has finished printing its "I'm ready" statement before we start
// printing ours
waitcnt(10 * MILLISECOND + CNT);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ find_package(PropWare REQUIRED)

project(SimplexUART_Demo C CXX ASM)

create_simple_executable(${PROJECT_NAME} SimplexUART_Demo.cpp)
create_simple_executable(${PROJECT_NAME} UARTTX_Demo.cpp)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file SimplexUART_Demo.cpp
* @file UARTTX_Demo.cpp
*
* @author David Zemon
*
Expand All @@ -25,7 +25,7 @@

// Includes
#include <PropWare/PropWare.h>
#include <PropWare/serial/uart/simplexuart.h>
#include <PropWare/serial/uart/uarttx.h>
#include <PropWare/hmi/output/printer.h>

void error (const PropWare::ErrorCode err);
Expand All @@ -38,15 +38,15 @@ const int32_t DELAY = 200;
*
* Write "Hello world!" out via UART protocol
*
* @include PropWare_SimplexUART/CMakeLists.txt
* @include PropWare_UARTTX/CMakeLists.txt
*/
int main () {
PropWare::ErrorCode err;
PropWare::SimplexUART uart;
PropWare::UARTTX uart;

// Create an easy-to-test number pattern - useful when testing with a logic
// analyzer
char numberPattern[] = {
uint8_t numberPattern[] = {
0x01,
0x02,
0x03,
Expand All @@ -70,7 +70,7 @@ int main () {

while (1) {
// Test the number pattern
uart.puts(numberPattern);
uart.send_array((char *) numberPattern, sizeof(numberPattern));
waitcnt(DELAY * MILLISECOND + CNT);

// Test a basic string
Expand Down
7 changes: 6 additions & 1 deletion PropWare/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ set(PROPWARE_SOURCES
${CMAKE_CURRENT_LIST_DIR}/serial/i2c/i2c.h
${CMAKE_CURRENT_LIST_DIR}/serial/i2c/i2cbase.h
${CMAKE_CURRENT_LIST_DIR}/serial/spi/spi.h
${CMAKE_CURRENT_LIST_DIR}/serial/uart/uart.cpp # FIXME
${CMAKE_CURRENT_LIST_DIR}/serial/uart/halfduplexuart.h
${CMAKE_CURRENT_LIST_DIR}/serial/uart/shareduarttx.h
${CMAKE_CURRENT_LIST_DIR}/serial/uart/uart.cpp
${CMAKE_CURRENT_LIST_DIR}/serial/uart/uart.h
${CMAKE_CURRENT_LIST_DIR}/serial/uart/uartrx.h
${CMAKE_CURRENT_LIST_DIR}/serial/uart/uarttx.h
${CMAKE_CURRENT_LIST_DIR}/string/staticstringbuilder.h
${CMAKE_CURRENT_LIST_DIR}/string/stringbuilder.h
${CMAKE_CURRENT_LIST_DIR}/utility/comparator.cpp
Expand Down
8 changes: 5 additions & 3 deletions PropWare/hmi/input/scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
*/

#include <PropWare/hmi/input/scanner.h>
#include <PropWare/serial/uart/halfduplexuart.h>
#include <PropWare/serial/uart/uartrx.h>

PropWare::HalfDuplexUART _g_halfDuplexUart;
PropWare::Scanner pwIn(_g_halfDuplexUart, &pwOut);
#ifndef __PROPELLER_COG__
PropWare::UARTRX _g_uartrx;
PropWare::Scanner pwIn(_g_uartrx, &pwOut);
#endif
7 changes: 7 additions & 0 deletions PropWare/hmi/input/scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ class Scanner {
}
}

template<size_t N>
const ErrorCode get (char (&buffer)[N]) {
return this->gets(buffer, N);
}

/**
* @overload
*/
Expand Down Expand Up @@ -257,4 +262,6 @@ class Scanner {

}

#ifndef __PROPELLER_COG__
extern PropWare::Scanner pwIn;
#endif
9 changes: 6 additions & 3 deletions PropWare/hmi/output/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
*/

#include <PropWare/hmi/output/printer.h>
#include <PropWare/serial/uart/simplexuart.h>
#include <PropWare/serial/uart/uarttx.h>

const PropWare::Printer::Format PropWare::Printer::DEFAULT_FORMAT;
PropWare::SimplexUART _g_simplexUart;
const PropWare::Printer pwOut(_g_simplexUart);

#ifndef __PROPELLER_COG__
PropWare::UARTTX _g_uarttx;
const PropWare::Printer pwOut(_g_uarttx);
#endif
2 changes: 2 additions & 0 deletions PropWare/hmi/output/printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,10 @@ class Printer {

}

#ifndef __PROPELLER_COG__
/**
* @brief Most common use of printing in PropWare applications (not thread safe; see PropWare::pwSyncOut for
* multi-threaded printing)
*/
extern const PropWare::Printer pwOut;
#endif
6 changes: 4 additions & 2 deletions PropWare/hmi/output/synchronousprinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
*/

#include <PropWare/hmi/output/synchronousprinter.h>
#include <PropWare/serial/uart/sharedsimplexuart.h>
#include <PropWare/serial/uart/shareduarttx.h>

PropWare::SharedSimplexUART _g_sharedSimplexUart;
#ifndef __PROPELLER_COG__
PropWare::SharedUARTTX _g_sharedSimplexUart;
const PropWare::Printer _g_printer(_g_sharedSimplexUart);
const PropWare::SynchronousPrinter pwSyncOut(_g_printer);
#endif
Loading

0 comments on commit 69de51b

Please sign in to comment.