Skip to content

mrkaleArduinoLib/gbj_appcore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gbj_appcore

This is an application library, which is used usually as a project library for particular PlatformIO project. It encapsulates common core methods for project centric application libraries and acts as their parent class. The encapsulation provides following advantages:

  • Functionality is hidden from the main sketch.
  • The library is reusable for various projects providing basic functionality.
  • Update in library is valid for all involved projects.
  • It provides error handling for all derived classes.

Fundamental functionality

  • Unified error handling.
  • Enumerated result and error codes.
  • Detecting microcontroller restart (boot) reason.
  • Registering HTTP response codes and texts.
  • Rounding float numbers.

Dependency

Arduino platform

  • Arduino.h: Main include file for the Arduino SDK.
  • avr/pgmspace.h: Processing flashed strings.
  • inttypes.h: Integer type conversions. This header file includes the exact-width integer definitions and extends them with additional facilities provided by the implementation.

Espressif ESP8266 platform

  • Arduino.h: Main include file for the Arduino platform.
  • pgmspace.h: Processing flashed strings.
  • user_interface.h: Various macros and definitions.

Espressif ESP32 platform

  • Arduino.h: Main include file for the Arduino platform.
  • pgmspace.h: Processing flashed strings.

Custom enumerations

Result and error codes

  • ResultCodes::SUCCESS: Result code for successful processing.
  • ResultCodes::ERROR_UKNOWN: Unexpected or not recognized error.
  • ResultCodes::ERROR_NOINIT: Not initialized yet.
  • ResultCodes::ERROR_NODEVICE: No device detected.
  • ResultCodes::ERROR_PINS: Wrong GPIO assignment.
  • ResultCodes::ERROR_ADDR: No or wrong address.
  • ResultCodes::ERROR_DATA: Not or wrong data.
  • ResultCodes::ERROR_ACK: No acknoledgment for a comunicating device.
  • ResultCodes::ERROR_CONNECT: Connection failed.
  • ResultCodes::ERROR_PUBLISH: Publishing failed.
  • ResultCodes::ERROR_SUBSCRIBE: Subsribing failed.
  • ResultCodes::ERROR_AUTH: Authorization failed.

Boot reason codes

  • BootReasons::BOOT_UNKNOWN: Not detected or unknown.
  • BootReasons::BOOT_DEFAULT_RST: Normal startup by power on.
  • BootReasons::BOOT_WDT_RST: Hardware watch dog reset.
  • BootReasons::BOOT_EXCEPTION_RST: Exception reset, GPIO status won’t change.
  • BootReasons::BOOT_SOFT_WDT_RST: Software watch dog reset, GPIO status won’t change.
  • BootReasons::BOOT_INT_WDT_RST: Interrupt watch dog reset.
  • BootReasons::BOOT_TASK_WDT_RST: Task watch dog reset.
  • BootReasons::BOOT_SOFT_RESTART: Software restart, system restart, GPIO status won’t change.
  • BootReasons::BOOT_DEEP_SLEEP_AWAKE: Wake up from deep-sleep.
  • BootReasons::BOOT_EXT_SYS_RST: External system reset (assertion of reset pin).
  • BootReasons::BOOT_DEEPSLEEP: After exiting deep sleep mode.
  • BootReasons::BOOT_BROWNOUT: Brownout reset (software or hardware).
  • BootReasons::BOOT_SDIO: Reset over SDIO.
  • BootReasons::BOOT_WAKEUP_UNDEFINED: Not caused by exit from deep sleep.
  • BootReasons::BOOT_WAKEUP_ALL: Not a wakeup cause.
  • BootReasons::BOOT_WAKEUP_EXT0: Wakeup caused by external signal using RTC_IO.
  • BootReasons::BOOT_WAKEUP_EXT1: Wakeup caused by external signal using RTC_CNTL.
  • BootReasons::BOOT_WAKEUP_TIMER: Wakeup caused by timer.
  • BootReasons::BOOT_WAKEUP_TOUCHPAD: Wakeup caused by touchpad.
  • BootReasons::BOOT_WAKEUP_ULP: Wakeup caused by ULP program.
  • BootReasons::BOOT_WAKEUP_GPIO: Wakeup caused by GPIO (light sleep only).
  • BootReasons::BOOT_WAKEUP_UART: Wakeup caused by UART (light sleep only).

Custom data types

Interface

