Skip to content

Commit

Permalink
Merge pull request #6 from viordash/ElementsStorage
Browse files Browse the repository at this point in the history
Elements storage
  • Loading branch information
viordash authored Sep 8, 2024
2 parents 6bb8e1d + a2d1622 commit 485164d
Show file tree
Hide file tree
Showing 112 changed files with 3,512 additions and 1,663 deletions.
7 changes: 6 additions & 1 deletion PLC_esp8266/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@
"variant": "cpp",
"logicprogram.h": "c",
"controller_engine.h": "c",
"process_engine.h": "c"
"process_engine.h": "c",
"portable.h": "c",
"portmacro.h": "c",
"xtensa_rtos.h": "c",
"xtensa_timer.h": "c",
"freertosconfig.h": "c"
}
}
2 changes: 1 addition & 1 deletion PLC_esp8266/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SHELL := env PATH=$(PATH) /bin/bash

project_prepare:
@tar -xzf $(PWD)/../SDK/xtensa-lx106-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz -C $(PWD)/../SDK/
@mkdir $(PWD)/main/MigrateAnyData
@mkdir -p $(PWD)/main/MigrateAnyData
@ln -sf $(PWD)/../SDK/MigrateAnyCppData/MigrateAnyData/MigrateAnyData.cpp $(PWD)/main/MigrateAnyData/MigrateAnyData.cpp
@ln -sf $(PWD)/../SDK/MigrateAnyCppData/MigrateAnyData/MigrateAnyData.h $(PWD)/main/MigrateAnyData/MigrateAnyData.h

Expand Down
13 changes: 0 additions & 13 deletions PLC_esp8266/main/Display/DisplayChainItem.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions PLC_esp8266/main/Display/DisplayChainItem.h

This file was deleted.

12 changes: 0 additions & 12 deletions PLC_esp8266/main/Display/DisplayItemBase.cpp

This file was deleted.

15 changes: 0 additions & 15 deletions PLC_esp8266/main/Display/DisplayItemBase.h

This file was deleted.

5 changes: 1 addition & 4 deletions PLC_esp8266/main/Display/LabeledLogicItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
#include <stdlib.h>
#include <string.h>

