Commit 5d819748 authored by Claes Sjofors's avatar Claes Sjofors

Component for demo of Do IO added Misc_DoDemo

parent 173993cd
/* /*
* Proview $Id$ * Proview Open Source Process Control.
* Copyright (C) 2005 SSAB Oxelsund AB. * Copyright (C) 2005-2011 SSAB Oxelosund AB.
*
* This file is part of Proview.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
...@@ -13,8 +15,23 @@ ...@@ -13,8 +15,23 @@
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with the program, if not, write to the Free Software * along with Proview. If not, see <http://www.gnu.org/licenses/>
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
* Linking Proview statically or dynamically with other modules is
* making a combined work based on Proview. Thus, the terms and
* conditions of the GNU General Public License cover the whole
* combination.
*
* In addition, as a special exception, the copyright holders of
* Proview give you permission to, from the build function in the
* Proview Configurator, combine Proview with modules generated by the
* Proview PLC Editor to a PLC program, regardless of the license
* terms of these modules. You may copy and distribute the resulting
* combined work under the terms of your choice, provided that every
* copy of the combined work is accompanied by a complete copy of
* the source code of Proview (the version used to produce the
* combined work), being distributed under the terms of the GNU
* General Public License plus this exception.
*/ */
/* misc_plc.c Plc function object code. */ /* misc_plc.c Plc function object code. */
...@@ -344,3 +361,305 @@ void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o) ...@@ -344,3 +361,305 @@ void Misc_PingPongFo_exec( plc_sThread *tp, pwr_sClass_Misc_PingPongFo *o)
co->OldMode = co->Mode; co->OldMode = co->Mode;
} }
#define DEMOPATTERN_MAXSTATE 33
void Misc_DemoPattern_exec( plc_sThread *tp, pwr_sClass_Misc_DemoPattern *o)
{
int new_state;
if ( !*o->OnP) {
o->Mask1 = 0;
o->Mask2 = 0;
o->State = 0;
o->CycleCnt = 0;
o->StateCnt = 0;
}
else {
o->Cycle = o->CycleTime / tp->PlcThread->ScanTime / o->NumberOfOutputs;
if ( o->CycleCnt >= o->Cycle)
o->CycleCnt = 0;
else
o->CycleCnt++;
if ( o->CycleCnt != 1)
return;
if ( o->StateCnt >= o->NumberOfOutputs - 1)
o->StateCnt = 0;
o->StateCnt++;
if ( o->StateCnt == 1) {
if ( o->State >= DEMOPATTERN_MAXSTATE)
o->State = 0;
else
o->State++;
new_state = 1;
}
else
new_state = 0;
switch ( o->State) {
case 0:
if ( new_state) {
o->Mask1 = 1;
o->Mask2 = 0;
}
else
o->Mask1 = o->Mask1 << 1;
break;
case 1:
if ( new_state) {
o->Mask1 = 1 << 31;
o->Mask2 = 0;
}
else
o->Mask1 = o->Mask1 >> 1;
break;
case 2:
case 3:
if ( new_state) {
o->Mask1 = 1;
o->Mask2 = 1 << 31;
}
else {
o->Mask1 = o->Mask1 << 1;
o->Mask2 = o->Mask2 >> 1;
}
break;
case 4:
case 5:
if ( new_state) {
o->Mask1 = 1 || 1 << 16;
o->Mask2 = 1 << 31 || 1 << 16;
}
else {
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
o->Mask2 = (o->Mask2 << 31) | (o->Mask2 >> 1);
}
break;
case 6:
case 7:
if ( new_state) {
o->Mask1 = 1 | 1 << 16;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 8:
if ( new_state) {
o->Mask1 = 1 | 1 << 8 | 1 << 16 | 1 << 24;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 9:
if ( new_state) {
o->Mask1 = 1 | 1 << 4 | 1 << 8 | 1 << 12 | 1 << 16 | 1 << 20 | 1 << 24 | 1 << 28;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 10:
if ( new_state) {
o->Mask1 = 1 | 1 << 2 | 1 << 4 | 1 << 6 | 1 << 8 | 1 << 10 | 1 << 12 | 1 << 14 |
1 << 16 | 1 << 18 | 1 << 20 | 1 << 22 | 1 << 24 | 1 << 26 | 1 << 28 | 1 << 30;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 11:
if ( new_state) {
o->Mask1 = ~(1 | 1 << 4 | 1 << 8 | 1 << 12 | 1 << 16 | 1 << 20 | 1 << 24 | 1 << 28);
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 12:
if ( new_state) {
o->Mask1 = ~(1 | 1 << 8 | 1 << 16 | 1 << 24);
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 13:
if ( new_state) {
o->Mask1 = ~(1 | 1 << 16);
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 14:
if ( new_state) {
o->Mask1 = ~1;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 15:
if ( new_state) {
o->Mask1 = ~(1 << 31);
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 << 31) | (o->Mask1 >> 1);
break;
case 16:
if ( new_state) {
o->Mask1 = 1;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 17:
if ( new_state) {
o->Mask1 = 3;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 18:
if ( new_state) {
o->Mask1 = 7;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 19:
if ( new_state) {
o->Mask1 = 0xF;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 20:
if ( new_state) {
o->Mask1 = 0x3F;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 21:
if ( new_state) {
o->Mask1 = 0x7F;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 22:
if ( new_state) {
o->Mask1 = 0xFF;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 23:
if ( new_state) {
o->Mask1 = 0x3FF;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 24:
if ( new_state) {
o->Mask1 = 0x7FF;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 25:
if ( new_state) {
o->Mask1 = 0xFFF;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 26:
if ( new_state) {
o->Mask1 = 0x3FFF;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 27:
if ( new_state) {
o->Mask1 = 0x7FFF;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 28:
if ( new_state) {
o->Mask1 = 0xFFFF;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 29:
if ( new_state) {
o->Mask1 = 0xFFFFF;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 30:
if ( new_state) {
o->Mask1 = 0xFFFFFF;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 31:
if ( new_state) {
o->Mask1 = 0xFFFFFFF;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 32:
if ( new_state) {
o->Mask1 = 0x3FFFFFFF;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
case 33:
if ( new_state) {
o->Mask1 = ~1;
o->Mask2 = 0;
}
else
o->Mask1 = (o->Mask1 >> 31) | (o->Mask1 << 1);
break;
}
}
o->Out = (pwr_tInt32)(o->Mask1 | o->Mask2);
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment