SHOW:
|
|
- or go back to the newest paste.
| 1 | - | component = require("component") |
| 1 | + | component = require("component")
|
| 2 | - | detector = component.ir_augment_detector |
| 2 | + | detector = component.ir_augment_detector |
| 3 | - | control = component.ir_augment_control |
| 3 | + | control = component.ir_augment_control |
| 4 | - | event = require("event") |
| 4 | + | event = require("event")
|
| 5 | - | os = require("os") |
| 5 | + | os = require("os")
|
| 6 | - | internet = component.internet |
| 6 | + | internet = component.internet |
| 7 | - | |
| 7 | + | |
| 8 | - | stationName = "grassland" |
| 8 | + | stationName = "grassland" |
| 9 | - | |
| 9 | + | |
| 10 | - | url = "http://localhost:8011" |
| 10 | + | url = "http://localhost:8011" |
| 11 | - | local readhash = "abe6db4c9f5484fae8d79f2e868a673c" |
| 11 | + | local readhash = "abe6db4c9f5484fae8d79f2e868a673c" |
| 12 | - | local updatehash = "abe6db4c9f5484fae8d79f2e868a673c" |
| 12 | + | |
| 13 | - | |
| 13 | + | while true do |
| 14 | - | while true do |
| 14 | + | event.pull("ir_train_overhead")
|
| 15 | - | event.pull("ir_train_overhead") |
| 15 | + | control.setThrottle(0) |
| 16 | - | control.setThrottle(0) |
| 16 | + | control.setBrake(1) |
| 17 | - | control.setBrake(1) |
| 17 | + | tag = detector.getTag() |
| 18 | - | detector.setTag("") |
| 18 | + | |
| 19 | - | tag = detector.getTag() |
| 19 | + | if tag == nil or tag == "" then |
| 20 | - | |
| 20 | + | print("Unregistered train!")
|
| 21 | - | if tag == nil or tag == "" then |
| 21 | + | local registerAnswer |
| 22 | - | print("Unregistered train!") |
| 22 | + | repeat |
| 23 | - | local registerAnswer |
| 23 | + | io.write("Register Train (y/n)? ")
|
| 24 | - | repeat |
| 24 | + | io.flush() |
| 25 | - | io.write("Register Train (y/n)? ") |
| 25 | + | registerAnswer=io.read() |
| 26 | - | io.flush() |
| 26 | + | until registerAnswer=="y" or registerAnswer=="n" |
| 27 | - | registerAnswer=io.read() |
| 27 | + | |
| 28 | - | until registerAnswer=="y" or registerAnswer=="n" |
| 28 | + | if answer == y then |
| 29 | - | |
| 29 | + | |
| 30 | - | local newTag |
| 30 | + | local newTag |
| 31 | - | io.write("Write your train tag!") |
| 31 | + | io.write("Write your train tag!")
|
| 32 | - | io.flush() |
| 32 | + | io.flush() |
| 33 | - | newTag = io.read() |
| 33 | + | newTag = io.read() |
| 34 | - | |
| 34 | + | detector.setTag(newTag) |
| 35 | - | local addHash = "abe6db4c9f5484fae8d79f2e868a673c" |
| 35 | + | |
| 36 | - | if answer == y then |
| 36 | + | local addHash = "abe6db4c9f5484fae8d79f2e868a673c" |
| 37 | - | local handle = internet.request(url .. "/addTrain?tag=" .. newTag .. "&passHash=" .. addHash .. "&station=" .. stationName) |
| 37 | + | local handle = internet.request(url .. "/addTrain?tag=" .. newTag .. "&passHash=" .. addHash .. "&station=" .. stationName) |
| 38 | - | print(handle.finishConnect()) |
| 38 | + | print(handle.finishConnect()) |
| 39 | - | end |
| 39 | + | end |
| 40 | - | else |
| 40 | + | else |
| 41 | - | print(tag) |
| 41 | + | local updatehash = "abe6db4c9f5484fae8d79f2e868a673c" |
| 42 | - | end |
| 42 | + | local handle = internet.request(url .. "/updateTrainByName?tag=" .. tag .. "&passHash=" .. updateHash .. "&station=" .. stationName) |
| 43 | - | |
| 43 | + | print(handle.finishConnect()) |
| 44 | - | os.sleep(1) |
| 44 | + | print(tag) |
| 45 | end | |
| 46 | ||
| 47 | os.sleep(1) | |
| 48 | end |