Skip to content

Commit

Permalink
Type Bool added, needed for Arduino Uno
Browse files Browse the repository at this point in the history
  • Loading branch information
JdeH committed Aug 21, 2017
1 parent f3c87d2 commit 5ced8ff
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 68 deletions.
9 changes: 5 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ What's new:

- Comments in code of SimPyLC/scene.py adapted to clarify different purpose of axis and pivot, and of passing angle to __init__ versus passing it to __call__
- Spaces rather than tabs are now used in the sourcecode.
- Adapted for Python 3.5 (SimPyLC 2.1.2 is last version running with Python 2.7)
- Adapted for Python 3.6 (SimPyLC 2.1.2 is last version running with Python 2.7)
- Development status bumped to production / stable.
- Native.py files replaced by native.cpp files, which are plain C++, hence benefit from syntax highlighting. You'll have to adapt your existing code to this (by merely leaving things out).
- Code now generated in a separate subdirectory to avoid confusion, especially with native.cpp.
Expand All @@ -41,21 +41,22 @@ REMARK: All complete Arduino examples were tested on the Arduino Due, since that

Bugs fixed:

- __nonzero__ changed to __bool__, as required by the move from Python 2.7 to Python 3.5. The blinkingLight demo will now work again.
- Type Bool added, needed for Arduino Uno.
- __nonzero__ changed to __bool__, as required by the move from Python 2.7 to Python 3.6. The blinkingLight demo will now work again.
- Sidewalks raised above road in arduinoTrafficLights example.
- Unused circuit group 'Lights' deleted from control in arduinoTrafficLights example.

**Bug reports and feature requests are most welcome and will be taken under serious consideration on a non-committal basis**

Requirements for Windows:

1. Install WinPython 3.5, e.g. from https://winpython.github.io
1. Install WinPython 3.6, e.g. from https://winpython.github.io
2. (Optional) Copy SimPyLC\\SimPyLC\\QuartzMS.TTF to C:\\Windows\\Fonts
3. (Optional) You can may also add SimPyLC\\SimPyLC to your PYTHONPATH

Requirements for Linux:

1. Install Python 3.5 and PyOpenGL
1. Install Python 3.6 and PyOpenGL

Usage:

Expand Down
2 changes: 1 addition & 1 deletion SimPyLC/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import os

programName = 'SimPyLC'
programVersion = '3.5.5'
programVersion = '3.6.1'
programNameAndVersion = '{0} {1}'.format (programName, programVersion)
programDir = os.getcwd () .replace ('\\', '/') .rsplit ('/', 3) [-1]

Expand Down
1 change: 1 addition & 0 deletions SimPyLC/coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def getPrologue (self):
#define {0}False 0
#define {0}True 1
#define {0}Bool bool
#define {0}UInt unsigned long
#define {0}Int long
#define {0}Float double
Expand Down
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ def read (*paths):

