just another web log

30 Apr 2020:
keeping a pi from blanking its X
Somewhere along the line I go t Raspberry Pi 4 and the first thing I noticed was the annoying screen blanking. Which, apparently is not a screen saver but power management.

Now it 8+ years since the Pi's release and a lot of people have looked to resolve the issue of the screen blanking when they do not want it to. So I was very surprised to find all the normal places devoid of consistent "Thanks! that works", but instead found a lot of "Did not work for me".

The official fix is to install xscreensaver, which normally I am in favour of, but installing 40MB to disable a screen blanking? There HAD to be a better way.

On the official Raspberry Pi forum was an old discussion that included, in passing, some github issues. But that issue was closed...

I tracked the user who closed it down to a cloned repo for raspi-config and there was the magic answer.

This fix has made it into the main Branch, but I do not think it is enabled, at least in the GUI version.

mkdir -p /etc/X11/xorg.conf.d/
cp /usr/share/raspi-config/10-blanking.conf /etc/X11/xorg.conf.d/

Where the contents of /usr/share/raspi-config/10-blanking.conf is

Section "Extensions"
    Option     "DPMS" "Disable"

Section "ServerLayout"
    Identifier "ServerLayout0"
    Option "StandbyTime" "0"
    Option "SuspendTime" "0"
    Option "OffTime"     "0"
    Option "BlankTime" "0"

You do need to reboot, but it does work!
27 Apr 2020:
git pages script bit lack of master commits
Enjoying the progress of my little bitey project I wanted to get the code out to my production server for users to experience.

When I say "Production Server", I mean the secret github pages(gh-pages) that comes with every project. I did a flog post about setting them up, but basically they are just a git branch off master.

So I automated the process of
  1. make a temporary folder
  2. copy requested files from the current master branch into it
  3. switch to the gh-branch
  4. copy those files from the temp folder to the project folder(now the gh-pages branch)
  5. add/commit them to the gh-pages branch
  6. push them to the github server
  7. switch back to master branch
  8. profit!

and in the first basic test it worked perfectly. So what went wrong?

In my hurry to publish a cool update I omitted adding the change to a commit in the master branch. So when the I switched to gh-pages branch with
git checkout gh-pages
It got all the gh-pages commits e.g. a lot older and overwrote them. Then the script copied all the new code over to gh-pages. All good so far, except for master.

Then disaster struck, I entered my github login incorrectly, but the script happily got all the (old) commits on master and switched to that branch. But I did not notice, I was just annoyed I got the login wrong. So I ran it again ...
Which happily copied all the files from master (old) and then tried to publish them to gh-pages.

Luckily I was able to recover from the View Source in the browser.

The publish_gh-pages.sh script has a little more protection and now looks like this. Use at your own peril.
# take files from master and add them to gh-pages branch and then publish
# returns you to master
if [ -z "$TARGET" ]; then
echo "Please supply files, cannot continue, exiting"
echo "USAGE: $0 <files separated by space>"
exit 1
git diff-index --quiet HEAD --
if git diff-index --quiet HEAD --; then
    echo No outstanding changes
    # Changes
    echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    exit 1
