mirror of
https://github.com/thiagoralves/OpenPLC_v3.git
synced 2026-02-06 02:02:20 +08:00
Update debian, install wiringPi
Remove pigpio api, change wiringpi version Remove pigpio api, add wiringPi api Remove pigpio api, add wiringPi api
This commit is contained in:
19
Dockerfile
19
Dockerfile
@@ -1,4 +1,4 @@
|
||||
FROM debian:bullseye-20240722
|
||||
FROM debian:stable
|
||||
|
||||
COPY . /workdir
|
||||
|
||||
@@ -8,6 +8,23 @@ RUN mkdir /docker_persistent
|
||||
|
||||
VOLUME /docker_persistent
|
||||
|
||||
# get git, wget, dpkg-dev and gettext
|
||||
RUN apt update && apt install -y \
|
||||
git \
|
||||
wget \
|
||||
dpkg-dev \
|
||||
gettext
|
||||
|
||||
# clone WiringPi
|
||||
RUN git clone https://github.com/WiringPi/WiringPi.git /api
|
||||
|
||||
# change the directory
|
||||
WORKDIR /api
|
||||
|
||||
# build wiringPi and install it
|
||||
RUN ./build debian \
|
||||
&& apt install -y ./debian-template/wiringpi_3.14_arm64.deb
|
||||
|
||||
RUN ./install.sh docker \
|
||||
&& touch /docker_persistent/mbconfig.cfg \
|
||||
&& touch /docker_persistent/persistent.file \
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
OPENPLC_DIR="$PWD"
|
||||
SWAP_FILE="$OPENPLC_DIR/swapfile"
|
||||
WIRINGPI_VERSION="3.4"
|
||||
WIRINGPI_VERSION="3.14" # Support RPi 1..5, CM5, CM5(L), Pi500, GCLK (Generic Clock) for RPi5 is not supported.
|
||||
VENV_DIR="$OPENPLC_DIR/.venv"
|
||||
|
||||
function print_help_and_exit {
|
||||
@@ -73,24 +73,6 @@ function install_wiringpi {
|
||||
) || fail "Failed to install wiringpi."
|
||||
}
|
||||
|
||||
function install_pigpio {
|
||||
echo "[PIGPIO]"
|
||||
echo "Trying distribution package..."
|
||||
sudo apt-get install -y pigpio && return 0
|
||||
|
||||
echo "Falling back to direct download..."
|
||||
local URL="https://github.com/joan2937/pigpio/archive/master.zip"
|
||||
(
|
||||
set -e
|
||||
wget -c "$URL"
|
||||
unzip master.zip
|
||||
cd pigpio-master
|
||||
make
|
||||
sudo make install
|
||||
rm -f master.zip
|
||||
)
|
||||
}
|
||||
|
||||
function install_wiringop {
|
||||
echo "[WIRINGOP]"
|
||||
local URL="https://github.com/orangepi-xunlong/wiringOP/archive/master.zip"
|
||||
@@ -369,7 +351,7 @@ elif [ "$1" == "docker" ]; then
|
||||
elif [ "$1" == "rpi" ]; then
|
||||
echo "Installing OpenPLC on Raspberry Pi"
|
||||
linux_install_deps sudo
|
||||
install_pigpio
|
||||
install_wiringpi
|
||||
install_py_deps
|
||||
install_all_libs sudo
|
||||
install_systemd_service sudo
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <pigpio.h>
|
||||
#include <wiringPi.h>
|
||||
#include <wiringSerial.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "ladder.h"
|
||||
@@ -39,7 +40,7 @@
|
||||
|
||||
#define MAX_INPUT 14
|
||||
#define MAX_OUTPUT 11
|
||||
#define MAX_ANALOG_OUT 1
|
||||
#define MAX_ANALOG_OUT 1
|
||||
|
||||
/********************I/O PINS CONFIGURATION*********************
|
||||
* A good source for RaspberryPi I/O pins information is:
|
||||
@@ -50,15 +51,15 @@
|
||||
****************************************************************/
|
||||
//inBufferPinMask: pin mask for each input, which
|
||||
//means what pin is mapped to that OpenPLC input
|
||||
int inBufferPinMask[MAX_INPUT] = { 2, 3, 4, 17, 27, 22, 10, 9, 11, 5, 6, 13, 19, 26 };
|
||||
int inBufferPinMask[MAX_INPUT] = { 8, 9, 7, 0, 2, 3, 12, 13, 14, 21, 22, 23, 24, 25 };
|
||||
|
||||
//outBufferPinMask: pin mask for each output, which
|
||||
//means what pin is mapped to that OpenPLC output
|
||||
int outBufferPinMask[MAX_OUTPUT] = { 14, 15, 23, 24, 25, 8, 7, 12, 16, 20, 21 };
|
||||
int outBufferPinMask[MAX_OUTPUT] = { 15, 16, 4, 5, 6, 10, 11, 26, 27, 28, 29 };
|
||||
|
||||
//analogOutBufferPinMask: pin mask for the analog PWM
|
||||
//output of the RaspberryPi
|
||||
int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 18 };
|
||||
int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 1 };
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// This function is called by the main OpenPLC routine when it is initializing.
|
||||
@@ -66,30 +67,29 @@ int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 18 };
|
||||
//-----------------------------------------------------------------------------
|
||||
void initializeHardware()
|
||||
{
|
||||
gpioInitialise();
|
||||
wiringPiSetup();
|
||||
//piHiPri(99);
|
||||
|
||||
//set pins as input
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
gpioSetMode(inBufferPinMask[i], PI_INPUT);
|
||||
pinMode(inBufferPinMask[i], INPUT);
|
||||
if (i != 0 && i != 1) //pull down can't be enabled on the first two pins
|
||||
{
|
||||
gpioSetPullUpDown(inBufferPinMask[i], PI_PUD_DOWN); //pull down enabled
|
||||
pullUpDnControl(inBufferPinMask[i], PUD_DOWN); //pull down enabled
|
||||
}
|
||||
}
|
||||
|
||||
//set pins as output
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
gpioSetMode(outBufferPinMask[i], PI_OUTPUT);
|
||||
pinMode(outBufferPinMask[i], OUTPUT);
|
||||
}
|
||||
|
||||
//set PWM pins as output
|
||||
for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
{
|
||||
gpioSetMode(analogOutBufferPinMask[i], PI_ALT5);
|
||||
gpioSetPWMrange(analogOutBufferPinMask[i], 1024);
|
||||
pinMode(analogOutBufferPinMask[i], PWM_OUTPUT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,6 @@ void initializeHardware()
|
||||
//-----------------------------------------------------------------------------
|
||||
void finalizeHardware()
|
||||
{
|
||||
gpioTerminate();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -114,7 +113,7 @@ void updateBuffersIn()
|
||||
//INPUT
|
||||
for (int i = 0; i < MAX_INPUT; i++)
|
||||
{
|
||||
if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = gpioRead(inBufferPinMask[i]);
|
||||
if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = digitalRead(inBufferPinMask[i]);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
@@ -132,13 +131,13 @@ void updateBuffersOut()
|
||||
//OUTPUT
|
||||
for (int i = 0; i < MAX_OUTPUT; i++)
|
||||
{
|
||||
if (bool_output[i/8][i%8] != NULL) gpioWrite(outBufferPinMask[i], *bool_output[i/8][i%8]);
|
||||
if (bool_output[i/8][i%8] != NULL) digitalWrite(outBufferPinMask[i], *bool_output[i/8][i%8]);
|
||||
}
|
||||
|
||||
//ANALOG OUT (PWM)
|
||||
for (int i = 0; i < MAX_ANALOG_OUT; i++)
|
||||
{
|
||||
if (int_output[i] != NULL) gpioPWM(analogOutBufferPinMask[i], (*int_output[i] / 64));
|
||||
if (int_output[i] != NULL) pwmWrite(analogOutBufferPinMask[i], (*int_output[i] / 64));
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&bufferLock); //unlock mutex
|
||||
|
||||
@@ -143,9 +143,9 @@ elif [ "$OPENPLC_PLATFORM" = "rpi" ]; then
|
||||
./glue_generator
|
||||
echo "Compiling main program..."
|
||||
if [ "$OPENPLC_DRIVER" = "sequent" ]; then
|
||||
g++ -DSEQUENT -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lpigpio -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lsnap7 -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w
|
||||
else
|
||||
g++ -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lpigpio -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lsnap7 -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w
|
||||
g++ -DSEQUENT -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lwiringPi -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lsnap7 -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w
|
||||
else
|
||||
g++ -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lwiringPi -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lsnap7 -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w
|
||||
fi
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Error compiling C files"
|
||||
|
||||
Reference in New Issue
Block a user