Friday, May 8, 2015

AVR ATtiny presentation with examples

Where I work, we hold bi-monthy gatherings where we present and/or debate technologies and tools. As a closet electronics engineer, I thought it could be interesting to drag my components to the office and let me colleagues, have some fun with writing programs targeted for 64 bytes of RAM - quite an anticlimax to our 8GB RAM workstations and 128GB RAM servers!



I put together a Back to Basics presentation about the popular Atmel ATtiny/ATmega microcontrollers, and put the accompanying code up on Github. These are the same family of chips being used by the popular Arduino stack, but I prefer to play with the bare metal using the GCC compiler, there's just something cool about seeing your C program being able to run 10 years on a couple of AA batteries due to the extreme effeciency! While nothing spectacular about it, protocol dictates that I mention this to be released under the Creative Commons license.

Monday, November 17, 2014

ER301 NFC/Mifare driver in pure C#

A YouTube viewer found my old demonstration of ER301 anti-collision and asked if I could make the source code available. So I cleaned it up a bit and wrote this small blog entry about it.

When I started tinkering with the unified Danish transit card about a year ago, it was using a cheap Ehuoyan ER301 NFC/Mifare reader which I got from ebay. This was the first time I played with NFC stuff even if I would since move on to other and better devices. The cool thing about the ER301 however, apart from the price, is that it's relatively easy to interface with. This is because it's using a plain virtualized serial port with native (cp2102) driver available in Linux and even Windows.




No software came with the ER301 reader but there was a download link at the ebay site. The software was very basic, and all examples revolved around a driver DLL for which the source code sadly was not provided. With the documentation in hand and tracing the traffic going over the serial interface, I decided to implement it in pure C# so I would not depend on Windows and static architecture libraries.

Although originally developed with Mono/Monodevelop, the current sources revolves around a Visual Studio solution, with the driver as one project and a simple console application as another. Note that the driver is not complete yet and it caters only to the needs I had at the time (complete dump of data), but it should be fairly easy to extend it with the granularity you might need, since most of the core API have already been implemented. It supports Mifare Classic S50 (1K) and S70 (4K). It can easily be made to support other types as well as long as it's supported by the ER301 hardware.



ER301.NET Console app dumping data from a Mifare Classic S70/4K

The source code is available on Github under GPL2 and most of the interesting stuff takes place in ER301.cs. I am looking into releasing a (WinForms) client application as well, but I need to clear it with a customer of some derivative work first.

Sunday, November 9, 2014

Øredev 2014 - The good and the bad

Last year I went to the 2013 GOTO conference in Aarhus, Denmark. This year, I got the opportunity to visit the 2014 Øredev conference in Malmø, Sweden. The following is just a short reflection of my experiences and they may of course be entirely different than those of other attendees.





The whole setup of Øredev is similar to GOTO and with 1300 attendees I believe they are about the same in size. Being in Sweden, albeit right across the water from Copenhagen, the crowd was predominantly Swedish with perhaps 20-30% of Danes. The speakers were slightly less known than those at GOTO, although a few speakers from Thoughtworks, Oracle and Microsoft stood out.

The good
Øredev feels quite a bit more intimate and cozy than GOTO did. It could be due to the constrained space and the lighting, but the pillow sacs, live jazz and plenty of popcorn, chips, candyfloss and beer sure didn't derail that perception.



Wifi coverage was generally good and there were plenty of sessions to attend as a whole. With decent food and no shortage of coffee, cake, snacks and candy, there was no risk of running out of energy anytime soon. At some point they did run out of the local no-name cola brand and finally gave us real coca-cola soft-drinks. If there's ever an event where you should not skimp on brand name cola, it's probably a conference for developers! :)

The venue also had more of a geek festival feel to it than GOTO had, with its 3D printing, classic console platforms, arcade machines, Occulus Rift etc. There were of course still the typical product pitch stands but it didn't feel quite as dominating.



Unlike at GOTO, where lunch takes place in another building at a specified time, lunch took place in the middle of the venue and was spread out over 1½ hour during talks. This meant that people would not all have to stand in line at the same time nor would it feel quite as chaotic. Also, lunch was served from 3 different locations in the halls, contributing further to the feeling of being able to breathe.

It's also very impressive that the Øredev video's are available some 24h after their capture, something other conferences could definitely take a lesson from. This means it's not quite as annoying to have gone into the wrong talk, since you can always catch up on the one you missed. I remember waiting several months for some of the GOTO videos to come out and I have since forgotten about those I missed seeing.

Last but not least, because of Sweden's very restrictive alcohol policies, you can drink a lot more beer before feeling it. A standard Tuborg with 4.6% alcohol is watered down to 3.1%. Not sure whether to characterize this as either good or bad, but it was an interesting observation none the less.

