Skip to content

Commit

Permalink
General fixes and fix instance on ESP32
Browse files Browse the repository at this point in the history
  • Loading branch information
Naguissa committed Jan 25, 2023
1 parent 8b8afc7 commit 95244c2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=uSevenSegmentLib
version=1.0.2
version=1.0.3
author=Naguissa <naguissa@foroelectro.net>
maintainer=Naguissa <naguissa@foroelectro.net>
sentence=Really tiny library to basic 7 segments displays
Expand Down
25 changes: 13 additions & 12 deletions src/uSevenSegmentLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* @see <a href="https://github.com/Naguissa/uTimerLib">https://github.com/Naguissa/uTimerLib</a> - Needed dependecy
* @see <a href="https://www.foroelectro.net/librerias-arduino-ide-f29/usevensegmentlib-libreria-arduino-para-controlar-d-t193.html">https://www.foroelectro.net/librerias-arduino-ide-f29/usevensegmentlib-libreria-arduino-para-controlar-d-t193.html</a>
* @see <a href="mailto:naguissa@foroelectro.net">naguissa@foroelectro.net</a>
* @version 1.0.2
* @version 1.0.3
*/
#include <Arduino.h>
#include "uSevenSegmentLib.h"

/**
* \brief Static variable assignment to NULL
*/
uSevenSegmentLib * uSevenSegmentLib::_instance = NULL;
uSevenSegmentLib * uSevenSegmentLib::instance = NULL;


/**
Expand All @@ -32,17 +32,17 @@ uSevenSegmentLib * uSevenSegmentLib::_instance = NULL;
* @param pins array of pins {a, b, c, d, e, f, g, dot}
* @param muxes array of common pin for each display
*/
uSevenSegmentLib::uSevenSegmentLib(unsigned char displays, int pins[8], int *muxes) {
uSevenSegmentLib::uSevenSegmentLib(const unsigned char displays, int pins[8], int *muxes) {
_displays = displays;
unsigned char i;
for (i = 0; i < 8; i++) {
_pins[i] = pins[i];
pinMode(pins[i], OUTPUT);
}
// Get memory for all digits
_values = (unsigned char *) malloc(_displays);
_values = (unsigned char *) malloc(displays * sizeof(unsigned char));
// Get memory for all multiple displays muxes
_muxes = (int *) malloc(_displays);
_muxes = (int *) malloc(displays * sizeof(int));
for (i = 0; i < _displays; i++) {
_muxes[i] = muxes[i];
pinMode(muxes[i], OUTPUT);
Expand All @@ -57,7 +57,7 @@ uSevenSegmentLib::uSevenSegmentLib(unsigned char displays, int pins[8], int *mux
* @param muxes array of common pin for each display
* @param common_anode Set true to change to common_anode displays
*/
uSevenSegmentLib::uSevenSegmentLib(unsigned char displays, int pins[8], int *muxes, bool common_anode) {
uSevenSegmentLib::uSevenSegmentLib(const unsigned char displays, int pins[8], int *muxes, bool common_anode) {
if (common_anode) {
for (unsigned char i = 0; i < 10; i++) {
_mask[i] = _mask[i] xor B11111111;
Expand All @@ -80,7 +80,7 @@ uSevenSegmentLib::uSevenSegmentLib(unsigned char displays, int pins[8], int *mux
* @param muxes array of common pin for each display
* @param Refresh frequency (for all digits, will be multiplied by digits to calculate end result)
*/
uSevenSegmentLib::uSevenSegmentLib(unsigned char displays, int pins[8], int *muxes, unsigned int freq) {
uSevenSegmentLib::uSevenSegmentLib(const unsigned char displays, int pins[8], int *muxes, unsigned int freq) {
_freq = freq;
uSevenSegmentLib(displays, pins, muxes);
}
Expand All @@ -94,7 +94,7 @@ uSevenSegmentLib::uSevenSegmentLib(unsigned char displays, int pins[8], int *mux
* @param Refresh frequency (for all digits, will be multiplied by digits to calculate end result)
* @param common_anode Set true to change to common_anode displays
*/
uSevenSegmentLib::uSevenSegmentLib(unsigned char displays, int pins[8], int *muxes, unsigned int freq, bool common_anode) {
uSevenSegmentLib::uSevenSegmentLib(const unsigned char displays, int pins[8], int *muxes, unsigned int freq, bool common_anode) {
_freq = freq;
uSevenSegmentLib(displays, pins, muxes, common_anode);
}
Expand Down Expand Up @@ -184,24 +184,25 @@ void uSevenSegmentLib::zeroFill(bool zf) {
*/
void uSevenSegmentLib::attachInterrupt() {
extern uTimerLib TimerLib;
if (_instance == NULL) {
uSevenSegmentLib::_instance = this;
if (instance == NULL) {
instance = this;
unsigned long int period_us = 1000000 / _freq / _displays;
TimerLib.setInterval_us(uSevenSegmentLib::interrupt, period_us);
}
}


/**
* \brief Main public interrupt loop
*
* Calls private loop
*/

void uSevenSegmentLib::interrupt() {
_instance->_interrupt();
instance->_interrupt();
}



/**
* \brief Main private interrupt loop
*
Expand Down
13 changes: 7 additions & 6 deletions src/uSevenSegmentLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @see <a href="https://github.com/Naguissa/uTimerLib">https://github.com/Naguissa/uTimerLib</a> - Needed dependecy
* @see <a href="https://www.foroelectro.net/librerias-arduino-ide-f29/usevensegmentlib-libreria-arduino-para-controlar-d-t193.html">https://www.foroelectro.net/librerias-arduino-ide-f29/usevensegmentlib-libreria-arduino-para-controlar-d-t193.html</a>
* @see <a href="mailto:naguissa@foroelectro.net">naguissa@foroelectro.net</a>
* @version 1.0.2
* @version 1.0.3
*/
/** \file uSevenSegmentLib.h
* \brief uSevenSegmentLib header file
Expand All @@ -31,10 +31,10 @@
class uSevenSegmentLib {
public:
// Constructors
uSevenSegmentLib(unsigned char, int[8], int *);
uSevenSegmentLib(unsigned char, int[8], int *, unsigned int);
uSevenSegmentLib(unsigned char, int[8], int *, bool);
uSevenSegmentLib(unsigned char, int[8], int *, unsigned int, bool);
uSevenSegmentLib(const unsigned char, int[8], int *);
uSevenSegmentLib(const unsigned char, int[8], int *, unsigned int);
uSevenSegmentLib(const unsigned char, int[8], int *, bool);
uSevenSegmentLib(const unsigned char, int[8], int *, unsigned int, bool);

void set(long int);
long int get();
Expand All @@ -44,7 +44,8 @@

static void interrupt(void);

static uSevenSegmentLib *_instance;
static uSevenSegmentLib *instance;

private:
void _interrupt(void);

Expand Down

0 comments on commit 95244c2

Please sign in to comment.