Prvni odevzdani

This commit is contained in:
Pavel Brychta 2019-08-13 09:30:05 +02:00
parent 7808743109
commit 4f224efb68
4 changed files with 216 additions and 0 deletions

22
library.json Normal file
View File

@ -0,0 +1,22 @@
{
"name":"SigLED",
"description":"Handle signalling LED easily",
"keywords":"signalling,indiaction,led",
"authors":
{
"name": "Pavel Brychta",
"maintainer": true
},
"repository":
{
"type": "git",
"url": "http://git.xpablo.cz/xPablo.cz/SigLed"
},
"version": "1.0.0",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",
"build": {
"libCompatMode": 2
}
}

9
library.properties Normal file
View File

@ -0,0 +1,9 @@
name=SigLED
version=1.0.0
author=Pavel Brychta
maintainer=Pavel Brychta
sentence=Handle signalling LED easily
paragraph=Handle signalling LED easily
category=Other
url=http://git.xpablo.cz/xPablo.cz/SigLed
architectures=*

113
src/sigLed.cpp Normal file
View File

@ -0,0 +1,113 @@
// Obsluha LED signalizace
#include <Arduino.h>
#include "sigLed.h"
SigLED::SigLED(int pin, int ledon, int ledoff)
{
_pin = pin;
_ledon = ledon;
_ledoff = ledoff;
}
void SigLED::rtLed(void)
{
switch (_state)
{
case LS_RUN:
{
uint8_t instr;
if (NULL != _signal)
instr = *_ptr; // instrukce
else if (NULL != _psignal)
instr = pgm_read_byte(_pptr);
else
instr = LEDS_STOP;
switch (instr & 0xc0)
{
case LEDS_ONFOR:
digitalWrite(_pin, _ledon);
_timer = 10ul * ((instr & 0x3F) + 1);
_state = LS_WAIT;
break;
case LEDS_OFFFOR:
digitalWrite(_pin, _ledoff);
_timer = 10ul * ((instr & 0x3F) + 1);
_state = LS_WAIT;
break;
case LEDS_STOP:
_state = LS_IDLE;
break;
case LEDS_RESTART:
_ptr = _signal;
_pptr = _psignal;
break;
}
}
break;
case LS_WAIT:
--_timer;
if (0 == _timer)
{
_state = LS_RUN;
++_ptr;
++_pptr;
}
break;
default:
break;
}
}
void SigLED::begin(void)
{
pinMode(_pin, OUTPUT);
digitalWrite(_pin, _ledoff);
_state = LS_IDLE;
_handler.attach_ms(10, lh, this);
}
void SigLED::set(const uint8_t *signal)
{
noInterrupts();
_signal = signal;
_ptr = _signal;
_psignal = NULL;
_state = LS_RUN;
interrupts();
}
void SigLED::set(PGM_P signal)
{
noInterrupts();
_psignal = signal;
_pptr = _psignal;
_signal = NULL;
_state = LS_RUN;
interrupts();
}
void SigLED::start()
{
noInterrupts();
_ptr = _signal;
_pptr = _psignal;
_state = LS_RUN;
interrupts();
}
void SigLED::lh(SigLED *ptr)
{
SigLED *pled = ptr;
pled->rtLed();
}

72
src/sigLed.h Normal file
View File

@ -0,0 +1,72 @@
/**
* @file sigLed.h
* @author Pavel Brychta, http://www.xpablo.cz
*
* Copyright (c) 2015,16 Pavel Brychta. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef _sigled_h_
#define _sigled_h_
#include <Ticker.h>
#include <pgmspace.h>
typedef struct
{
}ledsignal_t;
enum
{
LEDS_ONFOR = 0x00, // rozsviti LED na delku, ktera je uvedena v nizsich 6-ti bitech (+1) [100ms], 0 znamena, ze se rozsviti na 100ms
LEDS_OFFFOR = 0x40,
LEDS_STOP = 0x80,
LEDS_RESTART = 0xc0
};
class SigLED
{
// typedef void (LED::*runtime)(void);
protected:
int _pin; // pin, na kterem je LED pripojena
Ticker _handler; // obsluha LED signalizace
const uint8_t *_signal; // ukazatel na vzor signalizace
PGM_P _psignal;
const uint8_t *_ptr; // ukazatel na aktualne zpracovavane misto v signalizaci
PGM_P _pptr;
uint32_t _timer; // casovani
int _ledon;
int _ledoff;
enum
{
LS_IDLE, // klid, cekame na zmenu (zavolani set, nebo start)
LS_RUN, // bezi automat
LS_WAIT, // cekame v automatu
}_state; // stav automatu
public:
SigLED(int pin, int ledon, int ledoff);
void begin(void);
void set(const uint8_t *signal);
// void set(const __FlashStringHelper *signal);
void set(PGM_P signal);
void start();
// static void lh(void *ptr);
static void lh(SigLED *ptr);
void rtLed(void); // vykonna metoda
};
#endif