API Access

Discussion as to what further enhancements people would like to see in the software
Post Reply
RWAP
Site Admin
Posts: 405
Joined: Wed Sep 13, 2017 9:20 pm
Location: Oswestry, Shropshire
Contact:

API Access

Post by RWAP »

One suggestion we have received has been to offer API access to the software functionality.

We would welcome ideas as to what people would like to be able to access and do through the API.

Initial suggestions are being able to control the three LEDs on the Retro-Printer module, for custom status indicators.
Retro-Printer Specialists
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module

Also Involved in:
Icephorm
RWAP
Site Admin
Posts: 405
Joined: Wed Sep 13, 2017 9:20 pm
Location: Oswestry, Shropshire
Contact:

Re: API Access

Post by RWAP »

As per http://forum.retroprinter.com/viewtopic.php?f=3&t=9 we are now making the necessary changes to the PCB to allow software control of the LEDs and the offline switch, so API access is a real possibility :D
Retro-Printer Specialists
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module

Also Involved in:
Icephorm
RWAP
Site Admin
Posts: 405
Joined: Wed Sep 13, 2017 9:20 pm
Location: Oswestry, Shropshire
Contact:

Re: API Access

Post by RWAP »

What is the best way to implement the API access??

Would a retroprinter.h be sufficient which allows you to access the functions to turn on / off the LEDs in C be sufficient?

I guess we should also add a function to read the status of the offline switch - so that could be used for a different function.
Retro-Printer Specialists
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module

Also Involved in:
Icephorm
RWAP
Site Admin
Posts: 405
Joined: Wed Sep 13, 2017 9:20 pm
Location: Oswestry, Shropshire
Contact:

Re: API Access

Post by RWAP »

In the absence of any comment, I have created an rpleds.h file, so that you can add access to the software LEDs by simply compiling your C program with

Code: Select all

gcc test.c rpleds.o -o test
This adds 3 functions:

Code: Select all

 
    void initialize_leds();    
    void led_on(char *ledname);
    void led_off(char *ledname);
initialize_leds() sets up the led variables, turns on the blue (power) LED and turns everything else off, so must be called first.
It will be called by the Retro-Printer software, so can be ignored for now.

led_on("green");
led_on("blue");
led_on("red");

are 3 simple calls to switch on the 3 leds in turn

led_off does the opposite.

I will then create a new config file which allows you to say which of these leds are to be controlled externally in which case, the Retro-Printer software will not turn them on/off (other than calling initialize_leds() ).
Retro-Printer Specialists
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module

Also Involved in:
Icephorm
RWAP
Site Admin
Posts: 405
Joined: Wed Sep 13, 2017 9:20 pm
Location: Oswestry, Shropshire
Contact:

Re: API Access

Post by RWAP »

We have now switched to using the wiringpi - so the instructions are different.

In order to control the LEDs, you will need to link in the file rpleds.o to your C program, so create your new C source code (say test.c) in /home/pi/temp/sdl/escparser and add the lines:

Code: Select all

#include <wiringPi.h>
#include "library/rpleds.h"
You then have access to 4 functions:
void wiringPiSetup();
void initialize_leds();
void led_on(char *ledname);
void led_off(char *ledname);

So your program needs to include:

Code: Select all

wiringPiSetup();
initialize_leds(); 
to set up the led variables and turns off all LEDs, so must be called first.

You can then control the three LEDs with the commands:

Code: Select all

led_on("green");
led_on("blue");
led_on("red");
switch on the specified LED.

You then compile your program with:

Code: Select all

gcc test.c rpleds.o -o test  -lwiringPi
Retro-Printer Specialists
RWAP Software
RWAP Adventures
SellMyRetro
Retro-Printer Module

Also Involved in:
Icephorm
Post Reply