The bad
Interestingly, and unlike at GOTO, the organizers had not chosen to create an app for the event. This was unfortunate, since the supplied programs were not at all detailed enough to make you decide between conflicting talks - 8 simultaneous tracks are hard to choose from, when all you have to go by is a condensed headline.



In stead, you had to rely on the website which didn't work much of the time due to an unresponsive server and also suffered from navigation issues (on Android anyway). It's a good example of how you can scale so much better by taking advantage of a richer client (read: app) with its own state.

Staying with the app theme, it would also have been nice if rating of sessions was possible from your smartphone - sure there were the occasional iPad with a green-yellow-red star on, but it was only for some sessions at some doors. The GOTO app rating was buggy but at least they had put a bit more thought into it.

Finally, before leaving the app aspect, I also missed being able to ask questions during sessions for immediate followup at the end of the talk. This was something I took great advantage of at GOTO, in order to engage the talkers with my own thoughts and issues. At Øredev only a few of the speakers had set aside time for questions and I think that's a real shame. I got to ask 3 questions at Øredev whereas at GOTO I got to ask 11 questions and also opened up an email discussion about micro-services with Sam Newman from Thoughworks in the following weeks.

The seating at Øredev was perhaps a bit worse than at GOTO, with even the one large theater being devoid of armrests. It's a minor detail for sure, but after spending a day sitting down on tight hard chairs in jam-packed rooms, it would be nice with a bit of cushioning.

The worst experience at Øredev was definitely the interview with Nile Rogers. He was scheduled as a special keynote thursday night about "Passion and collaboration". Now granted, I never heard of the man and I have no special relationship with black hipsters from the 70's, but I still dare to say the interview missed its intended purpose. While Nile was certainly an experience and clearly commanded a guitar in the brief moments we were allowed to hear that, at many occasions I was left with "WTF is this?". At no time did the interviewer succeed in bringing either passion or collaboration into the picture, but seemed more interested in celebrating Sweden for its musical roots and making statements confusing poor Niles. Most of my colleagues had left midway in, I left after 1½ hour where the interviewer had apparently only addressed 4 out of a total 10 questions! If you'd like to see for yourself if it was really that bad, the interview is available here but I'd encourage you to spend your spare time on some of the other video's.





In conclusion
It was a very nice conference experience. In particular I'd like to highlight the cozy venue, widespread plentiful content and the fact that the logistics just simply worked. I do think its a pity, that a large amount of the attendee fee went to pay first class airfare, bodyguard, interviewer etc. for Nile Rogers and his wife and entourage. These conferences should not only be available to large corporations with enough money on their hand and I get the impression that the fee would've been lowered by 1000kr if they didn't have to cater to spoiled famous musicians.

I probably got more professionally out of my visit to GOTO simply because of the inherent ability to engage with the speaker through the questions. If Øredev would adjust these things, it would be a slam dunk which conference to go to.

For the mortal developers not engaged by large corporations, don't forget there's a very approachable and affordable conference in Copenhagen nov. 14 called Driving IT. Having attended IDA events before, I'd love to attend this one as well, but I think 2 conferences within one month is probably pushing the limit with my employer.


Saturday, October 18, 2014

TopIt - Window utility for Windows

It's been many years since Linux became my #1 OS of choice, for a variety of reasons. However, I changed job recently and one unfortunate side effect of that, is that I'm now having to spend my work hours on Windows again. Apart from the lackluster command-line, bloated environment, inhospitable development experience etc. etc. one of the annoying aspects, is how desktop and window management basically haven't changed since Windows 95 - for instance, it's still up to the individual application in question, whether it wants to allow the user to pin down a window, promoting its z-order to always be on top. This blog entry is about my attempt at bringing a bit more power to window management as seen from a Linux user.

Gnome Linux desktop
Talking about "the Linux desktop" is a bit of a misnomer. There are of course countless of XOrg window managers. All the recent KDE and Gnome versions I've come across, supports being able to pin a window on top (promote z-order), move a window to a specific workspace/desktop and control a windows transparency/opacity.


In Cinnamon, the Mint fork of Gnome Shell, z-order behavior is build right in!


Crap-ware nightmare 
There have never been a shortage of 3'rd part tools available for Windows to empower users, the problem is... finding them and knowing the flowers from the bad weed. Traditionally there's lots of spy-ware, share-ware, trial-ware in the Windows Eco-system.

I set out with a relatively modest goal, to find a simple application that would allow me to pin a window as the top-level window - something I use all the time for small TODO lists, calculator, chat applications etc.

One application turns up in Google searches as the de-facto solution to the problem, namely Window On Top, which also got a favorable mention on LifeHacker. I downloaded the application, installed it and all seemed fine and dandy... until I was met by a nag screen.