LabeledLogicItem::LabeledLogicItem(const char *label) {
void LabeledLogicItem::SetLabel(const char *label) {
this->label = label;
this->width = 6 * strlen(label);
this->height = 12;
}

LabeledLogicItem::~LabeledLogicItem() {
}
4 changes: 2 additions & 2 deletions PLC_esp8266/main/Display/LabeledLogicItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class LabeledLogicItem {
uint8_t width;
uint8_t height;

void SetLabel(const char *label);

public:
explicit LabeledLogicItem(const char *label);
virtual ~LabeledLogicItem();
};
26 changes: 11 additions & 15 deletions PLC_esp8266/main/Display/MapIOIndicator.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#include "Display/MapIOIndicator.h"
#include "Display/Common.h"
#include "Display/display.h"
#include "LogicProgram/MapIO.h"
#include "esp_err.h"
#include "esp_log.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

MapIOIndicator::MapIOIndicator(const Point &incoming_point,
const char *name,
uint8_t progress,
uint8_t separator_width)
: DisplayItemBase() {
this->incoming_point = incoming_point;
MapIOIndicator::MapIOIndicator(const char *name, uint8_t progress, uint8_t separator_width) {
this->name = name;
this->progress = progress;
this->separator_width = separator_width;
Expand All @@ -21,21 +16,22 @@ MapIOIndicator::MapIOIndicator(const Point &incoming_point,
MapIOIndicator::~MapIOIndicator() {
}

bool MapIOIndicator::Render(uint8_t *fb) {
bool MapIOIndicator::Render(uint8_t *fb, Point *start_point) {
bool res;
res = draw_horz_progress_bar(fb, incoming_point.x + margin, incoming_point.y, progress);

start_point->x += margin;

res = draw_horz_progress_bar(fb, start_point->x, start_point->y, progress);

res &= draw_text_f5X7(fb,
incoming_point.x + margin,
incoming_point.y + margin + HORZ_PROGRESS_BAR_HEIGHT,
start_point->x + margin,
start_point->y + margin + HORZ_PROGRESS_BAR_HEIGHT,
name);

start_point->x += (text_width * name_size) + margin + margin + separator_width;
return res;
}

uint8_t MapIOIndicator::GetWidth() {
return margin + (text_width * name_size) + margin + margin;
}

uint8_t MapIOIndicator::GetHeight() {
return HORZ_PROGRESS_BAR_HEIGHT + text_height;
}
12 changes: 3 additions & 9 deletions PLC_esp8266/main/Display/MapIOIndicator.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
#pragma once

#include "Display/Common.h"
#include "Display/DisplayItemBase.h"
#include <stdint.h>
#include <unistd.h>

class MapIOIndicator : public DisplayItemBase {
class MapIOIndicator {
protected:
Point incoming_point;
const char *name;
uint8_t progress;
uint8_t separator_width;
Expand All @@ -18,13 +16,9 @@ class MapIOIndicator : public DisplayItemBase {
static const uint8_t margin = 1;

public:
explicit MapIOIndicator(const Point &incoming_point,
const char *name,
uint8_t progress,
uint8_t separator_width);
explicit MapIOIndicator(const char *name, uint8_t progress, uint8_t separator_width);
virtual ~MapIOIndicator();

bool Render(uint8_t *fb) override final;
static uint8_t GetWidth();
bool Render(uint8_t *fb, Point *start_point);
static uint8_t GetHeight();
};
4 changes: 2 additions & 2 deletions PLC_esp8266/main/Display/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extern "C" {
#define SCL_PIN GPIO_NUM_4
#define SDA_PIN GPIO_NUM_5

static const char *TAG = "display";
static const char *TAG_display = "display";

static struct {
ssd1306_t dev = { .i2c_port = I2C_NUM_0,
Expand Down Expand Up @@ -75,7 +75,7 @@ void display_init() {

// ESP_ERROR_CHECK(ssd1306_load_frame_buffer(&display.dev, display.buffer) != 0 ? ESP_FAIL
// : ESP_OK);
ESP_LOGI(TAG, "init succesfully");
ESP_LOGI(TAG_display, "init succesfully");
}

void ladder_diagram(int8_t x, int8_t y) {
Expand Down
80 changes: 28 additions & 52 deletions PLC_esp8266/main/LogicProgram/Controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "LogicProgram/Controller.h"

#include "Display/Common.h"
#include "Display/display.h"
#include "LogicProgram/Ladder.h"
#include "LogicProgram/LogicProgram.h"
#include "LogicProgram/StatusBar.h"
#include "esp_event.h"
Expand All @@ -14,80 +16,54 @@

static const char *TAG_Controller = "controller";

uint8_t Controller::Var1 = StatefulElement::MinValue;
uint8_t Controller::Var2 = StatefulElement::MinValue;
uint8_t Controller::Var3 = StatefulElement::MinValue;
uint8_t Controller::Var4 = StatefulElement::MinValue;
bool Controller::runned = false;
EventGroupHandle_t Controller::gpio_events = NULL;

Controller::Controller(EventGroupHandle_t gpio_events) {
runned = false;
this->gpio_events = gpio_events;
}

Controller::~Controller() {
Stop();
}
uint8_t Controller::Var1 = LogicElement::MinValue;
uint8_t Controller::Var2 = LogicElement::MinValue;
uint8_t Controller::Var3 = LogicElement::MinValue;
uint8_t Controller::Var4 = LogicElement::MinValue;

void Controller::Start() {
runned = true;
ESP_ERROR_CHECK(xTaskCreate(ProcessTask, "controller_task", 4096, this, 3, NULL) != pdPASS
void Controller::Start(EventGroupHandle_t gpio_events) {
Controller::gpio_events = gpio_events;
Controller::runned = true;
ESP_ERROR_CHECK(xTaskCreate(ProcessTask, "controller_task", 4096, NULL, 3, NULL) != pdPASS
? ESP_FAIL
: ESP_OK);
}

void Controller::Stop() {
runned = false;
Controller::runned = false;
}

void Controller::ProcessTask(void *parm) {
(void)parm;
ESP_LOGI(TAG_Controller, "start ++++++");
Controller *controller = (Controller *)parm;
StatusBar statusBar(controller, 0);

IncomeRail incomeRail0(controller, 0, LogicItemState::lisActive);

InputNO input00(MapIO::DI, &incomeRail0);
InputNC input01(MapIO::V1, &input00);
TimerMSecs timer00(500, &input01);
SetOutput output00(MapIO::V1, &timer00);
OutcomeRail outcomeRail0(&output00, 0);

IncomeRail incomeRail1(controller, 1, LogicItemState::lisActive);
InputNO input10(MapIO::DI, &incomeRail1);
InputNO input11(MapIO::V1, &input10);
TimerMSecs timer10(500, &input11);
ResetOutput output10(MapIO::V1, &timer10);
OutcomeRail outcomeRail1(&output10, 1);
StatusBar statusBar(0);
Ladder ladder;
ladder.Load();

bool need_render = true;
while (controller->runned) {
while (Controller::runned) {
const int read_adc_max_period_ms = 100;
EventBits_t uxBits = xEventGroupWaitBits(controller->gpio_events,
EventBits_t uxBits = xEventGroupWaitBits(Controller::gpio_events,
INPUT_1_IO_CLOSE | INPUT_1_IO_OPEN,
true,
false,
read_adc_max_period_ms / portTICK_PERIOD_MS);

need_render |= (uxBits & (INPUT_1_IO_CLOSE | INPUT_1_IO_OPEN));

need_render |= incomeRail0.DoAction();
need_render |= incomeRail1.DoAction();

// need_render |= timer00.ProgressHasChanges();
// need_render |= timer10.ProgressHasChanges();
need_render |= ladder.DoAction();

if (need_render) {
ESP_LOGI(TAG_Controller, ".");

uint8_t *fb = begin_render();

statusBar.Render(fb);

incomeRail0.Render(fb);
outcomeRail0.Render(fb);

incomeRail1.Render(fb);
outcomeRail1.Render(fb);
ladder.Render(fb);

end_render(fb);
need_render = false;
Expand All @@ -107,18 +83,18 @@ uint8_t Controller::GetAIRelativeValue() {

uint8_t Controller::GetDIRelativeValue() {
bool val_1bit = get_digital_input_value();
uint8_t percent04 = val_1bit ? StatefulElement::MaxValue : StatefulElement::MinValue;
uint8_t percent04 = val_1bit ? LogicElement::MaxValue : LogicElement::MinValue;
return percent04;
}

uint8_t Controller::GetO1RelativeValue() {
uint8_t percent04 = get_digital_value(gpio_output::OUTPUT_0) ? StatefulElement::MaxValue
: StatefulElement::MinValue;
uint8_t percent04 =
get_digital_value(gpio_output::OUTPUT_0) ? LogicElement::MaxValue : LogicElement::MinValue;
return percent04;
}
uint8_t Controller::GetO2RelativeValue() {
uint8_t percent04 = get_digital_value(gpio_output::OUTPUT_1) ? StatefulElement::MaxValue
: StatefulElement::MinValue;
uint8_t percent04 =
get_digital_value(gpio_output::OUTPUT_1) ? LogicElement::MaxValue : LogicElement::MinValue;
return percent04;
}
uint8_t Controller::GetV1RelativeValue() {
Expand All @@ -135,10 +111,10 @@ uint8_t Controller::GetV4RelativeValue() {
}

void Controller::SetO1RelativeValue(uint8_t value) {
set_digital_value(gpio_output::OUTPUT_0, value != StatefulElement::MinValue);
set_digital_value(gpio_output::OUTPUT_0, value != LogicElement::MinValue);
}
void Controller::SetO2RelativeValue(uint8_t value) {
set_digital_value(gpio_output::OUTPUT_1, value != StatefulElement::MinValue);
set_digital_value(gpio_output::OUTPUT_1, value != LogicElement::MinValue);
}
void Controller::SetV1RelativeValue(uint8_t value) {
Controller::Var1 = value;
Expand Down
11 changes: 4 additions & 7 deletions PLC_esp8266/main/LogicProgram/Controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@ extern "C" {

class Controller {
private:
bool runned;
EventGroupHandle_t gpio_events;
static bool runned;
static EventGroupHandle_t gpio_events;
static uint8_t Var1;
static uint8_t Var2;
static uint8_t Var3;
static uint8_t Var4;

public:
explicit Controller(EventGroupHandle_t gpio_events);
~Controller();

void Start();
void Stop();
static void Start(EventGroupHandle_t gpio_events);
static void Stop();

static void ProcessTask(void *parm);

Expand Down
Loading

0 comments on commit 485164d

Please sign in to comment.