setup (
name = 'SimPyLC',
version = '3.5.5',
version = '3.6.1',
description = 'SimPyLC PLC simulator, after its C++ big brother that has controlled industrial installations for more than 20 years now. ARDUINO CODE GENERATION ADDED!',
long_description = (
read ('README.rst') + '\n\n' +
read ('qQuickLicence.txt')
read ('qQuickLicense.txt')
),
keywords = ['PLC', 'Arduino','simulator', 'SimPyLC', 'emulator', 'GEATEC', 'opy', 'eden'],
url = 'http://www.qquick.org/educational',
Expand All @@ -30,6 +30,7 @@ def read (*paths):
'Topic :: Software Development :: Libraries :: Python Modules',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3.5'
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6'
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@



// ====== BEGIN OF LICENCE COMMENT BLOCK, INCLUDE IN ANY COPY OF THIS GENERATED CODE AND DO NOT REMOVE ======
// ====== BEGIN OF License COMMENT BLOCK, INCLUDE IN ANY COPY OF THIS GENERATED CODE AND DO NOT REMOVE ======
//
// I M P O R T A N T S A F E T Y N O T I C E
//
Expand All @@ -12,12 +12,12 @@
// USE OF THIS CODE IS GOVERNED BY THE QQUICK LICENSE (WWW.QQUICK.ORG/LICENSE).
// YOUR LICENSE TO USE THIS GENERATED CODE AUTOMATICALLY ENDS IF YOU REMOVE OR LEAVE OUT THIS LICENSE COMMENT BLOCK OR THE CODE THAT GENERATED IT.
//
// ====== END OF LICENCE COMMENT BLOCK, INCLUDE IN COPY OF THIS GENERATED CODE AND DO NOT REMOVE ======
// ====== END OF License COMMENT BLOCK, INCLUDE IN COPY OF THIS GENERATED CODE AND DO NOT REMOVE ======



// Generator: SimPyLC 2.1.2
// Generated: 2016-12-09 19:38:24.144225
// Generator: SimPyLC 3.6.0
// Generated: 2017-08-21 18:50:37.930289
// Target platform: Arduino


Expand Down Expand Up @@ -66,14 +66,15 @@
// Support operations

#define update()\
thenExact = nowExact; nowExact = getNowExact(); period = 1e-6 * (nowExact - thenExact);\
nowInexact = getNowInexact();\
first = False;
thenExact = nowExact; nowExact = getNowExact(); period = 1e-6 * (nowExact - thenExact);\
nowInexact = getNowInexact();\
first = False;

// Types

#define False 0
#define True 1
#define Bool bool
#define UInt unsigned long
#define Int long
#define Float double
Expand All @@ -88,7 +89,7 @@
#define abs1(value) fabs (value)
#define max2(value0, value1) fmax (value0, value1)
#define min2(value0, value1) fmin (value0, value1)
#define limit3(value, aLimit0, aLimit1) min (max (value, aLimit0), aLimit1)
#define limit3(value, aLimit0, aLimit1) min (max (value, aLimit0), aLimit1)
#define limit2(value, aLimit) limit3 (value, -aLimit, aLimit)
#define digit2(value, index) getDigit (int (value), index)

Expand Down Expand Up @@ -134,9 +135,9 @@ void cycle () {
reset2 (blinkTimer, (elapsed1 (blinkTimer) > blinkTime));
mark2 (led, (elapsed1 (blinkTimer) < 0.2));

// ______ System ______
// ______ System ______

update ();
update ();
}


Expand Down Expand Up @@ -169,11 +170,11 @@ Removing this header ends your licence.
*/

void setup () {
pinMode (13, OUTPUT);
pinMode (13, OUTPUT);
}

void loop () {
cycle ();
digitalWrite (13, led);
}
cycle ();
digitalWrite (13, led);
}

85 changes: 43 additions & 42 deletions simulations/arduinoStove/generated/arduinoStove/arduinoStove.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@



// ====== BEGIN OF LICENCE COMMENT BLOCK, INCLUDE IN ANY COPY OF THIS GENERATED CODE AND DO NOT REMOVE ======
// ====== BEGIN OF License COMMENT BLOCK, INCLUDE IN ANY COPY OF THIS GENERATED CODE AND DO NOT REMOVE ======
//
// I M P O R T A N T S A F E T Y N O T I C E
// I M P O R T A N T S A F E T Y N O T I C E
//
// THIS CODE IS INTENDED SOLELY FOR EDUCATIONAL PURPOSES AND IS FUNDAMENTALLY UNSUITABLE FOR CONTROLLING REAL SYSTEMS.
// IT IS STRICKTLY PROHIBITED TO USE THIS GENERATED CODE IN ANY SITUATION THAT ENTAILS RISK OF DAMAGE OR INJURIES.
//
// USE OF THIS CODE IS GOVERNED BY THE QQUICK LICENSE (WWW.QQUICK.ORG/LICENSE).
// YOUR LICENSE TO USE THIS GENERATED CODE AUTOMATICALLY ENDS IF YOU REMOVE OR LEAVE OUT THIS LICENSE COMMENT BLOCK OR THE CODE THAT GENERATED IT.
//
// ====== END OF LICENCE COMMENT BLOCK, INCLUDE IN COPY OF THIS GENERATED CODE AND DO NOT REMOVE ======
// ====== END OF License COMMENT BLOCK, INCLUDE IN COPY OF THIS GENERATED CODE AND DO NOT REMOVE ======



