Bdanilko / EdPy

A compiler for a subset of python2 to be used on the Microbric Edison robot
GNU General Public License v2.0
18 stars 12 forks source link

ReadMusicEnd() reports bad value #6

Open PSLLSP opened 5 years ago

PSLLSP commented 5 years ago

Function Ed.ReadMusicEnd() report wrong status and it can end with deadlock condition.

There are two constants defined related to ReadMusicEnd():

    "Ed.MUSIC_FINISHED":     0x01,
    "Ed.MUSIC_NOT_FINISHED": 0x00,

Function ReadMusicEnd() should first test if any music is played at all and if not, return 1 (MUSIC_FINISHED); or other value. Current implementation in that case returns 0 (MUSIC_NOT_FINISHED).

Demo, it ends in deadlock condition after first pass of the loop:

#-------------Setup----------------

import Ed

Ed.EdisonVersion = Ed.V2

Ed.DistanceUnits = Ed.CM
Ed.Tempo = Ed.TEMPO_MEDIUM

#--------Your code below-----------

led = False
Ed.PlayBeep()
while True:
    while Ed.ReadMusicEnd() == Ed.MUSIC_NOT_FINISHED: pass  # bug is here
    led = not led
    if led:
        Ed.LeftLed(Ed.ON)
        Ed.RightLed(Ed.OFF)
    else:
        Ed.LeftLed(Ed.OFF)
        Ed.RightLed(Ed.ON)
    Ed.TimeWait(50, Ed.TIME_MILLISECONDS)
PSLLSP commented 5 years ago

This is duplicate for #4