Adding support for initialize all LPC module variables even if not used
authorlaurent
Fri, 04 Jun 2010 09:02:22 +0200
changeset 550 b03f586547c9
parent 549 5dd92bd6e6e5
child 551 d18e86b603bc
Adding support for initialize all LPC module variables even if not used
Beremiz.py
LPCBeremiz.py
--- a/Beremiz.py	Thu Jun 03 17:26:47 2010 +0200
+++ b/Beremiz.py	Fri Jun 04 09:02:22 2010 +0200
@@ -1066,7 +1066,7 @@
             rightwindow.SetBackgroundColour(wx.WHITE)
             
             leftwindowsizer.Add(wx.Size(20, 16), 0)
-            
+        
         sb = wx.StaticBitmap(leftwindow, -1)
         icon = location.get("icon")
         if icon is None:
@@ -1082,7 +1082,9 @@
             infos = location.copy()
             infos.pop("children")
             st.SetFont(wx.Font(faces["size"] * 0.5, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]))
-            st.Bind(wx.EVT_LEFT_DOWN, self.GenerateLocationLeftDownFunction(infos))
+            leftcallback = self.GenerateLocationLeftDownFunction(infos)
+            st.Bind(wx.EVT_LEFT_DOWN, leftcallback)
+            sb.Bind(wx.EVT_LEFT_DOWN, leftcallback)
         elif location["type"] == LOCATION_GROUP:
             st.SetFont(wx.Font(faces["size"] * 0.6, wx.DEFAULT, wx.NORMAL, wx.NORMAL, faceName = faces["helv"]))
         else:
--- a/LPCBeremiz.py	Thu Jun 03 17:26:47 2010 +0200
+++ b/LPCBeremiz.py	Fri Jun 04 09:02:22 2010 +0200
@@ -97,6 +97,15 @@
             children.append(child)
     return children
 
+def _GetVariables(module):
+    variables = []
+    for child in module["children"]:
+        if child["type"] in [LOCATION_GROUP, LOCATION_MODULE]:
+            variables.extend(_GetVariables(child))
+        else:
+            variables.append(child)
+    return variables
+
 def _GetLastModuleGroup(module):
     group = module
     for child in module["children"]:
@@ -136,14 +145,13 @@
   #include "iec_std_lib.h"
 #endif
 
-%(declare_code)s
-
 /* LPCBus plugin user variables definition */
 %(var_decl)s
 
 /* LPCBus plugin functions */
 int __init_%(location_str)s(int argc,char **argv)
 {
+%(declare_code)s
   return 0;
 }
 
@@ -153,12 +161,12 @@
 
 void __retrieve_%(location_str)s(void)
 {
-  %(retrieve_code)s
+%(retrieve_code)s
 }
         
 void __publish_%(location_str)s(void)
 {
-  %(publish_code)s
+%(publish_code)s
 }
 """
 
@@ -285,6 +293,10 @@
                     "publish_code": "",
                    }
         
+        for variable in _GetVariables(self):
+            if variable["declare"] != "":
+                code_str["declare_code"] += "  %s\n" % variable["declare"]
+        
         # Adding variables
         vars = []
         self.ResetUsedLocations()
@@ -310,7 +322,6 @@
                         self.AddUsedLocation(location["LOC"])
                     vars.append({"location": location["NAME"],
                                  "Type": variable["IEC_type"],
-                                 "Declare": variable["declare"],
                                  "Retrieve": variable["retrieve"],
                                  "Publish": variable["publish"],
                                 })
@@ -322,12 +333,10 @@
                 prefix = "IEC_"
             code_str["var_decl"] += "%s%s beremiz%s;\n"%(prefix, var["Type"], var["location"])
             code_str["var_decl"] += "%s%s *%s = &beremiz%s;\n"%(prefix, var["Type"], var["location"], var["location"])
-            if var["Declare"] != "":
-                code_str["declare_code"] += var["Declare"] + "\n"
             if var["Retrieve"] != "":
-                code_str["retrieve_code"] += var["Retrieve"] % ("*" + var["location"]) + "\n"
+                code_str["retrieve_code"] += "  " + var["Retrieve"] % ("*" + var["location"]) + "\n"
             if var["Publish"] != "":
-                code_str["publish_code"] += var["Publish"] % ("*" + var["location"]) + "\n"
+                code_str["publish_code"] += "  " + var["Publish"] % ("*" + var["location"]) + "\n"
         
         Gen_Module_path = os.path.join(buildpath, "Module_%s.c"%location_str)
         module = open(Gen_Module_path,'w')