Path: csiph.com!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'handler': 0.04; 'initialize': 0.05; 'needed,': 0.05; 'exit': 0.07; 'interpreted': 0.07; 'callback': 0.09; 'loop.': 0.09; 'message-id:@4ax.com': 0.09; 'plug': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'tends': 0.09; 'subject:Help': 0.10; 'python': 0.10; 'def': 0.13; 'variables': 0.15; '>that': 0.16; 'coupling': 0.16; 'existance': 0.16; 'framework,': 0.16; 'globals.': 0.16; 'in...': 0.16; 'integers.': 0.16; 'literal,': 0.16; 'loops': 0.16; 'mapped': 0.16; 'parts.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'scopes': 0.16; 'sees': 0.16; 'so)': 0.16; 'something.': 0.16; 'subprograms': 0.16; 'subroutine': 0.16; 'looked': 0.16; 'memory': 0.17; 'integer': 0.18; 'url:home': 0.18; 'gui': 0.18; 'variable': 0.18; 'language': 0.19; 'library': 0.20; 'changes': 0.20; '2015': 0.20; 'aug': 0.20; '(the': 0.22; 'saying': 0.22; 'arguments': 0.22; 'info.': 0.22; 'defined': 0.23; 'performing': 0.23; 'second': 0.24; 'import': 0.24; 'script': 0.25; 'example': 0.26; '(which': 0.26; 'header:X -Complaints-To:1': 0.26; 'checking': 0.27; 'fri,': 0.27; 'change,': 0.27; 'errors.': 0.27; 'function': 0.28; 'about.': 0.29; 'arguments,': 0.29; 'declared': 0.29; 'i/o': 0.29; 'loop,': 0.29; 'short,': 0.29; 'sleep': 0.29; 'url:wikipedia': 0.29; 'url:wiki': 0.30; 'code': 0.30; 'task': 0.30; 'probably': 0.31; 'another': 0.32; 'related': 0.32; 'addresses': 0.32; 'language.': 0.32; 'possibly': 0.32; 'maybe': 0.33; 'run': 0.33; 'point': 0.33; 'problem': 0.33; 'common': 0.33; 'accessible': 0.33; 'values.': 0.33; 'channel': 0.34; 'gets': 0.35; 'gives': 0.35; 'behind': 0.35; 'replace': 0.35; 'something': 0.35; 'level': 0.35; "isn't": 0.35; 'but': 0.36; 'should': 0.36; 'instead': 0.36; 'there': 0.36; 'url:org': 0.36; 'created': 0.36; '(and': 0.36; 'basic': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'being': 0.37; 'setting': 0.37; 'thanks': 0.37; 'received:org': 0.37; 'spread': 0.37; 'thought': 0.37; 'charset:us-ascii': 0.37; 'wanted': 0.37; 'doing': 0.38; 'mean': 0.38; 'shared': 0.38; 'why': 0.39; 'data': 0.39; 'url:en': 0.39; 'whatever': 0.39; 'to:addr:python.org': 0.40; 'called': 0.40; 'software': 0.40; 'term': 0.60; 'john': 0.61; 'real': 0.62; 'linked': 0.63; 'more': 0.63; 'times': 0.63; 'between': 0.65; 'url:%28': 0.66; 'url:%29': 0.66; 'url:%1': 0.67; 'online': 0.71; 'cohesion': 0.84; 'dozens': 0.84; 'functions)': 0.84; "they'd": 0.84; 'dennis': 0.91; 'download.': 0.91; 'interrupt': 0.91; 'received:108': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: RPI.GPIO Help Date: Sat, 29 Aug 2015 14:21:58 -0400 Organization: IISS Elusive Unicorn References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 108.68.178.61 X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 110 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1440872531 news.xs4all.nl 23730 [2001:888:2000:d::a6]:48122 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:95757 On Fri, 28 Aug 2015 17:40:24 GMT, John McKenzie declaimed the following: >>What is "channel"? > > Channel is something that is in every GPIO library example, and I pretty >sure it is literal, not a placeholder. If I replace it with channel >numbers it gives more errors. Channel is in place in working script >examples you can download. > I suspect it is likely the pin-# that was attached when setting up the callback linkage. The purpose being to allow one callback to be used for multiple connections. > >> timered is not declared "global", so will be considered local >to><> the > > Rereading global variables info. Never understood why all variables >aren't always global at all times in any language. Why would you not want >the variable accessible whenever you wanted it? Maybe it is related to >performance or something. Anyway, will look at the scopes of variables >again and look at the code again. > The only language the really had everything global was Kemeny&Kurtz BASIC -- from 1968. Even FORTRAN (1958 or so) did not have globals. Every subprogram (the meta term encompassing subroutines and functions -- though in Python they are all functions) had its local name space, arguments passed in... And -- possibly "common blocks" (which were declared memory addresses with variables mapped onto them -- and those variables did not have to match between subprograms subroutine A integer I integer j common /aBlock/ i, j ... subroutine B complex c common /aBlock/ c ... "aBlock" is a memory region. In "A", that memory region is defined as a pair of (32-bit) integers. In "B", that same memory region is now being looked at as a single complex number... And the bit-pattern of i and j are being interpreted as the floating point real and imaginary parts. There are software engineering concepts of "coupling" and "cohesion". In short, you want to minimize the coupling between parts of the program (between functions) by limiting shared data to passed in arguments, and passed out return values. By doing this, you can take that function -- with no code changes -- and plug it into another program and just use it. Cohesion tends to mean what is in the function is well linked to performing just the needs of that function -- it isn't spread all over the place. https://en.wikipedia.org/wiki/Coupling_%28computer_programming%29 > >> You initialize "colour" to 1, and then loop until "colour" is NOT >1 -- > > I thought the existance of the other callbacks would be able to interupt >it. Thanks for another point for me to look into and learn about. > Callbacks are not interrupts (and even if they were interrupts, they'd be at the same level -- and interrupts at the same level do not interrupt each other). Behind the scenes, the GPIO library probably created a task that just loops checking the registered I/O pins for state changes. When it sees a state change, it calls the callback function linked to it -- and waits for the callback to return to it so it can continue with its check loop. > >> You start an infinite loop, nothing below this point will be >executed > > The start of the infinite sleep loop is nessecary to have the script go >reiterate instead of run once in under a second and stop. Not saying this >has to be the way to do it, just explaining why I did it. What I used was >the example used in dozens and dozens of answers given online to solve >that same problem when using RPI.GPIO. > The infinite loop is needed, yes... But it needs to be performed after you've defined all the callbacks (and the exit handler IS a type of callback -- it gets called when an exit condition is activated). Program layout should be something like import whatever def all_functions(): register_callback(...) main_loop #in a gui framework, this may something like framework.mainloop() clean_up -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/