ResultCodes

Description

Enumeration with result and error codes.

Syntax

ResultCodes::<code_name>

Back to interface

BootReasons

Description

Enumeration with boot reason codes.

Syntax

BootReasons::<code_name>

Back to interface

gbj_appcore()

Description

Constructor creates the class instance object, determines microcontroller reset reason, and sets recent result code to SUCCESS.

Syntax

gbj_appcore()

Parameters

None

Returns

Object determining microcontroller reset reason. However, it is not intended to be instantiated as itself, only in form of a child class instance.

Back to interface

setLastResult()

Description

The method sets the internal status of recent processing to input value.

  • Without input parameter the method sets success internal status with result constant SUCCESS.

Syntax

ResultCodes setLastResult(ResultCodes lastResult)

Parameters

  • lastResult: Desired result code that should be set as a last result code.

Returns

New (actual) result code of the recent operation.

See also

getLastResult()

Back to interface

getLastResult()

Description

The method returns a result or error code of the recent operation. It is usually called for error handling in a sketch.

Syntax

ResultCodes getLastResult()

Parameters

None

Returns

Some of result or error codes.

See also

setLastResult()

Back to interface

setLastHttpCode(), setLastHttpText()

Description

The particular method registers the HTTP response code and related text to the object for later utilization.

  • Without input HTTP code argument the method sets neutral HTTP response code.
  • Without input HTTP text argument the method sets empty HTTP response text.

Syntax

int setLastHttpCode(int lastHttpCode)
String setLastHttpCode(String lastHttpText)

Parameters

  • lastHttpCode: Recent HTTP response code.

    • Valid values: -32628 ~ 32628
    • Default value: 0
  • lastHttpText: Description of recent HTTP response code.

    • Valid values: String
    • Default value: empty string

Returns

The value of the just put input argument.

See also

getLastHttpCode()

getLastHttpText()

Back to interface

getLastHttpCode(), getLastHttpText()

Description

The method returns recent HTTP response code and its related text, if any.

Syntax

int getLastHttpCode()
String getLastHttpCode()

Parameters

None

Returns

The value of the recently registered HTTP response code and its related description.

See also

setLastHttpCode()

setLastHttpText()

Back to interface

getResetReason()

Description

The method returns a boot reason code of the recent microcontroller restart from boot reason codes.

  • The method is valid only for microcontrollers ESP5266 and ESP32. For others it returns always unknown boot reason.

Syntax

BootReasons getResetReason()

Parameters

None

Returns

Some of boot reason codes.

See also

getResetName()

Back to interface

getResultName()

Description

The method returns a pointer to textual name of last result of a recent operation.

Syntax

char *getResultName()

Parameters

None

Returns

Pointer to name of a recent operation.

See also

getLastResult()

Back to interface

getResetName()

Description

The method returns a pointer to textual name of a boot reason of the recent microcontroller restart.

  • The method is valid only for microcontrollers ESP5266 and ESP32. For others it returns always unknown boot reason name.
  • The boot reason names are equal to corresponding enumeration literals from boot reason codes.

Syntax

char *getResetName()

Parameters

None

Returns

Pointer to name of a microcontroller reset reason name.

See also

getResetReason()

Back to interface

isSuccess()

Description

The overloade method returns a flag whether the recent operation was successful or input argument is a success code.

Syntax

bool isSuccess()
bool isSuccess(ResultCodes lastResult)

Parameters

  • lastResult: Optional error code as a last result code.

Returns

Flag about successful processing of the recent operation or input as a success code.

See also

isError()

Back to interface

isError()

Description

The method returns a flag whether the recent operation failed or input argument is an error code. The corresponding error code can be obtained by the method getLastResult().

Syntax

bool isError()
bool isError(ResultCodes lastResult)

Parameters

  • lastResult: Optional error code as a last result code.

Returns

Flag about failing of the recent operation or input as an error code.

See also

getLastResult()

isSuccess()

Back to interface

roundoff()

Description

The method rounds provided rational number to desired decimal places.

Syntax

float roundoff(float value, byte prec)

Parameters

  • value: A number to be rounded.

    • Valid values: float numbers
    • Default value: none
  • prec: Rounding precision in number of decimal places.

    • Valid values: 0 ~ 255
    • Default value: none

Returns

Rounded rational number to provided number of decimal places.

Back to interface

About

Parent library for project centric application libraries.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages