Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef BLINK_H_LABVANT
- #define BLINK_H_LABVANT
- #define NORMAL_ON_COUNT 5000
- #define NORMAL_OFF_COUNT 5000
- #include "AVRBase.h"
- class Blink : public AVRBase {
- public:
- Blink();
- ~Blink();
- void SetLEDGPIO(uint8_t nPort) { m_nLedPort = nPort; PrepareLEDPort(); }
- void SetLEDOnCount(uint32_t nCount) { m_nChosenOnCount = nCount; }
- void SetLEDOffCount(uint32_t nCount) { m_nChosenOffCount = nCount; }
- void PrepareLEDPort();
- void TurnLEDOn();
- void TurnLEDOff();
- void ManageLED();
- void BlinkLED();
- void StopLED();
- void AttentionBlinkLED(uint8_t);
- private:
- uint8_t m_nLedPort;
- volatile bool m_bBlinking;
- volatile bool m_bAttention;
- volatile bool m_bPeriodComplete;
- volatile uint8_t m_nNumBlinks;
- volatile uint8_t m_nAttentionCounter;
- volatile long m_nCounter;
- volatile bool m_bLEDisOn;
- volatile long m_nLedOffCount;
- volatile long m_nLedOnCount;
- volatile long m_nBlinkCount;
- volatile long m_nChosenOnCount, m_nChosenOffCount, m_nChosenAttentionOnCount, m_nChosenAttentionOffCount;
- };
- #endif
- #include "Blink.h"
- Blink::Blink() {
- m_nLedPort = 7;
- m_nChosenOnCount = NORMAL_ON_COUNT;
- m_nChosenOffCount = NORMAL_OFF_COUNT;
- m_nLedOffCount = NORMAL_OFF_COUNT;
- m_nLedOnCount = NORMAL_ON_COUNT;
- m_bBlinking = false;
- m_bAttention = false;
- m_nAttentionCounter = 0;
- m_nCounter = 0;
- }
- Blink::~Blink() {
- }
- void Blink::PrepareLEDPort() {
- switch (m_nLedPort) {
- case 1: GPIO1_IS_OUTPUT; break;
- case 2: GPIO2_IS_OUTPUT; break;
- case 3: GPIO3_IS_OUTPUT; break;
- case 4: GPIO4_IS_OUTPUT; break;
- case 5: GPIO5_IS_OUTPUT; break;
- case 6: GPIO6_IS_OUTPUT; break;
- case 7: GPIO7_IS_OUTPUT; break;
- case 8: GPIO8_IS_OUTPUT; break;
- case 9: GPIO9_IS_OUTPUT; break;
- case 10: GPIO10_IS_OUTPUT; break;
- case 11: GPIO11_IS_OUTPUT; break;
- default: GPIO7_IS_OUTPUT; break;
- }
- }
- void Blink::TurnLEDOn() {
- switch (m_nLedPort) {
- case 1: GPIO1_HIGH; break;
- case 2: GPIO2_HIGH; break;
- case 3: GPIO3_HIGH; break;
- case 4: GPIO4_HIGH; break;
- case 5: GPIO5_HIGH; break;
- case 6: GPIO6_HIGH; break;
- case 7: GPIO7_HIGH; break;
- case 8: GPIO8_HIGH; break;
- case 9: GPIO9_HIGH; break;
- case 10: GPIO10_HIGH; break;
- case 11: GPIO11_HIGH; break;
- default: GPIO7_HIGH; break;
- }
- m_bLEDisOn = true;
- }
- void Blink::TurnLEDOff() {
- switch (m_nLedPort) {
- case 1: GPIO1_LOW; break;
- case 2: GPIO2_LOW; break;
- case 3: GPIO3_LOW; break;
- case 4: GPIO4_LOW; break;
- case 5: GPIO5_LOW; break;
- case 6: GPIO6_LOW; break;
- case 7: GPIO7_LOW; break;
- case 8: GPIO8_LOW; break;
- case 9: GPIO9_LOW; break;
- case 10: GPIO10_LOW; break;
- case 11: GPIO11_LOW; break;
- default: GPIO7_LOW; break;
- }
- m_bLEDisOn = false;
- }
- void Blink::ManageLED() {
- m_nCounter++;
- if (m_bBlinking) {
- if (m_bLEDisOn) {
- if (m_nCounter > m_nLedOnCount) {
- TurnLEDOff();
- m_nCounter = 0;
- m_bPeriodComplete = true;
- }
- }
- else {
- if (m_nCounter > m_nLedOffCount) {
- TurnLEDOn();
- m_nCounter = 0;
- m_bPeriodComplete = false;
- }
- }
- if ( m_bAttention ) {
- if (m_bPeriodComplete ) {
- m_bPeriodComplete = false;
- m_nAttentionCounter--;
- }
- if (m_nAttentionCounter == 0) {
- m_bBlinking = false;
- m_nCounter = 0;
- }
- }
- }
- else {
- if (m_nCounter > (3 * (m_nLedOnCount + m_nLedOffCount))) {
- m_bBlinking = true;
- m_bAttention = true;
- m_nAttentionCounter = m_nNumBlinks;
- m_nCounter = 0;
- }
- }
- }
- void Blink::BlinkLED() {
- m_bBlinking = true;
- m_bAttention = false;
- m_nLedOnCount = m_nChosenOnCount;
- m_nLedOffCount = m_nChosenOffCount;
- }
- void Blink::StopLED() {
- m_bBlinking = false;
- m_bAttention = false;
- }
- void Blink::AttentionBlinkLED(uint8_t nTimes) {
- m_bAttention = true;
- m_nNumBlinks = nTimes;
- m_nAttentionCounter = m_nNumBlinks;
- }
Advertisement
Add Comment
Please, Sign In to add comment