Read modify and generate PPM
Fork of PPM by
Revision 1:3649456c67ef, committed 2017-06-09
- Comitter:
- edy05
- Date:
- Fri Jun 09 08:34:42 2017 +0000
- Parent:
- 0:ab42e541f04d
- Commit message:
- PPM read class
Changed in this revision
diff -r ab42e541f04d -r 3649456c67ef PPMIn.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PPMIn.cpp Fri Jun 09 08:34:42 2017 +0000 @@ -0,0 +1,43 @@ +#include "mbed.h" +#include "PPMIn.h" + +PpmIn::PpmIn(PinName pin): ppm(pin), pc_com(USBTX, USBRX) +{ + pc_com.printf("Constructor say hi!"); + current_channel = 0; + state = false; + timer.start(); + ppm.rise(this, &PpmIn::rise); + +} + +uint16_t* PpmIn::getPpm() +{ + uint16_t* p_out[CHANNELS+2]; + *p_out = &channels[0]; + return *p_out; + +} + +void PpmIn::rise() +{ + uint16_t time = timer.read_us(); + + //pc_com.printf("Rise say hi!"); + // we are in synchro zone + if(time > 2500) + { + current_channel = 0; + // return values + state = true; + } + else + { + channels[current_channel] = timer.read_us(); + current_channel += 1; + } + + timer.reset(); + + //if (current_channel > (CHANNELS + 2 - 1)); //+frame and - 1 indexing of channels list +} \ No newline at end of file
diff -r ab42e541f04d -r 3649456c67ef PPMIn.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PPMIn.h Fri Jun 09 08:34:42 2017 +0000 @@ -0,0 +1,31 @@ +#ifndef CH_PPM_IN +#define CH_PPM_IN + + + +class PpmIn +{ + public: + + static const uint8_t CHANNELS = 8; + + uint16_t period; + uint16_t channels[CHANNELS+2]; + bool state; + + PpmIn(PinName pin); + + uint16_t* getPpm(); + void rise(); + + + protected: + InterruptIn ppm; + Serial pc_com; + Timer timer; + uint8_t current_channel; + + +}; + +#endif \ No newline at end of file
diff -r ab42e541f04d -r 3649456c67ef PPMOut.cpp --- a/PPMOut.cpp Sun Jan 08 20:17:29 2017 +0000 +++ b/PPMOut.cpp Fri Jun 09 08:34:42 2017 +0000 @@ -52,8 +52,7 @@ void PpmOut::resetChannels() { int8_t channel; - uint16_t sum_channels = 0; - + current_dot = 0; memset(dots, 0x00, DOTS); for(channel = 0; channel < channel_number; channel++) {
diff -r ab42e541f04d -r 3649456c67ef PPMOut.h --- a/PPMOut.h Sun Jan 08 20:17:29 2017 +0000 +++ b/PPMOut.h Fri Jun 09 08:34:42 2017 +0000 @@ -7,9 +7,9 @@ static const uint16_t CHANNEL_SYNC = 300; // us static const uint16_t CHANNEL_PAD_SYNC = 1000 - CHANNEL_SYNC; // us static const uint16_t FRAME_SYNC = 5000; // us - static const uint16_t FRAME_LEN = 22300; // us - static const uint16_t MAX_CHANNEL_VALUE = 1000; // us - static const uint16_t MIN_CHANNEL_VALUE = 0; + static const uint16_t FRAME_LEN = 20000; // us + static const uint16_t MAX_CHANNEL_VALUE = 1980; // us + static const uint16_t MIN_CHANNEL_VALUE = 1020; static const uint16_t DOTS = MAX_CHANNELS*2+2; // two dots per channel + FRAME_SYNC /* Will start the PPM output */