tmpdir=$(date +"%s")
mkdir /tmp/$tmpdir
cp $@ /tmp/$tmpdir
echo $@ saved to /tmp/$tmpdir
echo switching to gh-pages branch
git checkout gh-pages
echo overwriting $@ files
cp /tmp/$tmpdir/* .
git add $@ ; git commit -m "updating gh-pages with latest code"
git push origin gh-pages
if [ $? -eq 0 ]; then
    echo OK
    git checkout master
    git status
    echo FAIL
    echo you are stuck in gh-pages branch
    echo most likely you want to
    echo git checkout master
    echo you did commit all your changes did not you?
    echo use
    echo git status
    echo to check what branch you are on

I was also caught out by the fact that gh-pages the site takes a few moments after the files are pushed. A few more moments than I expected.
27 Apr 2020:
Take the Shark by the enum and delaying a CSS animtion trip
So much new stuff going on in the shark tank since my update about the animation/game loop.

The game is playable, well, as a basic anagram game i.e. completing a word brings up a new word, until it crashes with no more levels :D But considering how difficult the words are even without any sharks, well, good luck getting to the crash!

I had a cool CSS animation playing on the Tiles when you complete the current word. The letter tile would go to 50% opacity and as it animated to 1.5 times it's size the opacity would return to 100%. This is followed by a small dip(translation down the screen) and then a jump up with the tile rotating in 3D and disappearing off the screen. These animations are staggered across the letter tiles of the word, making a cool ripple/wave effect. This worked fine for level one and it's large four letter tiles, later levels not so much. Later levels have more letters per word and more letter tiles, making them smaller to fit. The CSS animation used percentages to get the tile to travel off the top of the screen and increasing it for later tile sizes caused the earlier ones to move too quickly(as they tried to travel greater distance in the same amount of time). On top of this I am trying to make everything screen size agnostic, which would include a portrait screen shape.

I looked at dynamically creating the CSS for every animation and setting up the translate percentage based on individual size, but this was thwarted by CSP(Content Security Policy) that will complain if you fiddle with the CSS on a page. So then I thought about implementing all those animations in my animation loop. In the end I kept all the CSS animation as it was, except the translate up. This I did implement in the animation loop and I even created a working delay parameter in to the system. So, as the CSS animation does it's thing, my code is hoisting the whole thing up the screen to the correct location. Works really well, even on mobile.

Next I looked at all the janky Booleans in the Tile class. I realised that each one was really an exclusive "state" of the tile and what I need was an enum.

// Tile State - enum equivalent

Which is not a true enum, but suits my use case perfectly...

// check if any objects need animating for GAMEANIMWON - end of level "up" animation
    animatableTiles = tiles.filter(x => x.state == TileState.GAMEANIMWON);

I also replaced all my uses of var with let. var creates document/global variables where as let creates them just in the scope they are used. This was not an option when I started 20+ years ago.

Which brings me to this ...

for (let i=0;i<tiles.length;i++) {


tiles.forEach(function(tile) {

I started with forEach, but kept seeing posts that forEach is slower than a basic for loop, so switched. Since then I have seen pros and cons for both, with the final word being "current generation browsers appear to be optimised for 'for loops', but, ideally the next generation will optimise for forEach".

Needless to say, there were plenty bone head mistakes that cost me a lot of time(haven't got any hair), including a bothersome semicolon and accidentally deleting two hours of work. That will be the subject of my next post.

Go play the game
20 Apr 2020:
robonearth woos folding at home
Brief folding@home update;

Team Hackaday

RobOnEarth stats.
20 Apr 2020:
framework to work with shark frames
It has been a while since I posted any Shark action, but I have been making(slow) progress.

The latest code uploaded to my public demo pages looks the same, but the tiles will now seek the valid locations.

This tile settling animation is currently set to two seconds and looks very sluggish, but I will tighten that in future releases.

To get to this point(dynamic animations) I did have to do quite a lot of work.

First up is the requestAnimationFrame magic/voodoo. By calling this with a function and then calling it again in that function, we create an infinite loop. Normally infinite loops are very bad in Javascript, but here the function is only called when the browser is ready, usually once per frame.

This means that

function animate(timestamp) {
// do animation work

creates an animation system that can be added to and if the browser happens to be busy, all that happens is it is called less.

This is where it becomes a bit more complex. The timestamp is sent by requestAnimationFrame and is the number of milliseconds since the document was created. This can be compared to find out how long since requestAnimationFrame was last called and affect how much your animation should proceed.

In the // do animation work section I loop through all the game tiles and check if any have a flag set stating they were just dropped by the user and now needs to be animated.

I calculate the nearest tile position that the tile could occupy and then set about creating the required animation.

Elements of a successful animation are
Start Position: Where did the animation start from. So just record where the tile was dropped by the user.
Finish Position: Where do we want the animation to end.
Distance to Finish Position: We actually want these values to calculate where in the animation the current progress should take us.
Length(in milliseconds) of the total animation: we can compare this to the timestamp as sent by requestAnimationFrame

So each frame or call from requestAnimationFrame we can, for each tile that may need animating;

Calculate the percentage of time that has passed since the animation was started. This is represented by a value that is 0.0 - 1.0. We can then multiply the distance by this value and add it to the Start Position.

So when that time fraction is 0.0 nothing is added to Start Position and when it is 1.0 the full distance is added to Start Position putting the animation at Finish Position. At 0.5 50% of the distance would be added to Start Position putting the animation at exactly half way.

This was one of those things that sounds simple on paper. I had to research how requestAnimationFrame worked quite lot before I could even begin to mess about with the maths to get those values and get them right.

There was plenty of non-moving tiles and tiles that shot off the page at the speed of light.
11 Apr 2020:
folding covid19 at home after a few false starts
I have been sick for the last 3 weeks and I am still recovering. Most likely Covid-19, although my fever never got quite to the level required to be classed as Covid-19.

Read a lot about how Folding@Home were working on Covid-19 on various sites and thought I would give it a go.

emerge --ask sci-biology/foldingathome
These are the packages that would be merged, in order:

Calculating dependencies... done!

!!! All ebuilds that could satisfy "sci-biology/foldingathome" have been masked.
!!! One of the following masked packages is required to complete your request:
- sci-biology/foldingathome-7.5.1-r3::gentoo (masked by: FAH-EULA-2014 license(s), ~amd64 keyword)
A copy of the 'FAH-EULA-2014' license is located at '/var/db/repos/gentoo/licenses/FAH-EULA-2014'.

For more information, see the MASKED PACKAGES section in the emerge
man page or refer to the Gentoo Handbook.

Recently Gentoo has been resolving these for me, so I not sure why I needed to go old-school.

Lets add the licences and try again.

vi /etc/portage/package.license
#required by FaH
>=sci-biology/foldingathome-7.5.1-r3 FAH-EULA-2014 FAH-special-permission

emerge --ask sci-biology/foldingathome
These are the packages that would be merged, in order:

Calculating dependencies... done!

!!! All ebuilds that could satisfy "sci-biology/foldingathome" have been masked.
!!! One of the following masked packages is required to complete your request:
- sci-biology/foldingathome-7.5.1-r3::gentoo (masked by: ~amd64 keyword)

For more information, see the MASKED PACKAGES section in the emerge
man page or refer to the Gentoo Handbook.

So I am running full INTEL now, but seems ~amd64 is still the keyword.

vi /etc/portage/package.accept_keywords
# needed by folding@home
sci-biology/foldingathome ~amd64

emerge --ask sci-biology/foldingathome
These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild N     ] dev-util/patchelf-0.10
[ebuild N     ] dev-libs/openssl-compat-1.0.2u USE="asm sslv3 tls-heartbeat zlib -bindist -gmp -kerberos -rfc3779 -sctp -sslv2 -static-libs -test -vanilla" ABI_X86="(64) -32 (-x32)" CPU_FLAGS_X86="(sse2)"
[ebuild N    ~] sci-biology/foldingathome-7.5.1-r3

Would you like to merge these packages? [Yes/No]

...SNIP code compiling...

>>> Recording sci-biology/foldingathome in "world" favorites file...

* Messages for package sci-biology/foldingathome-7.5.1-r3:

* Special permission is hereby granted to the Gentoo project to provide an
* automated installer package which downloads and installs the Folding@home client
* software. Permission is also granted for future Gentoo installer packages on the
* condition that they continue to adhere to all of the terms of the accompanying
* Folding@home license agreements and display this notice.
* -- Vijay S. Pande, Stanford University, 07 May 2013
* (ref: http://foldingforum.org/viewtopic.php?f=16&t=22524&p=241992#p241992 )
* Adding group 'foldingathome' to your system ...
* - Groupid: next available
* Adding user 'foldingathome' to your system ...
* - Userid: 994
* - Shell: /sbin/nologin
* - Home: /opt/foldingathome
* - Groups: video
* - GECOS: added by portage for foldingathome
* - Creating /opt/foldingathome in /
* To run Folding@home in the background at boot:
* (openrc)    rc-update add foldingathome default
* (systemd)    systemctl enable foldingathome
* No config.xml file found -- please run
* emerge --config foldingathome-7.5.1 to configure your client, or specify
* all necessary runtime options in FOLD_OPTS within
* /etc/conf.d/foldingathome
* Please see /opt/foldingathome/FAHClient --help for more details.
>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.

* GNU info directory index is up-to-date.

It is installed but not configured.

emerge --config foldingathome-7.5.1
!!! 'foldingathome-7.5.1' is not a valid package atom.
!!! Please check ebuild(5) for full details.
!!! (Did you specify a version but forget to prefix with '='?)

emerge --config foldingathome
Configuring pkg...

./FAHClient: /opt/foldingathome/libssl.so.10: no version information available (required by ./FAHClient)
./FAHClient: /opt/foldingathome/libcrypto.so.10: no version information available (required by ./FAHClient)
./FAHClient: /opt/foldingathome/libcrypto.so.10: no version information available (required by ./FAHClient)
20:37:16:INFO(1):Read GPUs.txt

User name [Anonymous]: robonearth
Team number [0]: 44851
Passkey: 590d9b339438bc0e590d9b339438b
Enable SMP [true]:
Enable GPU [true]:
Name of configuration file [config.xml]:
Overwrite 'config.xml'? [y/N] [false]: y

The passkey assigns your work units to your username. This has a number of advantages, you will be ranked(slightly) higher than non-passkey participants, allows you to use multiple computers and have the numbers add up. Finally it stops anyone else claiming the work units just by using the same username.

It is really easy to setup. You enter the username and an email address and it emails you the unique passkey.

and finally lets add this service to start at boot and kick it off
rc-update add foldingathome default
/etc/init.d/foldingathome start

* Caching service dependencies ...                                                                                                             [ ok ]
* Starting foldingathome ...        

And check it is running OK
cat /opt/foldingathome/log.txt

Initially I found a lot of
WARNING:WU02:FS00:Failed to get assignment from '': No WUs available for this configuration
ERROR:WU02:FS00:Exception: Could not get an assignment
ERROR:WU02:FS00:Exception: Server did not assign work unit

But eventually work units did come in.

Oh, that Team Number is Hackaday's. I tried to get LTT's and originally I had Gentoo's, before I got a passkey.
loading results, please wait loading animateloading animateloading animate
[More tags]
rss feed



flog archives

Disclaimer: This page is by me for me, if you are not me then please be aware of the following
I am not responsible for anything that works or does not work including files and pages made available at www.jumpstation.co.uk I am also not responsible for any information(or what you or others do with it) available at www.jumpstation.co.uk In fact I'm not responsible for anything ever, so there!