Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22f141e2cd | ||
|
|
f5d6e376c6 | ||
|
|
eeac10c66f | ||
|
|
e9d16a80d4 | ||
|
|
dcae074b55 | ||
|
|
472eba7977 |
@@ -1,170 +0,0 @@
|
|||||||
//
|
|
||||||
// Academic License - for use in teaching, academic research, and meeting
|
|
||||||
// course requirements at degree granting institutions only. Not for
|
|
||||||
// government, commercial, or other organizational use.
|
|
||||||
//
|
|
||||||
// File: FSMTreppe.cpp
|
|
||||||
//
|
|
||||||
// Code generated for Simulink model 'FSMTreppe'.
|
|
||||||
//
|
|
||||||
// Model version : 1.22
|
|
||||||
// Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
|
|
||||||
// C/C++ source code generated on : Fri Jul 2 17:45:36 2021
|
|
||||||
//
|
|
||||||
// Target selection: ert.tlc
|
|
||||||
// Embedded hardware selection: ARM Compatible->ARM Cortex-M
|
|
||||||
// Code generation objectives: Unspecified
|
|
||||||
// Validation result: Not run
|
|
||||||
//
|
|
||||||
#include "FSMTreppe.h"
|
|
||||||
|
|
||||||
// Named constants for Chart: '<Root>/FSMTreppe'
|
|
||||||
const uint8_t FSMTreppe_IN_animation_down = 1U;
|
|
||||||
const uint8_t FSMTreppe_IN_animation_up = 2U;
|
|
||||||
const uint8_t FSMTreppe_IN_idle = 3U;
|
|
||||||
|
|
||||||
// Model step function
|
|
||||||
void FSMTreppeModelClass::step()
|
|
||||||
{
|
|
||||||
// Chart: '<Root>/FSMTreppe' incorporates:
|
|
||||||
// Inport: '<Root>/anim_finished'
|
|
||||||
// Inport: '<Root>/sensor_oben'
|
|
||||||
// Inport: '<Root>/sensor_unten'
|
|
||||||
|
|
||||||
if (FSMTreppe_DW.temporalCounter_i1 < 511U) {
|
|
||||||
FSMTreppe_DW.temporalCounter_i1 = static_cast<uint16_t>
|
|
||||||
(FSMTreppe_DW.temporalCounter_i1 + 1U);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FSMTreppe_DW.is_active_c3_FSMTreppe == 0U) {
|
|
||||||
FSMTreppe_DW.is_active_c3_FSMTreppe = 1U;
|
|
||||||
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_idle;
|
|
||||||
|
|
||||||
// Outport: '<Root>/anim_active'
|
|
||||||
FSMTreppe_Y.anim_active = 0U;
|
|
||||||
FSMTreppe_DW.got_sensor = 0U;
|
|
||||||
FSMTreppe_DW.got_anim_finished = 0U;
|
|
||||||
FSMTreppe_DW.finished_up = 0U;
|
|
||||||
FSMTreppe_DW.finished_dn = 0U;
|
|
||||||
} else {
|
|
||||||
switch (FSMTreppe_DW.is_c3_FSMTreppe) {
|
|
||||||
case FSMTreppe_IN_animation_down:
|
|
||||||
// Outport: '<Root>/anim_active'
|
|
||||||
FSMTreppe_Y.anim_active = 2U;
|
|
||||||
if ((FSMTreppe_DW.finished_dn == 1) || (FSMTreppe_DW.temporalCounter_i1 >=
|
|
||||||
300U)) {
|
|
||||||
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_idle;
|
|
||||||
|
|
||||||
// Outport: '<Root>/anim_active'
|
|
||||||
FSMTreppe_Y.anim_active = 0U;
|
|
||||||
FSMTreppe_DW.got_sensor = 0U;
|
|
||||||
FSMTreppe_DW.got_anim_finished = 0U;
|
|
||||||
FSMTreppe_DW.finished_up = 0U;
|
|
||||||
FSMTreppe_DW.finished_dn = 0U;
|
|
||||||
} else {
|
|
||||||
if (FSMTreppe_U.sensor_unten) {
|
|
||||||
FSMTreppe_DW.got_sensor = 1U;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FSMTreppe_U.anim_finished) {
|
|
||||||
FSMTreppe_DW.got_anim_finished = 1U;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((FSMTreppe_DW.got_anim_finished == 1) && (FSMTreppe_DW.got_sensor ==
|
|
||||||
1)) {
|
|
||||||
FSMTreppe_DW.finished_dn = 1U;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FSMTreppe_IN_animation_up:
|
|
||||||
// Outport: '<Root>/anim_active'
|
|
||||||
FSMTreppe_Y.anim_active = 1U;
|
|
||||||
if ((FSMTreppe_DW.finished_up == 1) || (FSMTreppe_DW.temporalCounter_i1 >=
|
|
||||||
300U)) {
|
|
||||||
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_idle;
|
|
||||||
|
|
||||||
// Outport: '<Root>/anim_active'
|
|
||||||
FSMTreppe_Y.anim_active = 0U;
|
|
||||||
FSMTreppe_DW.got_sensor = 0U;
|
|
||||||
FSMTreppe_DW.got_anim_finished = 0U;
|
|
||||||
FSMTreppe_DW.finished_up = 0U;
|
|
||||||
FSMTreppe_DW.finished_dn = 0U;
|
|
||||||
} else {
|
|
||||||
if (FSMTreppe_U.sensor_oben) {
|
|
||||||
FSMTreppe_DW.got_sensor = 1U;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FSMTreppe_U.anim_finished) {
|
|
||||||
FSMTreppe_DW.got_anim_finished = 1U;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((FSMTreppe_DW.got_anim_finished == 1) && (FSMTreppe_DW.got_sensor ==
|
|
||||||
1)) {
|
|
||||||
FSMTreppe_DW.finished_up = 1U;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
// Outport: '<Root>/anim_active'
|
|
||||||
// case IN_idle:
|
|
||||||
FSMTreppe_Y.anim_active = 0U;
|
|
||||||
if (FSMTreppe_U.sensor_oben) {
|
|
||||||
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_animation_down;
|
|
||||||
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
|
||||||
|
|
||||||
// Outport: '<Root>/anim_active'
|
|
||||||
FSMTreppe_Y.anim_active = 2U;
|
|
||||||
FSMTreppe_DW.got_sensor = 0U;
|
|
||||||
FSMTreppe_DW.got_anim_finished = 0U;
|
|
||||||
FSMTreppe_DW.finished_dn = 0U;
|
|
||||||
} else if (FSMTreppe_U.sensor_unten) {
|
|
||||||
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_animation_up;
|
|
||||||
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
|
||||||
|
|
||||||
// Outport: '<Root>/anim_active'
|
|
||||||
FSMTreppe_Y.anim_active = 1U;
|
|
||||||
FSMTreppe_DW.got_sensor = 0U;
|
|
||||||
FSMTreppe_DW.got_anim_finished = 0U;
|
|
||||||
FSMTreppe_DW.finished_up = 0U;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// End of Chart: '<Root>/FSMTreppe'
|
|
||||||
}
|
|
||||||
|
|
||||||
// Model initialize function
|
|
||||||
void FSMTreppeModelClass::initialize()
|
|
||||||
{
|
|
||||||
// (no initialization code required)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Model terminate function
|
|
||||||
void FSMTreppeModelClass::terminate()
|
|
||||||
{
|
|
||||||
// (no terminate code required)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
FSMTreppeModelClass::FSMTreppeModelClass() :
|
|
||||||
FSMTreppe_DW(),
|
|
||||||
FSMTreppe_U(),
|
|
||||||
FSMTreppe_Y()
|
|
||||||
{
|
|
||||||
// Currently there is no constructor body generated.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
FSMTreppeModelClass::~FSMTreppeModelClass()
|
|
||||||
{
|
|
||||||
// Currently there is no destructor body generated.
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// File trailer for generated code.
|
|
||||||
//
|
|
||||||
// [EOF]
|
|
||||||
//
|
|
||||||
@@ -0,0 +1,237 @@
|
|||||||
|
//
|
||||||
|
// Academic License - for use in teaching, academic research, and meeting
|
||||||
|
// course requirements at degree granting institutions only. Not for
|
||||||
|
// government, commercial, or other organizational use.
|
||||||
|
//
|
||||||
|
// File: FSMTreppe.cpp
|
||||||
|
//
|
||||||
|
// Code generated for Simulink model 'FSMTreppe'.
|
||||||
|
//
|
||||||
|
// Model version : 1.29
|
||||||
|
// Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
|
||||||
|
// C/C++ source code generated on : Sat Jul 3 17:39:25 2021
|
||||||
|
//
|
||||||
|
// Target selection: ert.tlc
|
||||||
|
// Embedded hardware selection: ARM Compatible->ARM Cortex-M
|
||||||
|
// Code generation objectives: Unspecified
|
||||||
|
// Validation result: Not run
|
||||||
|
//
|
||||||
|
#include "FSMTreppe2.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
// Named constants for Chart: '<Root>/FSMTreppe'
|
||||||
|
const uint8_t FSMTreppe_IN_abdimmen_hoch = 1U;
|
||||||
|
const uint8_t FSMTreppe_IN_abdimmen_runter = 2U;
|
||||||
|
const uint8_t FSMTreppe_IN_aufdimmen_hoch = 3U;
|
||||||
|
const uint8_t FSMTreppe_IN_aufdimmen_runter = 4U;
|
||||||
|
const uint8_t FSMTreppe_IN_inaktiv = 5U;
|
||||||
|
const uint8_t FSMTreppe_IN_ruhezustand = 6U;
|
||||||
|
const uint8_t FSMTreppe_IN_warten_hoch = 7U;
|
||||||
|
const uint8_t FSMTreppe_IN_warten_runter = 8U;
|
||||||
|
|
||||||
|
// Model step function
|
||||||
|
void FSMTreppeModelClass::step()
|
||||||
|
{
|
||||||
|
// Chart: '<Root>/FSMTreppe' incorporates:
|
||||||
|
// Inport: '<Root>/anim_beendet'
|
||||||
|
// Inport: '<Root>/ldr_schwelle'
|
||||||
|
// Inport: '<Root>/sensor_oben'
|
||||||
|
// Inport: '<Root>/sensor_unten'
|
||||||
|
|
||||||
|
if (FSMTreppe_DW.temporalCounter_i1 < 511U) {
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = static_cast<uint16_t>
|
||||||
|
(FSMTreppe_DW.temporalCounter_i1 + 1U);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FSMTreppe_DW.is_active_c3_FSMTreppe == 0U) {
|
||||||
|
FSMTreppe_DW.is_active_c3_FSMTreppe = 1U;
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_inaktiv;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 0U;
|
||||||
|
} else {
|
||||||
|
switch (FSMTreppe_DW.is_c3_FSMTreppe) {
|
||||||
|
case FSMTreppe_IN_abdimmen_hoch:
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 4U;
|
||||||
|
if (FSMTreppe_U.anim_beendet || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
||||||
|
{
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_ruhezustand;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 1U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSMTreppe_IN_abdimmen_runter:
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 7U;
|
||||||
|
if (FSMTreppe_U.anim_beendet || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
||||||
|
{
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_ruhezustand;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 1U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSMTreppe_IN_aufdimmen_hoch:
|
||||||
|
// Outport: '<Root>/laufrichtung'
|
||||||
|
FSMTreppe_Y.laufrichtung = 1U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 1U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 2U;
|
||||||
|
if (FSMTreppe_U.anim_beendet || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
||||||
|
{
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_warten_hoch;
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 3U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSMTreppe_IN_aufdimmen_runter:
|
||||||
|
// Outport: '<Root>/laufrichtung'
|
||||||
|
FSMTreppe_Y.laufrichtung = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 1U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 5U;
|
||||||
|
if (FSMTreppe_U.anim_beendet || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
||||||
|
{
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_warten_runter;
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 6U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSMTreppe_IN_inaktiv:
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 0U;
|
||||||
|
if (FSMTreppe_U.ldr_schwelle == 1.0) {
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_ruhezustand;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 1U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSMTreppe_IN_ruhezustand:
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 1U;
|
||||||
|
if (FSMTreppe_U.sensor_unten) {
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_aufdimmen_hoch;
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/laufrichtung'
|
||||||
|
FSMTreppe_Y.laufrichtung = 1U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 1U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 2U;
|
||||||
|
} else if (FSMTreppe_U.sensor_oben) {
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_aufdimmen_runter;
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/laufrichtung'
|
||||||
|
FSMTreppe_Y.laufrichtung = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 1U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 5U;
|
||||||
|
} else if (FSMTreppe_U.ldr_schwelle == 0.0) {
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_inaktiv;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 0U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSMTreppe_IN_warten_hoch:
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 3U;
|
||||||
|
if (FSMTreppe_U.sensor_oben || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
||||||
|
{
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_abdimmen_hoch;
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 4U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
// case IN_warten_runter:
|
||||||
|
FSMTreppe_Y.status = 6U;
|
||||||
|
if (FSMTreppe_U.sensor_unten || (FSMTreppe_DW.temporalCounter_i1 >= 500U))
|
||||||
|
{
|
||||||
|
FSMTreppe_DW.is_c3_FSMTreppe = FSMTreppe_IN_abdimmen_runter;
|
||||||
|
FSMTreppe_DW.temporalCounter_i1 = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/dimmrichtung'
|
||||||
|
FSMTreppe_Y.dimmrichtung = 0U;
|
||||||
|
|
||||||
|
// Outport: '<Root>/status'
|
||||||
|
FSMTreppe_Y.status = 7U;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// End of Chart: '<Root>/FSMTreppe'
|
||||||
|
}
|
||||||
|
|
||||||
|
// Model initialize function
|
||||||
|
void FSMTreppeModelClass::initialize()
|
||||||
|
{
|
||||||
|
// (no initialization code required)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Model terminate function
|
||||||
|
void FSMTreppeModelClass::terminate()
|
||||||
|
{
|
||||||
|
// (no terminate code required)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
FSMTreppeModelClass::FSMTreppeModelClass() :
|
||||||
|
FSMTreppe_DW(),
|
||||||
|
FSMTreppe_U(),
|
||||||
|
FSMTreppe_Y()
|
||||||
|
{
|
||||||
|
// Currently there is no constructor body generated.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
FSMTreppeModelClass::~FSMTreppeModelClass()
|
||||||
|
{
|
||||||
|
// Currently there is no destructor body generated.
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// File trailer for generated code.
|
||||||
|
//
|
||||||
|
// [EOF]
|
||||||
|
//
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
//
|
//
|
||||||
// Code generated for Simulink model 'FSMTreppe'.
|
// Code generated for Simulink model 'FSMTreppe'.
|
||||||
//
|
//
|
||||||
// Model version : 1.22
|
// Model version : 1.28
|
||||||
// Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
|
// Simulink Coder version : 9.5 (R2021a) 14-Nov-2020
|
||||||
// C/C++ source code generated on : Fri Jul 2 17:45:36 2021
|
// C/C++ source code generated on : Sat Jul 3 13:50:17 2021
|
||||||
//
|
//
|
||||||
// Target selection: ert.tlc
|
// Target selection: ert.tlc
|
||||||
// Embedded hardware selection: ARM Compatible->ARM Cortex-M
|
// Embedded hardware selection: ARM Compatible->ARM Cortex-M
|
||||||
@@ -30,22 +30,21 @@ class FSMTreppeModelClass {
|
|||||||
uint16_t temporalCounter_i1; // '<Root>/FSMTreppe'
|
uint16_t temporalCounter_i1; // '<Root>/FSMTreppe'
|
||||||
uint8_t is_active_c3_FSMTreppe; // '<Root>/FSMTreppe'
|
uint8_t is_active_c3_FSMTreppe; // '<Root>/FSMTreppe'
|
||||||
uint8_t is_c3_FSMTreppe; // '<Root>/FSMTreppe'
|
uint8_t is_c3_FSMTreppe; // '<Root>/FSMTreppe'
|
||||||
uint8_t got_anim_finished; // '<Root>/FSMTreppe'
|
|
||||||
uint8_t finished_up; // '<Root>/FSMTreppe'
|
|
||||||
uint8_t finished_dn; // '<Root>/FSMTreppe'
|
|
||||||
uint8_t got_sensor; // '<Root>/FSMTreppe'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// External inputs (root inport signals with default storage)
|
// External inputs (root inport signals with default storage)
|
||||||
struct ExtU_FSMTreppe_T {
|
struct ExtU_FSMTreppe_T {
|
||||||
bool sensor_unten; // '<Root>/sensor_unten'
|
bool sensor_unten; // '<Root>/sensor_unten'
|
||||||
bool sensor_oben; // '<Root>/sensor_oben'
|
bool sensor_oben; // '<Root>/sensor_oben'
|
||||||
bool anim_finished; // '<Root>/anim_finished'
|
bool anim_beendet; // '<Root>/anim_beendet'
|
||||||
|
double ldr_schwelle; // '<Root>/ldr_schwelle'
|
||||||
};
|
};
|
||||||
|
|
||||||
// External outputs (root outports fed by signals with default storage)
|
// External outputs (root outports fed by signals with default storage)
|
||||||
struct ExtY_FSMTreppe_T {
|
struct ExtY_FSMTreppe_T {
|
||||||
uint8_t anim_active; // '<Root>/anim_active'
|
uint8_t laufrichtung; // '<Root>/laufrichtung'
|
||||||
|
uint8_t status; // '<Root>/status'
|
||||||
|
uint8_t dimmrichtung; // '<Root>/dimmrichtung'
|
||||||
};
|
};
|
||||||
|
|
||||||
// model initialize function
|
// model initialize function
|
||||||
+42
-38
@@ -132,10 +132,8 @@ void Treppe::rampe()
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Treppe::setup(){
|
void Treppe::setup(){
|
||||||
Serial.printf("differenz_pwm_pro_tick %f\n", differenz_pwm_pro_tick);
|
|
||||||
|
|
||||||
pwmController.resetDevices();
|
pwmController.resetDevices();
|
||||||
|
|
||||||
// Deactive PCA9685 Phase Balancer due to LED Flickering
|
// Deactive PCA9685 Phase Balancer due to LED Flickering
|
||||||
// https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
// https://github.com/NachtRaveVL/PCA9685-Arduino/issues/15
|
||||||
// see also lib/PCA9685-Arduin/PCA9685.h:204
|
// see also lib/PCA9685-Arduin/PCA9685.h:204
|
||||||
@@ -145,61 +143,67 @@ void Treppe::setup(){
|
|||||||
pwmController.setAllChannelsPWM(idle_brightness);
|
pwmController.setAllChannelsPWM(idle_brightness);
|
||||||
|
|
||||||
pinMode(A0, INPUT);
|
pinMode(A0, INPUT);
|
||||||
pinMode(SENSOR1, INPUT);
|
pinMode(SENSOR_OBEN, INPUT);
|
||||||
pinMode(SENSOR2, INPUT);
|
pinMode(SENSOR_UNTEN, INPUT);
|
||||||
pinMode(OE, OUTPUT);
|
pinMode(OE, OUTPUT);
|
||||||
digitalWrite(OE, 0);
|
digitalWrite(OE, 0);
|
||||||
|
|
||||||
|
Serial.printf("differenz_pwm_pro_tick %f\n", differenz_pwm_pro_tick);
|
||||||
Serial.println("Hello from Treppe");
|
Serial.println("Hello from Treppe");
|
||||||
Serial.print("Treppe: initial parameters: stairs=");
|
Serial.print("Treppe: initial parameters: stairs=");
|
||||||
Serial.println(stairs);
|
Serial.println(stairs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Treppe::print_state_on_change() {
|
||||||
|
static FSMTreppeModelClass::ExtU_FSMTreppe_T last_in;
|
||||||
|
static FSMTreppeModelClass::ExtY_FSMTreppe_T last_out;
|
||||||
|
if(
|
||||||
|
fsm_inputs.anim_beendet != last_in.anim_beendet ||
|
||||||
|
fsm_inputs.sensor_oben != last_in.sensor_oben ||
|
||||||
|
fsm_inputs.sensor_unten != last_in.sensor_unten ||
|
||||||
|
fsm_outputs.dimmrichtung != last_out.dimmrichtung ||
|
||||||
|
fsm_outputs.laufrichtung != last_out.laufrichtung ||
|
||||||
|
fsm_outputs.status != last_out.status
|
||||||
|
) {
|
||||||
|
last_in.anim_beendet = fsm_inputs.anim_beendet;
|
||||||
|
last_in.sensor_oben = fsm_inputs.sensor_oben;
|
||||||
|
last_in.sensor_unten = fsm_inputs.sensor_unten;
|
||||||
|
|
||||||
|
Serial.printf("FSM IN: s_u: %d, s_o: %d, beendet: %d =>",
|
||||||
|
fsm_inputs.sensor_oben, fsm_inputs.sensor_unten, fsm_inputs.anim_beendet);
|
||||||
|
Serial.print(" step => ");
|
||||||
|
Serial.printf("OUT: LR: %d DR: %d ST: %d\n",
|
||||||
|
fsm_outputs.laufrichtung, fsm_outputs.dimmrichtung, fsm_outputs.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Treppe::task(){
|
void Treppe::task(){
|
||||||
FSMTreppe_Obj.step();
|
//Serial.printf("LDR: %f\n", ((float)analogRead(A0))/1023.*3.68);
|
||||||
|
|
||||||
if(finish){
|
if(finish){
|
||||||
direction = switch_direction;
|
direction = switch_direction;
|
||||||
state = switch_state;
|
state = switch_state;
|
||||||
}
|
}
|
||||||
static uint8_t last_sensor_state[2] = {0,0};
|
|
||||||
uint8_t current_sensor_state[2] = {0,0};
|
|
||||||
current_sensor_state[0] = digitalRead(SENSOR1);
|
|
||||||
current_sensor_state[1] = digitalRead(SENSOR2);
|
|
||||||
|
|
||||||
if(current_sensor_state[0] && !last_sensor_state[0] && state == 0){
|
fsm_inputs.ldr_schwelle = true;
|
||||||
setTick(0);
|
fsm_inputs.sensor_oben = read_sensor(SENSOR_OBEN);
|
||||||
setAnAus(1);
|
fsm_inputs.sensor_unten = read_sensor(SENSOR_UNTEN);
|
||||||
setDirection(1);
|
fsm_inputs.anim_beendet = static_cast<bool>(finish);
|
||||||
setState(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(current_sensor_state[1] && !last_sensor_state[1] && state == 0){
|
FSMTreppe_Obj.setExternalInputs(&fsm_inputs);
|
||||||
setTick(0);
|
FSMTreppe_Obj.step();
|
||||||
setAnAus(0);
|
fsm_outputs = FSMTreppe_Obj.getExternalOutputs();
|
||||||
setDirection(0);
|
print_state_on_change();
|
||||||
setState(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// first switch - off approach, use timer later
|
direction = fsm_outputs.laufrichtung;
|
||||||
if(!current_sensor_state[0] && last_sensor_state[0] && state == 1){
|
state = fsm_outputs.dimmrichtung;
|
||||||
setTick(ticks_treppe);
|
|
||||||
setAnAus(1);
|
|
||||||
setDirection(1);
|
|
||||||
setState(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!current_sensor_state[1] && last_sensor_state[1] && state == 1){
|
// setTick(ticks_treppe);
|
||||||
setTick(ticks_treppe);
|
// setAnAus(1);
|
||||||
setAnAus(1);
|
// setDirection(0);
|
||||||
setDirection(0);
|
// setState(0);
|
||||||
setState(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
last_sensor_state[0] = current_sensor_state[0];
|
|
||||||
last_sensor_state[1] = current_sensor_state[1];
|
|
||||||
|
|
||||||
ledsequence();
|
ledsequence();
|
||||||
//Serial.printf("LDR: %f\n", ((float)analogRead(A0))/1023.*3.68);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+23
-9
@@ -1,30 +1,27 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "FSMTreppe/FSMTreppe.h"
|
#include "FSMTreppe/FSMTreppe2.h"
|
||||||
#include "PCA9685.h"
|
#include "PCA9685.h"
|
||||||
|
|
||||||
#define SENSOR1 2
|
#define SENSOR_OBEN 2
|
||||||
#define SENSOR2 12
|
#define SENSOR_UNTEN 12
|
||||||
#define OE 14
|
#define OE 14
|
||||||
|
|
||||||
#define INT_TIME 20 // interrupt intervall [ms]
|
#define INT_TIME 20 // interrupt intervall [ms]
|
||||||
|
|
||||||
class Treppe {
|
class Treppe {
|
||||||
private:
|
private:
|
||||||
// initialize with i2c-Address 0, use Wire Library
|
|
||||||
PCA9685 pwmController;
|
|
||||||
FSMTreppeModelClass FSMTreppe_Obj;// Instance of model class
|
|
||||||
|
|
||||||
uint8_t stairs;
|
uint8_t stairs;
|
||||||
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
|
uint16_t time_per_stair = 300; // dimmtime per stair [ms]
|
||||||
uint16_t idle_brightness = 100;
|
uint16_t idle_brightness = 100;
|
||||||
uint16_t active_brightness = 2048;
|
uint16_t active_brightness = 300;
|
||||||
|
|
||||||
uint8_t direction = 0;
|
uint8_t direction = 0;
|
||||||
uint8_t switch_direction = 0;
|
uint8_t switch_direction = 0;
|
||||||
uint8_t state = 0;
|
uint8_t state = 0;
|
||||||
uint8_t switch_state = 0;
|
uint8_t switch_state = 0;
|
||||||
uint8_t finish = 1;
|
bool finish = 1;
|
||||||
|
|
||||||
// alternative
|
// alternative
|
||||||
uint32_t tick = 0;
|
uint32_t tick = 0;
|
||||||
@@ -36,14 +33,31 @@ private:
|
|||||||
float differenz_pwm_pro_tick = 0.0;
|
float differenz_pwm_pro_tick = 0.0;
|
||||||
// alternative
|
// alternative
|
||||||
|
|
||||||
|
// initialize with i2c-Address 0, use Wire Library
|
||||||
|
PCA9685 pwmController;
|
||||||
|
FSMTreppeModelClass FSMTreppe_Obj;
|
||||||
|
FSMTreppeModelClass::ExtU_FSMTreppe_T fsm_inputs;
|
||||||
|
FSMTreppeModelClass::ExtY_FSMTreppe_T fsm_outputs;
|
||||||
|
void print_state_on_change();
|
||||||
|
|
||||||
|
const uint8_t FSMTreppe_IN_animation_down = 1U;
|
||||||
|
const uint8_t FSMTreppe_IN_animation_up = 2U;
|
||||||
|
const uint8_t FSMTreppe_IN_idle = 3U;
|
||||||
|
|
||||||
|
|
||||||
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
|
uint8_t softstart_led(uint8_t led, uint16_t startval, uint16_t stopval);
|
||||||
void ledsequence();
|
void ledsequence();
|
||||||
void rampe();
|
void rampe();
|
||||||
|
bool read_sensor(int sensor) {
|
||||||
|
int pegel = digitalRead(sensor);
|
||||||
|
return static_cast<bool>(pegel);
|
||||||
|
}
|
||||||
public:
|
public:
|
||||||
Treppe(uint8_t _stairs) : stairs(_stairs){
|
Treppe(uint8_t _stairs) : stairs(_stairs){
|
||||||
FSMTreppe_Obj.initialize();
|
FSMTreppe_Obj.initialize();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ticks_pro_stufe = time_per_stair / 20; // [ms]
|
ticks_pro_stufe = time_per_stair / 20; // [ms]
|
||||||
ticks_treppe = ticks_pro_stufe * stairs;
|
ticks_treppe = ticks_pro_stufe * stairs;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user