Martin Winkler
/
ProcVisDemo
Programmmmm
Fork of ProcVisDemo by
Revision 2:78185950c376, committed 2017-02-28
- Comitter:
- winkler_martin
- Date:
- Tue Feb 28 07:18:47 2017 +0000
- Parent:
- 1:e88b745f2ca2
- Commit message:
- hi
Changed in this revision
BtnEventM0.h | Show annotated file Show diff for this revision Revisions of this file |
ProcVisDemo.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r e88b745f2ca2 -r 78185950c376 BtnEventM0.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BtnEventM0.h Tue Feb 28 07:18:47 2017 +0000 @@ -0,0 +1,174 @@ + +// V4.0 + +class BtnEventM0 { + public: + int16_t pressed; + + BtnEventM0(PinName pin) : _isr(pin) + { pressed=0; } + + // Ist eine steigende Flanke aufgetreten ? + int CheckFlag(); + + // 1..Button is pressed else 0 + int CheckButton() + { return _isr.read(); } + + void Init(); + // { _isr.rise(this,&BtnEventM0::RisingISR); } + + void RisingISR(); + + protected: + InterruptIn _isr; +}; + +void BtnEventM0::Init() + { _isr.rise(this,&BtnEventM0::RisingISR); } + +void BtnEventM0::RisingISR() +{ + if( _isr.read() ) + pressed = 1; +} + +int BtnEventM0::CheckFlag() +{ + if( pressed ) + { pressed=0; return 1; } + return 0; +} + + + + + +/* +class BtnEventM02 : public BtnEventM0 +{ +public: + BtnEventM02(PinName pin) : BtnEventM0(pin) { + _tm.stop(); + _tm.reset(); + _state=1; + } + + void Init() { + _isr.rise(this, &BtnEventM02::RisingISR); + } + + void RisingISR() { + if( !_isr.read() ) + return; + pressed = 1; + _tm.start(); + _state = 2; + } + + void CheckButton() { + if( _state==1 ) + return; + if( _state==2 ) { + if( !_isr.read() ) { + _state = 1; + return; + } + if( _tm.read_ms()>500 ) { + _tm.reset(); + _state = 3; + pressed = 1; + } + } else if( _state==3 ) { + if( !_isr.read() ) { + _state = 1; + return; + } + if( _tm.read_ms()>100 ) { + _tm.reset(); + _state = 3; + pressed = 1; + } + } + } +private: + int16_t _state; + Timer _tm; +}; +*/ + +class AnalogInHL : public AnalogIn +{ +public: + AnalogInHL(PinName pin) : AnalogIn(pin) { } + int Read() { + return read_u16()>>6; + } +}; + +class BtnEventM0S { + public: + BtnEventM0S(PinName pin) : _btn(pin) { } + + void Init() {} + + // Ist eine steigende Flanke aufgetreten ? + int CheckFlag() + { + if( _btn ) + { wait_ms(100); return 1; } + else + return 0; + } + + protected: + DigitalIn _btn; +}; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r e88b745f2ca2 -r 78185950c376 ProcVisDemo.cpp --- a/ProcVisDemo.cpp Fri Oct 09 07:58:26 2015 +0000 +++ b/ProcVisDemo.cpp Tue Feb 28 07:18:47 2017 +0000 @@ -1,5 +1,6 @@ #include "mbed.h" #include "Serial_HL.h" +#include "BtnEventM0.h" SerialBLK pc(USBTX, USBRX); SvProtocol ua0(&pc); @@ -12,29 +13,35 @@ void CommandHandler(); +AnalogInHL poti(p15); +AnalogInHL ldr(p16); + int main(void) { pc.format(8,SerialBLK::None,1); pc.baud(115200); leds = 9; - ua0.SvMessage("SvTest_Serial_HL"); // Meldung zum PC senden + ua0.SvMessage("SvTest_Serial_HL5"); // Meldung zum PC senden int16_t sv1=0, sv2=100; + float sv3=0.0; Timer stw; stw.start(); while(1) { CommandHandler(); - if( ua0.acqON && (stw.read_ms()>100) ) { // 10Hz + if( ua0.acqON && (stw.read_ms()>10) ) { // 100Hz // dieser Teil wird mit 10Hz aufgerufen stw.reset(); sv1++; sv2++; + sv3 += 0.1; if( ua0.acqON ) { // nur wenn vom PC aus das Senden eingeschaltet wurde // wird auch etwas gesendet - ua0.WriteSvI16(1, sv1); - ua0.WriteSvI16(2, sv2); + ua0.WriteSvI16(1, poti.Read()); + ua0.WriteSvI16(2, ldr.Read()); + //ua0.WriteSV(3, sv3); } } } @@ -61,6 +68,13 @@ // für die Analyse den Wert einfach nur zum PC zurücksenden ua0.SvPrintf("Command2 %d %d", idata1, idata2); } + if(cmd==3) { + leds = ua0.ReadI16(); + ua0.SvPrintf("cmd3, Set LEDs"); + } + if(cmd==4) { + ua0.SvPrintf("LEDs= %d", (int)leds); + } }