// Generator: SimPyLC 3.5.0
// Generated: 2017-01-23 12:26:00.389172
// Generator: SimPyLC 3.6.0
// Generated: 2017-08-21 18:45:36.728265
// Target platform: Arduino


Expand Down Expand Up @@ -66,14 +66,15 @@
// Support operations

#define update()\
thenExact = nowExact; nowExact = getNowExact(); period = 1e-6 * (nowExact - thenExact);\
nowInexact = getNowInexact();\
first = False;
thenExact = nowExact; nowExact = getNowExact(); period = 1e-6 * (nowExact - thenExact);\
nowInexact = getNowInexact();\
first = False;

// Types

#define False 0
#define True 1
#define Bool bool
#define UInt unsigned long
#define Int long
#define Float double
Expand All @@ -88,14 +89,14 @@
#define abs1(value) fabs (value)
#define max2(value0, value1) fmax (value0, value1)
#define min2(value0, value1) fmin (value0, value1)
#define limit3(value, aLimit0, aLimit1) min (max (value, aLimit0), aLimit1)
#define limit3(value, aLimit0, aLimit1) min (max (value, aLimit0), aLimit1)
#define limit2(value, aLimit) limit3 (value, -aLimit, aLimit)
#define digit2(value, index) getDigit (int (value), index)

// ____________ General functions ____________

int getDigit (int value, int index) {
return (index == 0) ? value % 10 : getDigit (value / 10, --index);
return (index == 0) ? value % 10 : getDigit (value / 10, --index);
}

// ____________ General variables ____________
Expand Down Expand Up @@ -285,9 +286,9 @@ void cycle () {
set3 (sweepMin, 1000, (!elapsed1 (sweepWatch)));
set3 (sweepMax, 0, (!elapsed1 (sweepWatch)));

// ______ System ______
// ______ System ______

update ();
update ();
}


