Episode: 2951 Title: HPR2951: A walk through my PifaceCAD Python code – Part 2 Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr2951/hpr2951.mp3 Transcribed: 2025-10-24 13:47:25 --- This is HBR Episode 2951 for Monday the 25th of November 2019. Today's show is entitled a walk through my Pyface CAD Python Code Part 2, and as part of the series a little bit of Python, it's hosted by MrX, is about 15 minutes long and carries an explicit flag. The summary is, in this episode I cover some generic functions at the top of the code. This episode of HBR is brought to you by archive.org. Support universal access to all knowledge by heading over to archive.org forward slash donate. Hello and welcome hacker public audience. My name is MrX and welcome to this podcast. I'd like to start as usual by thanking the people at HBR for making this series available to all it's actually invaluable service. HBR is a community led podcast provided by the community for the community. That means you can contribute to why you record something and send a turn I'm sure would often interest in. Okay so this is part two of my run through my Python code for the Pyface CAD and display. I don't board what you have from a Raspberry Pi. In this episode I covered some of the generic functions at the top of the code basically. I forgot to mention last time that I'll include a copy of my Python code CAD-menu.py. That's how it was called. I think it was. I'll include a copy of that script on each of the episodes. I recorded this the actual main part on a one or and listening back to it I noticed that I started off a nice paste nice gentle piece and gradually it gets faster and faster to the point where I'm just a jibbering wreck and just desperately get to the end of it. So I must apologise for that and don't worry if you can't comprehend it. It's a fault at my end not yours. So never mind. Anyway on with the show. So this is part two. Sit back and enjoy. Watch my thing. How long has it been going for? 15 minutes. Oh this is a disaster. This is going to be far too long. Right okay global variables. So yeah rubbish. Got too many global variables. So I'll just mention the various functions. So I've got the first function come to is getHPRQ. So I've got a description here. Go to hacker probably just a stats page and extract the number of days to next free slot. Turns on Blinkstick LED with coloured dependent on the number of days to next free slot in HPRQ. Prince number of days to next free slot to the display. Yeah so I think that's quite self-explanatory. The next one is a series of functions set up. The control of Blinkstick. So I was probably next from the Blinkstick documentation or whatever. So Blinkstick underscore off. That turns all the Blinksticks you've got attached off. Blinkstick on open parenthesis colour close parenthesis. So if you give it if you pass a value to it the way you should do it you can pass a colour and it will change colours. So if you if you if you's called Bstick underscore on open parenthesis and you put the colour in I don't know let me think blue is our blue. I'm not sure if there's a blue red then I must be a red. Green is a green. Close parenthesis. Then it'll switch on the Blinkstick colour green. So if I like colours what's it say? Black, silver, grey, white, maroon, red, purple, fushia, there's a red. Green, lime, olive, yellow, navy, blue, steel and aqua. How accurate these colours are going to be? Well I don't think it's terribly accurate but there you go. So that's Blink Bstick on. Bstick on random. That just turns it on with a random colour. A Bstick Blink. Turn Blinkstick on with with supplied colour. Oh yeah oh yeah it's Bstick underscore Blink open parenthesis colour close parenthesis. So you can give it a colour and it'll blink off and on basically. Right so into the Blinkstick stuff. So death, run, CMD, run command used to run external Linux commands so you can run a command with that basically. I think that may have got that idea from a project that somebody did to turn their Raspberry Pi into our internet radio thingy. I think I may have got that from that. I'm going to be saving and find the reference. Get my IP. Well that just returns IP address. That's what that does. Get my ESSID. I'll get your Wi-Fi ESSID basically. Get my Wi-Fi strength. Well it gets the Wi-Fi strength as a percentage. Next one. Wait for IP. That tries 10 times to get an IP of our IP address. So while a length of IP is less than 0 and an account is greater than 0, then go through the loop basically. And if it can't get it within 10 turns it'll say I don't know IP. So it's a very, very basic thing. I'm not even sure if it works properly to tell you the truth. I haven't thoroughly tested that. Death show Wi-Fi info. Show us why information on display shows ESSID on first line and both the Wi-Fi signal strength as a percentage and the IP address on the second line. Obviously any of these ideas you can pinch for your own use. So any of these ideas you can obviously pinch for your own use. Custom bitmaps. Slicing of custom bitmaps to use on LCD display. So I've got a speaker. I play a stop. I play list. I pause. I back in a forward. I think some of these I had to draw myself. As it paused I had to draw myself. I can't remember. One of these ones I had to draw myself anyway. I couldn't find an example online. There's a website you can go to to work out. I think it's a chip that uses on the LCD display board and the company that provides a chip has got a website, a handy website where you can put in numbers and it'll give you an approach. It'll show you what it's going to look like basically because trying to is quite tricky to do with numbers yourself without this website. You can do it I think. So that's that. Right long string. Open parenthesis. Long string. Close parenthesis. So this is one of these rare examples where I pass a value to one of my functions. It's a string that you passed it. So writes a long string to the pie face control and display LCD and scrolls it to the left until the last character appears on the right hand side of the screen. This is my I had multiple attempts at doing this. My first attempt was it was just a hack really and it sometimes got it wrong and also stuff that this just this one seems to work. This seems to work reliably and I add a character at the end because it's otherwise it would be very I can special character because I kind of arrow thing I came across. It's like a pointy arrow so that you can clearly see where the end of the string appears and the beginning starts because otherwise it's not tricky to see where the string stops sort of thing. So if there's a there's a few variables look local that's it. You've got global variables and local variables. So local variables are only visible from within that function. So there's a number of local variables in the right long string function. One is called display size and it got set to 15 so that's the number of characters that can be displayed on one line of display. Another one step size and that's kind of set to four. Step size when scrolling message on display so as it's scrolling across how many characters on each scroll does it do you want it to move it you know if it's going to it's going to ripple through is it moving the screen one character or two characters four or whatever now this was off something that I did as a five minute later on because I just well I'll carry on in that explain in a minute. Good after that I've got scroll speed and that set to 0.55 I think that's of a second 0.55 second I just scroll speed delay in seconds between scrolls or the last one is oh last one is scrolling scroll equals zero default value for scroll used when string is smaller than display size sort of the if the scroll if the if the string is smaller than the full width of the screen then there's no need to scroll it sort of scrolls zero so that's what that's for so what I wasn't discovered was that um you know at obviously LCD it's quite a basic LCD screen and at different temperatures the update refresh rate differs so sometimes it can be very bloody particularly when the temperature drops and but then it could be okay in the summer so then you put it make it really slow and then you find it well it's that slow it's taking forever to scroll and it's unnecessarily slow in the summer and so what I did was I thought well it doesn't actually need to move just one character at a time it could it can it can move more and I found it four characters it was quite a good compromise you could still clearly see it scrolling across the screen it looked quite natural and 0.55 of a second between each scroll was fast enough that it didn't blur too much and you could still you could still read it obviously you can tweak these settings yourself but that's a whole point of having these variables rather rather than digging around in the code trying to work out what the heck's going on you can just tweak these numbers and and to suit yourself and you could go crazy I mean you could say okay it was between this month and that month and it's somewhere so therefore set the scroll speed to this speed if it's between this month and that month and it's obviously winter so set it to that speed she could do all this or it's a clever thing it's you're limited only by your own imagination I mean that's that's the beauty of of doing this I think yourself probably nobody else on a planet would be slightly interested in this but here you go remember a tattoo talking about a project that he did they said you know a good project you know was it say something along the lines of something that the person themselves is fascinated by and things it finds it wonderful and but nobody else can see at any point and then you know it's or something to that effect and I think that's true these are just I just tend to use this thing I don't tend to look at it at all I'm look to the code for what other than a tiny we change I was telling you about earlier with a variable and it display sets up the LCD display for selected menu zero for podcasts one for your books and two for system so yeah you just call in at display and it sets the display back up again for reset the the the screen basically quite handy display main menu what's the first tune in a sheet display oh yes display main menu so this is the that when you're changing between the menus you get a brief message telling you what menu you're in so clear LCD and display the appropriate main menu message so for example if you're in menu zero it'll print zero zero open-square bracket podcast close-square bracket wait for point seven of a second and then go to init this init display to initiate the display for the screen for menu zero and if it's not zero it does the one for audio books which is one if it's not that it's two which is system and so on and if it's not that it's an invalid menu right so finally we get on to the buttons except we don't because I think that's a good place there to stop I think that's long enough so thank you very much for listening to this hopefully you've got something out of it if you want to contact me I can be contacted at mrx at hpr at googlemail.com that's mrx 80 hpr the at symbol googlemail.com so tune in next time for exciting episode part three of my series on my python program bye for new you've been listening to hecka public radio at hecka public radio dot org we are a community podcast network that releases shows every weekday Monday through Friday today's show like all our shows was contributed by an hpr listener like yourself if you ever thought of recording a podcast and click on our contributing to find out how easy it really is hecka public radio was found by the digital dog pound and the infonomican computer club and it's part of the binary revolution at binwave.com if you have comments on today's show please email the host directly leave a comment on the website or record a follow-up episode yourself unless otherwise stated today's show is released on the creative comments attribution share a light 3.0 license