From b83ccf1f8839737af2c57a0f7a701f048b1bae12 Mon Sep 17 00:00:00 2001 From: Eduardo-bat Date: Mon, 26 Feb 2024 11:45:02 -0300 Subject: [PATCH] commit tracked files only --- background_installer.sh | 20 +++++++++++++- webserver/active_program | 2 +- .../core/hardware_layers/raspberrypi.cpp | 26 +++++++++--------- webserver/openplc.db | Bin 53248 -> 53248 bytes webserver/scripts/compile_program.sh | 4 +-- webserver/scripts/openplc_driver | 2 +- webserver/scripts/openplc_platform | 2 +- 7 files changed, 37 insertions(+), 19 deletions(-) diff --git a/background_installer.sh b/background_installer.sh index 8901a79..114c9a9 100755 --- a/background_installer.sh +++ b/background_installer.sh @@ -71,6 +71,24 @@ 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_py_deps { python3 -m venv "$VENV_DIR" "$VENV_DIR/bin/python3" -m pip install --upgrade pip @@ -282,7 +300,7 @@ elif [ "$1" == "docker" ]; then elif [ "$1" == "rpi" ]; then echo "Installing OpenPLC on Raspberry Pi" linux_install_deps sudo - install_wiringpi + install_pigpio install_py_deps install_all_libs sudo install_systemd_service sudo diff --git a/webserver/active_program b/webserver/active_program index 44b6177..5621f10 100755 --- a/webserver/active_program +++ b/webserver/active_program @@ -1 +1 @@ -blank_program.st +890590.st diff --git a/webserver/core/hardware_layers/raspberrypi.cpp b/webserver/core/hardware_layers/raspberrypi.cpp index 5636e35..bd81711 100755 --- a/webserver/core/hardware_layers/raspberrypi.cpp +++ b/webserver/core/hardware_layers/raspberrypi.cpp @@ -28,8 +28,7 @@ #include #include #include -#include -#include +#include #include #include "ladder.h" @@ -52,15 +51,15 @@ ****************************************************************/ //inBufferPinMask: pin mask for each input, which //means what pin is mapped to that OpenPLC input -int inBufferPinMask[MAX_INPUT] = { 8, 9, 7, 0, 2, 3, 12, 13, 14, 21, 22, 23, 24, 25 }; +int inBufferPinMask[MAX_INPUT] = { 2, 3, 4, 17, 27, 22, 10, 9, 11, 5, 6, 13, 19, 26 }; //outBufferPinMask: pin mask for each output, which //means what pin is mapped to that OpenPLC output -int outBufferPinMask[MAX_OUTPUT] = { 15, 16, 4, 5, 6, 10, 11, 26, 27, 28, 29 }; +int outBufferPinMask[MAX_OUTPUT] = { 14, 15, 23, 24, 25, 8, 7, 12, 16, 20, 21 }; //analogOutBufferPinMask: pin mask for the analog PWM //output of the RaspberryPi -int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 1 }; +int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 18 }; //----------------------------------------------------------------------------- // This function is called by the main OpenPLC routine when it is initializing. @@ -68,7 +67,7 @@ int analogOutBufferPinMask[MAX_ANALOG_OUT] = { 1 }; //----------------------------------------------------------------------------- void initializeHardware() { - wiringPiSetup(); + gpioInitialise(); //piHiPri(99); //set pins as input @@ -76,10 +75,10 @@ void initializeHardware() { if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), inBufferPinMask[i])) { - pinMode(inBufferPinMask[i], INPUT); + gpioSetMode(inBufferPinMask[i], PI_INPUT); if (i != 0 && i != 1) //pull down can't be enabled on the first two pins { - pullUpDnControl(inBufferPinMask[i], PUD_DOWN); //pull down enabled + gpioSetPullUpDown(inBufferPinMask[i], PI_PUD_DOWN); //pull down enabled } } } @@ -88,14 +87,14 @@ void initializeHardware() for (int i = 0; i < MAX_OUTPUT; i++) { if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), outBufferPinMask[i])) - pinMode(outBufferPinMask[i], OUTPUT); + gpioSetMode(outBufferPinMask[i], PI_OUTPUT); } //set PWM pins as output for (int i = 0; i < MAX_ANALOG_OUT; i++) { if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), analogOutBufferPinMask[i])) - pinMode(analogOutBufferPinMask[i], PWM_OUTPUT); + gpioSetMode(analogOutBufferPinMask[i], PI_ALT5); } } @@ -105,6 +104,7 @@ void initializeHardware() //----------------------------------------------------------------------------- void finalizeHardware() { + gpioTerminate(); } //----------------------------------------------------------------------------- @@ -120,7 +120,7 @@ void updateBuffersIn() for (int i = 0; i < MAX_INPUT; i++) { if (pinNotPresent(ignored_bool_inputs, ARRAY_SIZE(ignored_bool_inputs), inBufferPinMask[i])) - if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = digitalRead(inBufferPinMask[i]); + if (bool_input[i/8][i%8] != NULL) *bool_input[i/8][i%8] = gpioRead(inBufferPinMask[i]); } pthread_mutex_unlock(&bufferLock); //unlock mutex @@ -139,14 +139,14 @@ void updateBuffersOut() for (int i = 0; i < MAX_OUTPUT; i++) { if (pinNotPresent(ignored_bool_outputs, ARRAY_SIZE(ignored_bool_outputs), outBufferPinMask[i])) - if (bool_output[i/8][i%8] != NULL) digitalWrite(outBufferPinMask[i], *bool_output[i/8][i%8]); + if (bool_output[i/8][i%8] != NULL) gpioWrite(outBufferPinMask[i], *bool_output[i/8][i%8]); } //ANALOG OUT (PWM) for (int i = 0; i < MAX_ANALOG_OUT; i++) { if (pinNotPresent(ignored_int_outputs, ARRAY_SIZE(ignored_int_outputs), i)) - if (int_output[i] != NULL) pwmWrite(analogOutBufferPinMask[i], (*int_output[i] / 64)); + if (int_output[i] != NULL) gpioPWM(analogOutBufferPinMask[i], (*int_output[i] / 64)); } pthread_mutex_unlock(&bufferLock); //unlock mutex diff --git a/webserver/openplc.db b/webserver/openplc.db index a0cc5b383c5941c2638070908348a41ec08c55ed..e86bbe6d4c42f47b3c650555e0450da2f2c38509 100644 GIT binary patch delta 176 zcmZozz}&Ead4e?KuZc3wtiKrayeDob@}+00`wgI_^TfQ>)S`SKyC5eSN;yDjz2y8{D07p-7k&wTPG)9tMv(eqE?%HfjQmF!_>b@} g-^^n$gMVTG8>8$*N6F1c>`fHdq1rb8k7q0Z06b+dH~;_u diff --git a/webserver/scripts/compile_program.sh b/webserver/scripts/compile_program.sh index 42d2127..e1f8729 100755 --- a/webserver/scripts/compile_program.sh +++ b/webserver/scripts/compile_program.sh @@ -141,9 +141,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 -lwiringPi -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w + g++ -DSEQUENT -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lpigpio -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -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` -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w + g++ -std=gnu++11 *.cpp *.o -o openplc -I ./lib -lrt -lpigpio -lpthread -fpermissive `pkg-config --cflags --libs libmodbus` -lasiodnp3 -lasiopal -lopendnp3 -lopenpal -w fi if [ $? -ne 0 ]; then echo "Error compiling C files" diff --git a/webserver/scripts/openplc_driver b/webserver/scripts/openplc_driver index 055bd00..61aaae3 100755 --- a/webserver/scripts/openplc_driver +++ b/webserver/scripts/openplc_driver @@ -1 +1 @@ -blank_linux +rpi diff --git a/webserver/scripts/openplc_platform b/webserver/scripts/openplc_platform index a08e1f3..61aaae3 100755 --- a/webserver/scripts/openplc_platform +++ b/webserver/scripts/openplc_platform @@ -1 +1 @@ -linux +rpi