Libreria libeS8CoreMng

Per lo sviluppo di applicazioni con i linguaggi standard "C", Python, Node.js, ecc viene fornita la libreria libeS8CoreMng che contiene definizioni e funzioni per gestire l'hardware del sistema SlimLine oltre a numerose funzioni utili.

Esempi

Come utilizzare gli esempi.
Dimostrativo PTP174: Il programma Main.cpp  richiama le altre sezioni di programma (Viste come funzioni) in cui sono eseguite le funzioni di libreria. Compilando il progetto con CodeLite ed eseguendo il programma S8CoreMng generato dal compilatore è possibile verificarne il funzionamento. Eseguire con il comando sudo ./S8CoreMng.

CodeLite (Ptp174)
// *****************************************************************************
// PROGRAM "Main.cpp"
// *****************************************************************************
// A main program, it calls the functions that show how to use the library.
//
// Note: If the system is executing the LogicLab run time, it must be stopped
// with the command: "sudo /etc/init.d/LLExecDaemon stop".
// -----------------------------------------------------------------------------

#include <Library.h>
#include <stdio.h>
#include <string.h>
#include <termio.h>
#include <unistd.h> 

// -----------------------------------------------------------------------------
// EXTERNAL FUNCTIONS
// -----------------------------------------------------------------------------
// External functions

extern bool LibraryInit(void);
extern bool PhrBusInit(void);
extern bool WatchDog(void);
extern bool PhrModules(void);

// -----------------------------------------------------------------------------
// GLOBAL VARIABLES
// -----------------------------------------------------------------------------
// Global variables

bool FirstLoop; //First execution loop
int8_t Kb; //Key pressed

// -----------------------------------------------------------------------------
// KEYBOARD HIT FUNCTION
// -----------------------------------------------------------------------------
// The function returns true if a key on the keyboard has been pressed.

bool KbHit(void)
{
    struct termios original;
    tcgetattr(STDIN_FILENO, &original);

    struct termios term;
    memcpy(&term, &original, sizeof(term));

    term.c_lflag &= ~ICANON;
    tcsetattr(STDIN_FILENO, TCSANOW, &term);

    int Ch=0;
    ioctl(STDIN_FILENO, FIONREAD, &Ch);

    tcsetattr(STDIN_FILENO, TCSANOW, &original);
    return(Ch != 0);
}

// -----------------------------------------------------------------------------
// MAIN PROGRAM
// -----------------------------------------------------------------------------

int main(int argc, char **argv)
{
    // -------------------------------------------------------------------------
    // CALL THE EXAMPLE PROGRAMS
    // -------------------------------------------------------------------------
    // Initialize library and peripheral bus.

    FirstLoop=true; //First execution loop
    printf("[LibraryInit...]\n");
    if (!LibraryInit()) return(0); //Initialize the library

    printf("\n[PhrBusInit...]\n");
    if (!PhrBusInit()) return(0); //Initialize the peripheral bus

    // Simply help menu, every command is executed simply by a keystroke.

    printf("\"a\":Analog command, acquires analog input and set analog output\n");
    printf("\"o\":Output command, reverses status of digital output\n");
    printf("\"s\":Sleep command, program sleeps waiting watchdog reboot\n");
    printf("\"x\":Exit command, gracefully terminates program execution\n");
    printf("...\n");

    // Cyclically execute programs that manage watchdog and peripheral modules.

    while (true)
    {
        // Check if a keyboard key has been pressed and read the key.

        Kb=0; //Key pressed
        if (KbHit()) read(0, &Kb, sizeof(Kb));

        // Executes program sections.

        if (!WatchDog()) return(0); //Manage the watch dog
        if (!PhrModules()) return(0); //Manage the peripheral modules
        FirstLoop=false; //First execution loop
    }
}

// [End of file]
Was this article helpful?