Skip to content

Commit 488b89f

Browse files
authored
Move HTTP code in helper.py to a separate file (#271)
* Move HTTP code in helper.py to a separate file
1 parent 2f2bc7a commit 488b89f

File tree

8 files changed

+653
-645
lines changed

8 files changed

+653
-645
lines changed

demo/EV3D4/EV3D4.py

Lines changed: 0 additions & 35 deletions
This file was deleted.

demo/EV3D4/EV3D4RemoteControl

Lines changed: 0 additions & 13 deletions
This file was deleted.

demo/EV3D4/EV3D4RemoteControl.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
3+
import logging
4+
import sys
5+
from ev3dev.auto import OUTPUT_A, OUTPUT_B, OUTPUT_C
6+
from ev3dev.helper import RemoteControlledTank, MediumMotor
7+
8+
class EV3D4RemoteControlled(RemoteControlledTank):
9+
10+
def __init__(self, medium_motor=OUTPUT_A, left_motor=OUTPUT_C, right_motor=OUTPUT_B):
11+
RemoteControlledTank.__init__(self, left_motor, right_motor)
12+
self.medium_motor = MediumMotor(medium_motor)
13+
14+
if not self.medium_motor.connected:
15+
log.error("%s is not connected" % self.medium_motor)
16+
sys.exit(1)
17+
18+
self.medium_motor.reset()
19+
20+
21+
logging.basicConfig(level=logging.INFO,
22+
format='%(asctime)s %(levelname)5s: %(message)s')
23+
log = logging.getLogger(__name__)
24+
25+
log.info("Starting EV3D4")
26+
ev3d4 = EV3D4RemoteControlled()
27+
ev3d4.main()
28+
log.info("Exiting EV3D4")

demo/EV3D4/EV3D4WebControl

Lines changed: 0 additions & 13 deletions
This file was deleted.

demo/EV3D4/EV3D4WebControl.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env python3
2+
3+
import logging
4+
import sys
5+
from ev3dev.auto import OUTPUT_A, OUTPUT_B, OUTPUT_C
6+
from ev3dev.helper import MediumMotor
7+
from ev3dev.webserver import WebControlledTank
8+
9+
class EV3D4WebControlled(WebControlledTank):
10+
11+
def __init__(self, medium_motor=OUTPUT_A, left_motor=OUTPUT_C, right_motor=OUTPUT_B):
12+
WebControlledTank.__init__(self, left_motor, right_motor)
13+
self.medium_motor = MediumMotor(medium_motor)
14+
15+
if not self.medium_motor.connected:
16+
log.error("%s is not connected" % self.medium_motor)
17+
sys.exit(1)
18+
19+
self.medium_motor.reset()
20+
21+
22+
logging.basicConfig(level=logging.INFO,
23+
format='%(asctime)s %(levelname)5s: %(message)s')
24+
log = logging.getLogger(__name__)
25+
26+
log.info("Starting EV3D4")
27+
ev3d4 = EV3D4WebControlled()
28+
ev3d4.main() # start the web server
29+
log.info("Exiting EV3D4")

demo/EV3D4/README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
# EV3D4
22
EV3D4 is designed to look like R2-D2 from Star Wars. There are two options for
33
controlling EV3D4. The first is to use the IR remote to send commands to the IR
4-
sensor, run EV3D4RemoteControl to use this method. The second means of
5-
controlling EV3D4 is via a web browser, run EV3D4WebControl to use this method.
4+
sensor, run EV3D4RemoteControl.py to use this method. The second means of
5+
controlling EV3D4 is via a web browser, run EV3D4WebControl.py to use this method.
6+
You can run both of these from the Brickman interface or if logged in via ssh
7+
you can run them via ./EV3D4RemoteControl.py or ./EV3D4WebControl.py.
68

79
**Building instructions**: https://www.lego.com/en-us/mindstorms/build-a-robot/ev3d4
810

911
### EV3D4RemoteControl
10-
If you are using EV3D4RemoteControl the only other file you need from
11-
`demo/EV3D4/` is EV3D4.py. The other files are only needed by EV3D4WebControl.
12-
13-
EV3D4RemoteControl creates a child class of ev3dev/helper.py's
12+
EV3D4RemoteControl.py creates a child class of ev3dev/helper.py's
1413
RemoteControlledTank.
1514

1615

1716
### EV3D4WebControl
18-
EV3D4WebControl creates a child class of ev3dev/helper.py's WebControlledTank.
17+
EV3D4WebControl creates a child class of ev3dev/webserver.py's WebControlledTank.
1918
The WebControlledTank class runs a web server that serves the web pages,
2019
images, etc but it also services the AJAX calls made via the client. The user
2120
loads the initial web page at which point they choose the "Desktop interface"

0 commit comments

Comments
 (0)