a
Dependencies: mbed
PPM/PPMIn.cpp@1:dd6e70abeb8e, 2018-05-25 (annotated)
- Committer:
- halusis
- Date:
- Fri May 25 08:09:17 2018 +0000
- Revision:
- 1:dd6e70abeb8e
- Parent:
- 0:f0b20f502059
a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
halusis | 0:f0b20f502059 | 1 | #include "mbed.h" |
halusis | 0:f0b20f502059 | 2 | #include "PPMIn.h" |
halusis | 0:f0b20f502059 | 3 | #include "Pin_Assign.h" |
halusis | 0:f0b20f502059 | 4 | |
halusis | 0:f0b20f502059 | 5 | PpmIn::PpmIn(PinName pin): ppm(pin)//, pc_com(USBTX, USBRX) |
halusis | 0:f0b20f502059 | 6 | { |
halusis | 0:f0b20f502059 | 7 | //pc_com.printf("Constructor say hi!"); |
halusis | 0:f0b20f502059 | 8 | current_channel = 0; |
halusis | 0:f0b20f502059 | 9 | state = false; |
halusis | 0:f0b20f502059 | 10 | timer.start(); |
halusis | 0:f0b20f502059 | 11 | ppm.rise(this, &PpmIn::rise); |
halusis | 0:f0b20f502059 | 12 | |
halusis | 0:f0b20f502059 | 13 | } |
halusis | 0:f0b20f502059 | 14 | |
halusis | 0:f0b20f502059 | 15 | uint16_t* PpmIn::getPpm() |
halusis | 0:f0b20f502059 | 16 | { |
halusis | 0:f0b20f502059 | 17 | uint16_t* p_out[CHANNELS+2]; |
halusis | 0:f0b20f502059 | 18 | *p_out = &channels[0]; |
halusis | 0:f0b20f502059 | 19 | //pc_com.printf("%d",channels[0]); |
halusis | 0:f0b20f502059 | 20 | return *p_out; |
halusis | 0:f0b20f502059 | 21 | } |
halusis | 0:f0b20f502059 | 22 | |
halusis | 0:f0b20f502059 | 23 | void PpmIn::rise() |
halusis | 0:f0b20f502059 | 24 | { |
halusis | 0:f0b20f502059 | 25 | uint16_t time = timer.read_us(); |
halusis | 0:f0b20f502059 | 26 | |
halusis | 0:f0b20f502059 | 27 | //pc.printf("%d\n",time); |
halusis | 0:f0b20f502059 | 28 | |
halusis | 0:f0b20f502059 | 29 | //pc_com.printf("Rise say hi!"); |
halusis | 0:f0b20f502059 | 30 | // we are in synchro zone |
halusis | 0:f0b20f502059 | 31 | if(time > 2500) |
halusis | 0:f0b20f502059 | 32 | { |
halusis | 0:f0b20f502059 | 33 | current_channel = 0; |
halusis | 0:f0b20f502059 | 34 | // return values |
halusis | 0:f0b20f502059 | 35 | state = true; |
halusis | 0:f0b20f502059 | 36 | } |
halusis | 0:f0b20f502059 | 37 | else |
halusis | 0:f0b20f502059 | 38 | { |
halusis | 0:f0b20f502059 | 39 | channels[current_channel] = timer.read_us(); |
halusis | 0:f0b20f502059 | 40 | current_channel += 1; |
halusis | 0:f0b20f502059 | 41 | } |
halusis | 0:f0b20f502059 | 42 | |
halusis | 0:f0b20f502059 | 43 | timer.reset(); |
halusis | 0:f0b20f502059 | 44 | |
halusis | 0:f0b20f502059 | 45 | //if (current_channel > (CHANNELS + 2 - 1)); //+frame and - 1 indexing of channels list |
halusis | 0:f0b20f502059 | 46 | } |