Niels Leijen / PowerControl

PowerControl.cpp

Committer:
kwasymodo
Date:
2017-05-12
Revision:
2:1e3291e8294d
Parent:
1:1bae9ab7241e
Child:
3:54792b95c570

File content as of revision 2:1e3291e8294d:

#include "PowerControl.h"

extern RawSerial pc;
//extern DigitalOut ledError;
extern CAN can;

PowerControl::PowerControl(PinName button):
    _button(button), _canControl(BUCK2)
{
    enabled = false;
    
    _button.setSamplesTillHeld( 200 );
    _button.attach_asserted_held( this, &PowerControl::goSleep );
    _button.attach_asserted( this, &PowerControl::goWakeup );
}

void PowerControl::goSleep(){
#ifdef DEBUG
    pc.printf("going to sleep\r\n");
#endif
    enabled = false;
    
    //while(!biemDisable());
    while(!_canControl.disable()); // must be last
    
#ifdef DEBUG
    pc.printf("zzzzzzzzz.....r\n");
#endif

    sleep();
}

void PowerControl::goWakeup(){
    if(!enabled){
#ifdef DEBUG
        pc.printf("waking up\r\n");
#endif
    while(!_canControl.enable()); // must be first
    //while(!biemEnable());


#ifdef DEBUG
        pc.printf("fully awake\r\n");
#endif
    }
}