Bait-n-switch in action, Window On Top appears to be trial-ware!

Although neither the authors website, nor LifeHacker, has any mentioning of it being trial-ware, the application costs a whopping $20 - a ridiculous amount for something so simple! A similar utility called MooO which also got a mentioning on LifeHacker, is apparently infested with tool-bars and who knows what other crap.

Realizing full well how I may sound like a grumpy old fart with a long beard and entirely too much time on my hands, these crap-ware experiences made me want to try to solve this problem for myself.

Introducing TopIt
It's been some 10-15 years since I played around with the Windows API's. Back in the Visual Basic and MFC days, if you had to do something just remotely interesting, you had to call C/C++ functions from the core DLL's, so I had a pretty good idea as to how to go about this.

It took a few mornings and evenings of tinkering (when the wife and baby are sleeping), but I now have something entirely functional. In fact, it does more than just toggle a window on/off top - I guess you could argue that it already suffers from feature creep.


TopIt manipulating opacity/transparancy of a third-part window

These features are to be considered stable and tested:
  • <Alt>+<Z> Toggles the "always on top" Z-order lock of a window
  • <Alt>+<X> Completely hides the window temporarily (until combo hit again)
  • <Alt>+<C> Toggles the re-sizable/movable border of a window on/off
  • <Alt>+<Num Plus> Increases opacity (removes transparency) of a window
  • <Alt>+<Num Minus> Decreases opacity (adds transparency) of a window
The following features are tested but somewhat experimental:
  • <Alt>+<Num 5> Tries to expand window to take as much desktop space as available
  • <Alt>+<Num 2> Selects bottom edge of window for manipulation
  • <Alt>+<Num 8> Selects top edge of window for manipulation
  • <Alt>+<Num 4> Selects left edge of window for manipulation
  • <Alt>+<Num 6> Selects right edge of window for manipulation
These features are highly experimental and may or may not work:
  • <Alt>+<Num 7> Selects  top-left edges of window for manipulation
  • <Alt>+<Num 9> Selects  top-right edges of window for manipulation
  • <Alt>+<Num 1> Selects  lower-left edges of window for manipulation
  • <Alt>+<Num 3> Selects  lower-right edges of window for manipulation

You can get TopIt by downloading the raw x86/x64 executable or by cloning my reposatory on GitHub and building it yourself from source. The latter is preferable, as its the bona-fide approach to ensuring what you install on your computer. The memory footprint is absolutely minuscule, requiring just about 800KB of RAM.

Note that if you download the binary executables, you will have to launch it automatically when Windows boots. You can do so by including it in the Windows Start Menu "Startup" folder.

Since starting out on this project, I have since become aware of the utility called PowerMenu which looks very close to what I wanted originally, apparently without being crap-ware. The application is donor-ware, so should be safe to download and you'll likely want to use it rather than TopIt, since it is older and thus better tested. However, my efforts are not entirely wasted, as I plan to expand on TopIt further to get me some more power-features at a minimum overhead. Lot's of ideas come to mind:
  • Application screenshot (invoking "Save as..." dialog)
  • Emulation of multiple workspaces/desktops
  • Dockable and snapping windows
  • Menu item injection
  • Move applications to/from systray
  • Programmable hotkeys
Should you have any cool ideas which would boost your productivity on Windows, you are of course more than welcome to drop me a line about it or fork the code on GitHub and add it yourself. :)








Monday, April 14, 2014

Rejsekort Scanner i samarbejde med Rejsekort A/S

Siden mit forrige blogindlæg, har jeg taget kontakt til Rejsekort A/S og efterfølgende haft flere møder med dem, primært med chefkonsulent Gregers Mogensen. Det har været ganske interesant at få lejlighed til at stille spørgsmål og få indblik i de problemstillinger i systemet som jeg selv har oplevet.

Rejsekort A/S har været overaskende imødekommende og selv om min opfattelse måske er, at der har været lidt vel mange kokke i køkkenet, svarer de rimelig godt for sig og har anlagt en god pragmatisk holdning til tingene, hvilket incl. mig og mit lille indspark.

Der har udspillet sig lidt af en kamp på ord, imellem pressen og Rejsekort A/S, som også jeg blev en mindre del af. Min eneste kommentar til denne del af debatten er nok, at jeg ingenlunde forventer at mobilproducenterne retter ind efter et dansk rejsekort, selv om det da ville være skønt hvis de gjorde.

Udlevering af stationer/stoppesteder

