calliope-edu / CalliopEO_AstroPi

MIT License
1 stars 2 forks source link

Reference program implementation in readme #10

Closed Amerlander closed 3 years ago

Amerlander commented 3 years ago

Reference https://makecode.calliope.cc/_JaXhHVDH3V8e as a basic program.

rzbrk commented 3 years ago

Good! You mean, the basic program will serve as a "boiler plate" or as a starting point when using the Calliope Mini together with Astro Pi and the CalliopEO.py script, correct? If so, this boiler plate can also be included in the SW description document that has to be delivered to ESA.

Amerlander commented 3 years ago

Yes, the scripts we get from the students will not incliude this and we have to wrap this arround before compiling and sending it to the pi. We should also add the js version to this repo to be able to track changes in there.

function checkEndTime () {
    if (control.millis() >= startTime + runMaxSeconds * 1000) {
        runProgram = false
        serial.writeLine("@END@")
    }
}
serial.onDataReceived(serial.delimiters(Delimiters.NewLine), function () {
    SERIAL_RECEIVED = serial.readUntil(serial.delimiters(Delimiters.NewLine))
    if ("@START@" == SERIAL_RECEIVED.substr(0, 7) && !(runProgram)) {
        serial.writeLine("@START@")
        runProgram = true
        startTime = control.millis()
    }
})
let SERIAL_RECEIVED = ""
let startTime = 0
let runProgram = false
let runMaxSeconds = 0
runMaxSeconds = 60
runProgram = false
basic.forever(function () {
    if (runProgram) {
        // Students program goes here
    }
})
Amerlander commented 3 years ago

I think we should reference the test files when your fork is merged. That way we have the hex file as well as the .js (its not .java), multiple examples and the readme keeps clean from code citations.

rzbrk commented 3 years ago

In the mean time you already provided the test files in - thank you! Could you also add the corresponding .js files?

Honestly, I am more in favor to have a dedicated git repo for the boiler plate/reference program.

Also, later for the student code I would suggest to create dedicated respositories.

rzbrk commented 3 years ago

I slightly modified the reference program. The check if the maximum execution time is over is performed in a separate "basic.forever" function. The student code in the main "basic.forever" function is encapsulated in a while function.

serial.onDataReceived(serial.delimiters(Delimiters.NewLine), function () {
    SERIAL_RECEIVED = serial.readUntil(serial.delimiters(Delimiters.NewLine))
    if ("@START@" == SERIAL_RECEIVED.substr(0, 7) && !(runProgram)) {
        serial.writeLine("@START@")
        runProgram = true
        startTime = control.millis()
    }
})
let startTime = 0
let SERIAL_RECEIVED = ""
let runProgram = false
// runMaxSeconds is the maximum time in seconds the program is allowed to run.
let runMaxSeconds = 60
runProgram = false
basic.forever(function () {
    if (control.millis() >= startTime + runMaxSeconds * 1000) {
        runProgram = false
        serial.writeLine("@END@")
    }
})
basic.forever(function () {
    // Student code goes here.
    while (runProgram) {

    }
})

See repository: https://github.com/rzbrk/CalliopeMini-Boilerplate

Amerlander commented 3 years ago

I provided a Hex file as basic program Implementation: