Skip to content

Commit b05d32a

Browse files
author
Charles Weir
committed
cw: Documentation
1 parent 48c40c9 commit b05d32a

File tree

6 files changed

+54
-18
lines changed

6 files changed

+54
-18
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# CommandLineApplication class. Provides a dummy scheduler for BrickPiWrapper.
2+
# Applications using the BrickPi derive from this, implementing appropriate functionality.
3+
4+
5+
import Tkinter as tk
6+
7+
from BrickPiWrapper import *
8+
import logging
9+
10+
class CommandLineApplication(BrickPiWrapper):
11+
'''
12+
Main application class for command-line only apps. Doesn't support user input.
13+
'''
14+
15+
def __init__(self, sensorConfiguration={}):
16+
'''Initialization: *sensorConfiguration* is a map, e.g. {PORT_1: TYPE_SENSOR_ULTRASONIC_CONT }
17+
as passed to BrickPiWrapper'''
18+
BrickPiWrapper.__init__(self, sensorConfiguration )
19+
20+
def mainloop(self):
21+
'The main loop for the application - call this after initialization. Never returns.'
22+
while True:
23+
self.doWork()
24+
time.sleep(self.timeMillisToNextCall() / 1000.0)
25+

BrickPython/TkApplication.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,4 @@ def onKeyPress(self, event):
5858
return False
5959
return True
6060

61+

ExamplePrograms/SimpleApp.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22

33

44
import sortOutPythonPaths
5-
from BrickPython.TkApplication import *
5+
from BrickPython.CommandLineApplication import *
66

7-
class SimpleApp(TkApplication):
7+
class SimpleApp(CommandLineApplication):
88
def __init__(self):
9-
TkApplication.__init__(self)
9+
CommandLineApplication.__init__(self)
1010
self.addSensorCoroutine( self.doActivity() )
1111

1212
def doActivity(self):
1313
'Coroutine to rotate a motor forward and backward'
1414
motorA = self.motor('A')
1515
motorA.zeroPosition()
1616
while True:
17+
print 'a'
1718
for i in motorA.moveTo( 2*90 ):
1819
yield
19-
20+
print 'b'
2021
for i in motorA.moveTo( 0 ):
2122
yield
2223

docs/BrickPython.rst

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,32 @@ BrickPython API
33

44
This describes the BrickPython API in detail.
55

6-
:mod:`Scheduler` Module
7-
-----------------------
6+
:mod:`Scheduler`
7+
----------------
88
.. automodule:: Scheduler
99

1010

11-
:mod:`BrickPiWrapper` Module
12-
----------------------------
11+
:mod:`BrickPiWrapper`
12+
---------------------
1313
.. automodule:: BrickPiWrapper
1414

1515

16-
:mod:`TkApplication` Module
17-
----------------------------
16+
:mod:`TkApplication`
17+
--------------------
1818
.. automodule:: TkApplication
1919

2020

21-
:mod:`Motor` Module
22-
----------------------------
21+
:mod:`CommandLineApplication`
22+
-----------------------------
23+
.. automodule:: CommandLineApplication
24+
25+
26+
:mod:`Motor`
27+
------------
2328
.. automodule:: Motor
2429

2530

26-
:mod:`Sensor` Module
27-
----------------------------
31+
:mod:`Sensor`
32+
-------------
2833
.. automodule:: Sensor
2934

docs/introduction.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ Other Integrations
118118
Integrations with other frameworks, or non at all, are equally straightforward. The framework must call the
119119
method Scheduler.doWork regularly, pausing for Scheduler.timeMillisToNextCall() after each call.
120120

121+
For example `CommandLineApplication` provides a scheduler for applications that don't require user input.
122+
121123
Motors and Sensors
122124
==================
123125

docs/programmingWithCoroutines.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ A simple example
88

99
Here's a simple application, from ``ExamplePrograms/SimpleApp.py``::
1010

11-
from BrickPython.TkApplication import *
11+
from BrickPython.CommandLineApplication import *
1212

13-
class SimpleApp(TkApplication):
13+
class SimpleApp(CommandLineApplication):
1414
def __init__(self):
15-
TkApplication.__init__(self)
16-
self.addSensorCoroutine( self.doActivity() ) #A
15+
CommandLineApplication.__init__(self)
16+
self.addSensorCoroutine( self.doActivity() ) #A
1717

1818
def doActivity(self):
1919
'Coroutine to rotate a motor forward and backward'
@@ -29,6 +29,8 @@ Here's a simple application, from ``ExamplePrograms/SimpleApp.py``::
2929
if __name__ == "__main__":
3030
SimpleApp().mainloop()
3131

32+
It uses the simplest scheduler - the CommandLineApplication.
33+
3234
Line A creates a coroutine from the coroutine method doActivity() and adds it to the scheduler. A coroutine must have
3335
one or more `yield` calls, such as the one at line D, and the scheduler can then call it using 'next()'
3436
- see, for example https://wiki.python.org/moin/Generators

0 commit comments

Comments
 (0)