Expand All @@ -297,7 +298,7 @@ void cycle () {


// Pins configured for Arduino Due, adapt for Uno
int dataPin = 22, clockPin = 24, latchPin = 26;
int powerPin = 28, childLockPin = 30, plateSelectPin = 32;
int upPin = 34, downPin = 36, alarmSelectPin = 38;
Expand All @@ -309,44 +310,44 @@ int gain = 255 / 9;
int dark = 0, g = 1, f = 2, e = 4, d = 8, c = 16, b = 32, a = 64, dot = 128;

int segments [] = {
a + b + c + d + e + f,
b + c,
a + b + g + e + d,
a + b + g + c + d,
f + g + b + c,
a + f + g + c + d,
a + f + e + d + c + g,
a + b + c,
a + b + c + d + e + f + g,
g + f + a + b + c + d
a + b + c + d + e + f,
b + c,
a + b + g + e + d,
a + b + g + c + d,
f + g + b + c,
a + f + g + c + d,
a + f + e + d + c + g,
a + b + c,
a + b + c + d + e + f + g,
g + f + a + b + c + d
};

void setup () {
pinMode (dataPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(latchPin, OUTPUT);
pinMode (powerPin, INPUT); pinMode (childLockPin, INPUT); pinMode (plateSelectPin, INPUT);
pinMode (upPin, INPUT); pinMode (downPin, INPUT); pinMode (alarmSelectPin, INPUT);
pinMode (plate0Pin, OUTPUT); pinMode (plate1Pin, OUTPUT); pinMode (plate2Pin, OUTPUT); pinMode (plate3Pin, OUTPUT);
pinMode (buzzerPin, OUTPUT);
pinMode (dataPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(latchPin, OUTPUT);
pinMode (powerPin, INPUT); pinMode (childLockPin, INPUT); pinMode (plateSelectPin, INPUT);
pinMode (upPin, INPUT); pinMode (downPin, INPUT); pinMode (alarmSelectPin, INPUT);
pinMode (plate0Pin, OUTPUT); pinMode (plate1Pin, OUTPUT); pinMode (plate2Pin, OUTPUT); pinMode (plate3Pin, OUTPUT);
pinMode (buzzerPin, OUTPUT);
}

void readInputs () {
powerButton = digitalRead (powerPin); childLockButton = digitalRead (childLockPin); plateSelectButton = digitalRead (plateSelectPin);
upButton = digitalRead (upPin); downButton = digitalRead (downPin); alarmSelectButton = digitalRead (alarmSelectPin);
powerButton = digitalRead (powerPin); childLockButton = digitalRead (childLockPin); plateSelectButton = digitalRead (plateSelectPin);
upButton = digitalRead (upPin); downButton = digitalRead (downPin); alarmSelectButton = digitalRead (alarmSelectPin);
}

void writeOutputs () {
analogWrite (plate0Pin, gain * plate0Temp); analogWrite (plate1Pin, gain * plate1Temp);
analogWrite (plate2Pin, gain * plate2Temp); analogWrite (plate3Pin, gain * plate3Temp);
digitalWrite (buzzerPin, buzzer);
digitalWrite (latchPin, 0);
shiftOut (dataPin, clockPin, LSBFIRST, 1 << int (3 - digitIndex));
shiftOut (dataPin, clockPin, LSBFIRST, ~(power ? (segments [int (digitValue)] + (digitDot ? dot : dark)) : dark)); // Active low
digitalWrite (latchPin, 1);
void writeOutputs () {
analogWrite (plate0Pin, gain * plate0Temp); analogWrite (plate1Pin, gain * plate1Temp);
analogWrite (plate2Pin, gain * plate2Temp); analogWrite (plate3Pin, gain * plate3Temp);
digitalWrite (buzzerPin, buzzer);
digitalWrite (latchPin, 0);
shiftOut (dataPin, clockPin, LSBFIRST, 1 << int (3 - digitIndex));
shiftOut (dataPin, clockPin, LSBFIRST, ~(power ? (segments [int (digitValue)] + (digitDot ? dot : dark)) : dark)); // Active low
digitalWrite (latchPin, 1);
}

void loop () {
readInputs ();
cycle ();
writeOutputs ();
readInputs ();
cycle ();
writeOutputs ();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@



// ====== BEGIN OF LICENCE COMMENT BLOCK, INCLUDE IN ANY COPY OF THIS GENERATED CODE AND DO NOT REMOVE ======
// ====== BEGIN OF License COMMENT BLOCK, INCLUDE IN ANY COPY OF THIS GENERATED CODE AND DO NOT REMOVE ======
//
// I M P O R T A N T S A F E T Y N O T I C E
//
Expand All @@ -12,12 +12,12 @@
// USE OF THIS CODE IS GOVERNED BY THE QQUICK LICENSE (WWW.QQUICK.ORG/LICENSE).
// YOUR LICENSE TO USE THIS GENERATED CODE AUTOMATICALLY ENDS IF YOU REMOVE OR LEAVE OUT THIS LICENSE COMMENT BLOCK OR THE CODE THAT GENERATED IT.
//
// ====== END OF LICENCE COMMENT BLOCK, INCLUDE IN COPY OF THIS GENERATED CODE AND DO NOT REMOVE ======
// ====== END OF License COMMENT BLOCK, INCLUDE IN COPY OF THIS GENERATED CODE AND DO NOT REMOVE ======



// Generator: SimPyLC 3.5.5
// Generated: 2017-02-10 22:15:41.179688
// Generator: SimPyLC 3.6.0
// Generated: 2017-08-21 18:46:41.937185
// Target platform: Arduino


Expand Down Expand Up @@ -74,6 +74,7 @@

#define False 0
#define True 1
#define Bool bool
#define UInt unsigned long
#define Int long
#define Float double
Expand Down

0 comments on commit 5ced8ff

Please sign in to comment.