Ved mit andet møde fik jeg uden viddere udleveret et Excel-ark med samtlige stationer/stoppesteder. Skønt det viste sig at Rejsekort Scanner læste stationsdata en smule forkert, gik der ikke lang tid før dette var korrigeret og stationsdata nu lå umiddelbart tilgængelig i selve app'en. Det betød at nu kunne den mest komplicerede del af programmet (geolocation og en masse asynkrone webservice kald) skrottes, ligesom programmet blev hurtigere og nu kunne vise samtlige 20000 placeringer - ikke kun de ca. 200 jeg havde fundet via crowd-sourcing. Excel-arket indeholdt også zone info, så jeg fik ligeledes mulighed for at forbedre aspektet "fortsat rejse" i tilfælde af når folk er under transit i samme zone men imellem forskellige stationer/stoppesteder.

Stod ved en skillevej

Indtil viddere har jeg kunne spille med åbne kort, udtale mig om præcist hvad jeg havde lyst til, beskyttet af det faktum, at man ikke kan tage copyright på, eller patentere, et format, en protokol eller et API. Selv om der er mange der har spurgt ind til de tekniske detaljer, har jeg med vilje undladt at kommentere og publicere dette aspekt indtil jeg havde tænkt tingene grundigt igennem og forhørt mig hos Rejsekort A/S.

Der var to primære veje frem. Enten fortsatte jeg som hidtil med reverse-engineering (puslespil for nørder) og lave en app der virker for de brugs-scenarier jeg lærer at kende igennem fejlrapporter. Alternativet var at indgå i et samarbejde med Rejsekort A/S hvor jeg ad officiel vej får adgang til den fornødne tekniske dokumentation. Der var fordele og ulemper ved begge veje, for selv om det ville være skønt at kunne lave app'en perfekt, strider en NDA imod mit princip omkring åbenhed - jeg har før omgået en NDA i en lignende situation.

Indgået samarbejde

Efter nøje overvejelser, indgik jeg d. 11/4/2014 et samarbejde med Rejsekort A/S. Udslagsgivende for dette var, at jeg blev ved med at modtage suspekte eksempler på rejser som Rejsekort Scanner ikke kunne vise korrekt, primært når en cykel var involveret, opgradering til 1 klasse, samt lignende specielle tilfælde der alligevel er forbavsende mange af. Rejsekortet er af en meget dynamisk natur.

Når jeg lagde alt sammen, var det mest fordelagtige for mig, at indgå i et samarbejde. Nogen vil sige at jeg har solgt ud, andre vil egentlig bare gerne have en Rejsekort Scanner der virker 100% korrekt. Jeg tror og håber på, at de fleste hører til den sidste kategori.

Samarbejdsaftalen giver mig nogle rettigheder samt nogle forpligtelser, og indeholder også et økonomisk incitament. Der er tale om et støtte-tilskud, ikke et køb, dvs. jeg bibeholder samtlige forpligtelser og rettigheder fremover, med undtagelse af at jeg nu ikke kan frigive kommende versioner som open-source jvf. tavshedserklæring. I praksis vil jeg have svært ved at bevise hvad jeg vidste før og efter aftalens indgåelse (selv om jeg har tagget revisionskontrolsystemet), så jeg vælger nok den sikre vej ved at sige så lidt som muligt.

Fortsat udvikling

Rejsekort Scanner vil altså efterfølgende nuværende version 1.1.28, blive viddereudviklet ud fra officiel teknisk dokumentation hvor jeg forventer at tilvejebringe rabat-trin, komfort-trin, person-antal. zone-skift mv. Jeg kunne også godt tænke mig, at forbedre usability lidt, ved f.eks. at vise saldo-bevægelser når man holder telefonen vandret, hvor der jo er lidt mere kolonneplads.

En "Pro" version, uden reklamer og med mere avancerede features, er også en vej jeg påtænker at gå - der er en del brugere der har givet udtryk for at de gerne smed en mønt, mod at komme af med reklamer. En evt. "Pro" version vil iøvrigt brige størrelsen på app'en ned fra 3MB til 1MB, da Google's AdMob ikke ville skulle inkluderes.

Skal jeg tænke endnu længere ud i fremtiden, kunne det være overlegent, at kunne beregne en forventet pris, FØR en rejse er afsluttet. Ligeledes, kunne "spar 12kr ved at tage afsted en afgang senere" eller "Opgradér til 1 klasse for 28kr" tips bidrage til yderligere gennemskuelighed af rejsekortet.

Den fortsatte udvikling er ikke blevet gjort mindre interesant, efter det har vist sig at flagskibene HTC One M8 og Samsung Galaxy S5, der vil stå for en betragtelig andel af smartphone markedet i det kommende år, kan skanne rejsekortet. Jeg har derfor selv købt førstnævnte! :)


One M8 har jeg kunne observere i loggen for Rejsekort Scanner i et par ugers tid.



Det er først fra den officielle launch-dag d. 11/4, at jeg er begyndt at kunne se seriøst aktivt brug af Samsung's Galaxy S5.