zeroflag / punyforth

Forth inspired programming language for the ESP8266
Other
406 stars 43 forks source link

Convert flash.py to python3 #57

Open sgall17a opened 3 years ago

sgall17a commented 3 years ago

I did a simple conversion to python3

  1. I ran 2to3 on flash.py. (this changes mostly print statements, I think)
  2. That left two remaining issues:

line 188. -- had to convert address into an int def write_flash_many(self, tupl): if not tupl: return print('Flashing %s' % ', '.join('0x%x: %s' % (int(address), os.path.basename(path)) for (address, path) in tupl))

line 190 -- same thing os.system("python esptool.py -p %s write_flash -fs 32m -fm %s -ff 40m %s" % (self.port, self.flashmode, ' '.join("0x%x %s" % (int(a),p) for a,p in tupl)))

flash.py seems to run OK now. Surprisingly I did not seem to have to change esptool.py A python3 version of esptool.py has been installed by pip, so it seems to use this one.

The changed file is attached.

(Sorry I am not used to this - I had to change to txt extension to get it to upload)

flash.py.txt

Also:- This is for esp8266. I am running a macbook on catalina.

sgall17a commented 3 years ago

Also problem with a strange x character in ping.forth comment which does not get decoded by utf-8. \ Distance = (high level time×velocity of sound (340M/S) I just replaced this character in a text editor

===========================

GPIO load

: emit-pulse ( trigger-pin -- )
    dup GPIO_OUT gpio-mode
    dup GPIO_LOW gpio-write
    2 us
    dup GPIO_HIGH gpio-write
    10 us
    GPIO_LOW gpio-write ;

: listen-echo ( echo-pin timeout-us -- ms )
    over GPIO_IN gpio-mode    
    GPIO_HIGH rot pulse-len ;

\ Measures the pulse generated by ultrasonic ranging module (tested with: HC-SR04 sensors)
\ Works the following way:
\ (1) Using IO trigger for at least 10us high level signal,
\ (2) The Module automatically sends eight 40 kHz and detect whether there is a pulse signal back.
\ (3) IF the signal back, time of high output IO duration is the time from sending ultrasonic to returning.
\ Distance = (high level time x velocity of sound (340M/S) / 2, 
\ Usage example: PIN_ECHO 100 cm>timeout PIN_TRIGGER ping pulse>cm
: ping ( echo-pin timeout-us trigger-pin -- pulse-duration-us )
    os-enter-critical
    { emit-pulse listen-echo } catch
    os-exit-critical
    throw ;

: cm>timeout ( cm -- us ) 60 * ;
: inch>timeout ( inch -- us ) 150 * ;
: pulse>cm ( us -- cm ) 58 / ;
: pulse>inch ( us -- inch ) 148 / ;

/end