Pracovni prvni odevzdani - zatim nefunkcni!

This commit is contained in:
2018-06-26 10:48:12 +02:00
parent 76eae4e788
commit 691ecffe39
20 changed files with 2150 additions and 34 deletions

117
lib/led/led.cpp Normal file
View File

@ -0,0 +1,117 @@
// Obsluha LED signalizace
#include <Arduino.h>
#include "led.h"
LED::LED(int pin, int ledon, int ledoff)
{
_pin = pin;
_ledon = ledon;
_ledoff = ledoff;
}
void LED::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 LED::begin(void)
{
pinMode(_pin, OUTPUT);
digitalWrite(_pin, _ledoff);
_state - LS_IDLE;
// _handler.attach_ms(10, lh, static_cast<void *>(this));
_handler.attach_ms(10, lh, this);
}
void LED::set(const uint8_t *signal)
{
noInterrupts();
_signal = signal;
_ptr = _signal;
_psignal = NULL;
_state = LS_RUN;
interrupts();
}
//void LED::set(const __FlashStringHelper *signal)
void LED::set(PGM_P signal)
{
noInterrupts();
// _psignal = reinterpret_cast<PGM_P>(signal);
_psignal = signal;
_pptr = _psignal;
_signal = NULL;
_state = LS_RUN;
interrupts();
}
void LED::start()
{
noInterrupts();
_ptr = _signal;
_pptr = _psignal;
_state = LS_RUN;
interrupts();
}
//void LED::lh(void *ptr)
void LED::lh(LED *ptr)
{
// LED *pled = static_cast<LED *>(ptr);
LED *pled = ptr;
pled->rtLed();
}

72
lib/led/led.h Normal file
View File

@ -0,0 +1,72 @@
/**
* @file led.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 _led_h_
#define _led_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 LED
{
// 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:
LED(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(LED *ptr);
void rtLed(void); // vykonna metoda
};
#endif

41
lib/readme.txt Normal file
View File

@ -0,0 +1,41 @@
This directory is intended for the project specific (private) libraries.
PlatformIO will compile them to static libraries and link to executable file.
The source code of each library should be placed in separate directory, like
"lib/private_lib/[here are source files]".
For example, see how can be organized `Foo` and `Bar` libraries:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) http://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- readme.txt --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
Then in `src/main.c` you should use:
#include <Foo.h>
#include <Bar.h>
// rest H/C/CPP code
PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.
More information about PlatformIO Library Dependency Finder
- http://docs.platformio.org/page/librarymanager/ldf.html

View File

@ -0,0 +1,36 @@
extern "C" {
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
}
#include <Arduino.h>
#include "uinterval.h"
// Public Methods //////////////////////////////////////////////////////////////
uint32_t uInterval::remains(void)
{
return _timeout - (micros() - _timefrom);
}
uint32_t uInterval::elapsed(void)
{
return micros() - _timefrom;
}
bool uInterval::expired(void)
{
if ((micros() - _timefrom) >= _timeout)
return true;
else
return false;
}
void uInterval::set(uint32_t tmout)
{
_timefrom = micros();
_timeout = tmout;
}

30
lib/uinterval/uinterval.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef uinterval_h
#define uinterval_h
/* uInterval
* Copyright (C) 2014, 2016 Pavel Brychta http://www.xpablo.cz
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* This program 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 General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses
*/
#include <inttypes.h>
class uInterval
{
protected:
uint32_t _timefrom;
uint32_t _timeout;
public:
bool expired(void);
void set(uint32_t tmout);
uint32_t elapsed(void);
uint32_t remains(void);
};
#endif
// EOF