State of displays

Teeing up a display for an embedded system is a little more complex than buying a monitor.

At the core of it is one of my favorite sayings, “The wonderful thing about standards is that there are so many to choose from.”

Starting from the screen end of things, I want a screen that is roughly 150x90mm in size. Because I want it viewable from the side and ideally all angles, I have a strong preference for an IPS display. I found a screen that is really nice, Topfoison’s 6″ IPS display.

This display uses MIPI DSI for its video signal, specifically a 4 lane MIPI DSI interface (because standards restrict choice too much many standards allow incompatibility within themselves).

MIPI DSI is an interesting standard, it is a mobile industry standard (Mobile Industry Processor Interface – pronounced lowercase as mipi, like nbn) which essentially specifies a number of half duplex SERDES links for throwing video around. Many mobile phones seem to have adopted the standard as it removes the need for a video converter – reducing part count/cost, simplifying cabling and reducing internal EMI. The display and chip manufacturers have shifted with the market. However as it is fairly new mostly it is new/expensive hardware with support.
If you are meant to be doing something else here is some further reading, nice overview, detail with pretty scope pictures.

So, looking at hardware to plug in to this we have:

  • BananaPi M1, the board I have been planning on using.
    Is not listed as supporting MIPI DSI, does support relatively generic LVDS output.
    Graphics processor is the ARM MALI400 MP2, the newer ARM MALI cores include a display controller but I believe this wasn’t the case for the MALI400. I haven’t been able to find documentation on what display controller Allwinner used in the A20 chipset.
    Some websites do claim that BPI has a MIPI DSI output, I think they are wrong and are simply assuming that the RaspberryPi look-alike video header is a function-alike video header.

  • BananaPi M2
    Uses the Allwinner A32s (datasheet) chipset which does not support MIPI DSI output.
    The Allwinner A31 does, but it seems they removed it when pluralising chip.
    The SinoVoip website lists the output as “LVDS/RGB/CPU display interface (DSI) for raw LCD panels” on the product page. However the DSI gets dropped when getting into the detailed LCD connection information.

  • BananaPi M3
    Uses the Allwinner A83T chipset
    Specifically states support for MIPI DSI and MIPI CSI interfaces, with dedicated headers.
    However this isn’t available yet, when contacted SinoVoip suggested it should be out around the end of this year.

  • Raspberry Pi
    The Raspberry Pi uses a Broadcom chipset which supports and has a header for 2 lane MIPI DSI output.
    However due to driver issues this output isn’t generally useable.
    There are complex projects made with custom hardware to convert the HDMI output to MIPI DSI.
    The Raspberry foundation produced a screen which uses the MIPI DSI output with kernel support. Apparently they managed to do it in such a way that generic boards aren’t supported, just theirs.

  • Lemon Pi
    Uses an Actions S500 chipset
    Specification states support for MIPI DSI but doesn’t specify how many lanes and the S500 documentation doesn’t mention DSI.
    Not yet available, indications that things are happening so may ship this year.
    Includes (optional) built in bootable permanent storage.

  • Other boards
    There are other systems out there which aren’t suitable for various reasons.
    For example the H4 Hummingbird uses the Allwinner A31 with MIPI DSI output but at $70 isn’t competitive.

Making choices

I have ordered the official SinoVoip 7″ LCD touchscreen. This is a non-IPS 7″ display connected to the LCD connector via a dedicated adaptor board. It also includes a touchscreen, no details so am assume it is a capacitive panel. The main reason for getting this screen is that as it is distributed by SinoVoip it should be well supported, the price is rather high but I haven’t inquired about production quantities.

I am also negotiating an order of the Topfoison 6″ IPS screen with HDMI adaptor. The adaptor seems to add about $5-10 USD per unit and I expect a HDMI cable will be a few dollars, so the wiring ends up being a substantial percentage of the screen costs. Currently using MIPI DSI directly isn’t an option but I will definitely reevaluate down the track once the next generation of boards comes out.

Choosing a touchscreen

When selecting a touchscreen there is actually an interesting choice that I have to make. There are two common touch technologies, resistive and capacitive, many people probably know it as old and new touchscreens. (Interesting aside, capacitive screens actually came first in 1965 but weren’t widely adopted, then resistive screens became common before capacitive screens resurged with phones and became the “new” style.)

Resistive screens

A resistive screen works by letting you push one side closer to the other and detects this change.

Pro:

  • Electrically simple, 4 wire support built in to BananaPi A20 chip.
  • Cheaper to manufacture.
  • More accurate detection than capacitive screens.
  • Will work if wet.
  • Will work if wearing gloves, using elbow or poked with a stick.
  • Plastic is scratch resistant.
  • Can optionally detect pressure.

Con:

  • Easier to damage screen.
  • Damaged screen is useless, minor damage typically causes complete failure.
  • Only supports two simultaneous touch points.

Capacitive screens

A capacitive screen detects power loss to a nearby conductor such as a finger. The modern standard is a projected capacitive technology (PCT) panel which means a direct touch isn’t required, this allows a protective glass layer to be inserted on the top of the screen assembly.

Pro:

  • More familiar to people.
  • Easier to clean.
  • Sensitive PCT devices can detect fingers through insulating gloves.
  • Supports complex multitouch patterns.

Con:

  • Fails if coated in a conductive material, such as sweat or food liquids.
  • Sensitive to mechanical design, the metal chassis is a conductor which can significantly impact on screen operation and sensitivity.
  • Conductivity varies on the person, the person’s hydration, ambient humidity etc.

Further pontificating

So for something portable, like a phone, going capacitive is obviously the better choice.

For a kitchen appliance it is far less clear. Wearing dishwashing gloves or smearing tomato sauce across the controls is going to be more common.

The big factor I keep coming back to is the familiarity. People expect to have a solid capacitive touch screen and attach a higher quality value to it than a resistive screen. And that the limitations of the capacitive screen are well understood so people seem happy to work around them.

Basically the engineer in me leans towards resistive, the marketing orphan I recently adopted says capacitive.

So for now I’m getting both. I am already familiar with capacitive touch panels and have one coming as part of one of my screens. So I just need to acquire a resistive panel to play with and understand.

Shopping

Buying a resistive panel is far harder than it should be… mostly due to limitations with the wondrous site alibaba.

<rant>
Alibaba is fantastic for interacting with component suppliers but the search engine is absolute rubbish, pre-Google Yahoo rubbish. (As Yahoo used to own a substantial chunk of Alibaba maybe it is literally the pre-Google Yahoo rubbish.) Essentially you enter some words, Yahoo searches for those words in the title of each product, the product with the most words in common is the top of the list. Which means that the retailers create new duplicate product entries with different titles trying to hold the bingo card that matches your search words. One touchscreen manufacturer had a single 4 wire resistive touch product, available in about 15 different sizes. They had roughly 1800 bingo cards/product entries trying to attract eyeballs.

(A nice trick with Alibaba direct is that they don’t keep these all updated, so you can often get up to 20% off by finding a differently priced entry of the same product from the same manufacturer.)

Once I find a manufacturer I try to figure out if I can trust them. A warning trigger for me is anything that they are obviously lying about in their marketing, if there are obvious lies I can see then there are probably subtle lies that I can’t and will bite me later. With resistive touchscreens however EVERYBODYalmost everybody lies, possibly this is related to the above Alibaba is crap rant. And it doesn’t look like lies that help them, a 4 wire touchscreen has four analog passive resistive wires, they state this, then in the interface section they state “RS232 or USB interface”… which I don’t understand. It clearly is a 4 wire FPC connector, there is no RS232 or USB plug in the picture, no mention in the description. I suspect there is a series of checkboxes box for interface and they feel the need to tick something… Another odd one is they list a resolution, numbers vary but all are wrong. It is an analog device, any resolution limitations come from the quantization performed by the controller, which they don’t sell. Why provide a fake number and risk it being smaller than somebody else’s fake number when the real answer is infinite and therefor better? sigh
</rant>

Buying

I have reached out to three suppliers for further information:

I also found some interesting capacitive touch manufacturers in case I go that route:

Microwave Update

So for the more recent substantial chunk of time I have been neglecting this project, mainly procrastinating by playing with Zookeepr code. Over the last month I’ve churned almost 20k lines of code, though not all committed yet. Which is a relatively productive way of being spectacularly unproductive.

The big news is that I was selected to speak at the next linux.conf.au. I confess this was a bit of a surprise, my long term plan was to submit proposals to a few venues this year and hopefully speak in 2017. Spectacular success on that front does change the microwave plan slightly as it commits me to having a demonstrable prototype – so I’ve shifted my project reevaluation point further down the game plan and split the prototype section into two halves with an evaluation point between the cheap and expensive halves.

To support this shift I have restructured my plans around the basic prototype. I have set the final vision and the order of steps to achieve it.

As the base I will use a Panasonic NN-SF550W Microwave, this is a basic microwave that features an inverted power supply and magnetron as well as a flatbed and stirrer. I will replace the display with a screen and touchscreen, the processor with a banana pi. The power supply and door sensors will be integrated with the processor. Both the Panasonic Grid-Eye and Seek Thermal cameras will be mounted into the roof, I may only connect one at a time. A set of scales will be built into the floor of the microwave, probably using the existing base plate. Software of some sort will tie all the components together though it may not be pretty.

Work plan

At a rough estimate I’m looking at 2-3 months work to get a feature complete franken-prototype. There is also significant delay time in there to acquire new components to play with.

The groups of work are:

  • Screen
  • Touch
  • Scales
  • SeekThermal
  • GridEye
  • Inverter
  • Other electronics
  • OS Software

The Gantt chart below breaks it out into a bit more detail with some rough timing. I have only staggered out the next two weeks because I expect predicting that far out is ambitious, further would be silly.

I’ve also used a different program to generate the gantt chart with a different style of export, trying out Gnome Planner instead of Gantt Project. I confess I don’t really like either of them.

Gantt Chart

view fullscreen

Thermal imager gradient fix

One of the thermal imagers I have been considering using is the Seek Thermal camera. An impressive camera, currently only available in the US, they use a Raytheon sensor to create a small USB camera designed to be used with a mobile phone. Most importantly for me it supports a wide range of temperature, an intentional limitation with the FLIR cores.

Sadly the camera has some issues. All thermal sensors require post-processing to clean up the image and work around quality issues with the image, it is a bit more complex than a standard CCD. The Seek camera does some basic processing in the device but most of the image manipulation required to get the camera working is performed in the Android application. Seek has been promising an SDK since the product was first announced, presumably this will allow other clients to be used, but no SDK has been forthcoming.

I have been spending a fair bit of time trying to understand how to use their factory calibration values and get a good temperature reading out of the device, so far unsuccessfully.

As a side effort I spent a bit of time working on another problem with the device, with more success.

When first released the camera had an erroneous thermal gradient at the edges and particularly the corners. This was particularly obvious if you pointed the camera at a thermally flat surface, such as a wall, the autoscaling would highlight the error as the only variation in the image. Various people reported that adjusting the lens holder helped and that the problem varied with time. I believe that the issue is a combination of the lens holder being imperfectly aligned and so its temperature influences the sensor, the lens holder is heated by the circuitry around it and so gets worse with time.

Early this year Seek corrected the problem with a software update. Looking at version numbers of each component it was clear that the fix was purely post-processing performed by the Android application. They have never responded to questions on how this was achieved.

I have managed to figure out their technique and have documented it in an Octave/Matlab function which reproduces the process used. Hopefully this will allow people making independent clients to apply similar corrections and allow the camera to be used with non-phone devices.

I discuss details of the technique on the eevblog forum where most of the Seek dissection has taken place. The script is also relatively simple and commented for anyone with Matlab experience.

Some before and after photos of the processing. A thermally flat image and some ugly face.


Before – Floor

After – Floor

Before – Face

After – Face

It is interesting to see that the corrections to the face go far further than I initially expected.
The fixup in the bottom right corner is obvious, the gradient gets changed to a flat background.
However the fixes around the bottom of my face were startling, my neck gets corrected to a much better temperature, the beard cools down and the jumper collar cools right off. I think all these revised details are more accurate.

Source code, including the raw data of my face and usage instructions, is on github.

Door design

Designing a door

Designing the door to the microwave is turning out to be a bit more fiddly than I hoped. This is a combination of mechanicals being new to me and regulatory concerns about keeping the dangerous radiation in the box.

The criteria isn’t too complex, discovering that non-Australian standards are a touch more expansive was an unpleasant surprise though:

  1. Must open to allow foods in and out.
  2. Must comply with Aus, US & EU standards.
    • Must provide RF seal when shut (no cooking bystanders).
    • Must have double interlock to prevent operation when open.
    • Must be durable and maintain seal through lifespan.
  3. Must indicate when sealed to allow operation.
  4. Must provide mechanism to open/lock.
  5. Should allow viewing of food.

Standards

I was a bit annoyed to discover the US FDA standard Part 1030 in working through the door design. The Australian microwave standards simply specify a maximum allowed external radiation level. The US standards cover the radiation level, door interlocks and also mandate the presence of a user manual, service manual and a pair of warning stickers. The EU standards further proscribe durability tests.

According to a completely reputable source I actually only have to comply with the Australian regulations, if I ship a product to the US then the person buying it is considered the importer and are responsible for the local compliance. This is a touch dodgy, even for me. My plan is to comply and certify with the relevant Australian, US and EU (IEC) standards for a domestic microwave. As most countries have formally harmonized with the IEC standard or based their standard off the US or Europe standards I should actually comply with basically everyone worldwide. I am not going to pay for hundreds of certification marks and the documentation required to make it formal though.

Radiation leakage

All the standards specify limits on radiation leakage. During operation a radiation detector is moved around 5cm from the unit and the level must not exceed 1mW/cm². The areas of concern are any holes in the cavity like air holes or the front viewing panel, any seams to ensure they are welded correctly and my biggest concern is the edge around the sides of the door.

Deliberate holes are the easiest issue to handle. Radiation has a wavelength, for a microwave oven this is roughly 120mm. You can do complex maths around radiation holes by treating them as waveguides but it basically boils down to a 120mm wave needs a 120mm hole. As the hole gets smaller than 120mm you get an exponential drop in the radiation slipping through. Often a hole less than 1/4 or 1/10th of the wavelength is approximated as having zero transmission. My Panasonic microwave has holes of 1mm at the front, 2mm on the top and 3mm on the side, all less than 1/40th of the wavelength. I think the small holes are preferred by the manufacturers for their strength rather than due to radiation concerns.

The microwave radiation cavity is going to be made of several sheets of metal welded together. As radiation can slip out a narrow slit just as happily as a gaping hole care has to be taken at the joins to prevent this. My victim microwaves both put a dent in just before the join to block the radiation from reaching the slit. The spot welds they used also seem to involve indentation which would assist in breaking up any slit, the welds are spaced every 22mm. Dents like that are a bit harder with my manufacturing techniques but are possible, I think this one can be solved in consultation with the manufacturer and a little bit of testing.

Metal plate with a long dent parallel to the edge and a series of weld dents closer to the edge
Panasonic’s RF safe welding join

Panasonic's RF safe welding join

The most concerning issue is the edges of the door. These are nice big slits, just perfect for radiation to spew out of. Looking at the Samsung microwave I think the way this is generally solved is very sneaky and clever. They haven’t followed the obvious solution of trying to create a tight seal, with the Samsung microwave door shut I can see light from a torch shining through, a piece of paper moves without resistance. However if you look closely the aluminium outer frame of the microwave overlaps the door by a few mm. I’ve checked and found this in three microwaves, all different brands. I think what is happening is that the aluminium lip catches the radiation that slips out and limits the amount that gets through. The lip isn’t present on the bottom, so I think they have been differently sneaky there. For the testing of the device it would be reasonable to assume it would be placed a horizontal surface, the manual probably specifies this as the standard operating condition. This position would prevent the detection device being placed 5cm below the microwave door, compliance achieved, problem solved.

Door Interlocks

An interlock is a switch which prevents operation of a device when it is open. For example robots often have a proximity sensor or gate, get too close and the robot immediately shuts down. A common example of this is the automated airport bag drop systems, if you are too close to your bag the conveyor will shut down. Given that a microwave is a touch dangerous it is only sensible that we employ an interlock to prevent operation when the door is open. However US standards require that we take this a fair bit further.

The US Federal Regulations are very specific about what safety interlock must be employed and that special provision must be taken to prevent them from being disabled. Being able to disable an interlock is often a desired feature, the thinking is that if you want to deliberately bypass the safeties then you have chosen to accept the risk and know what you are doing. I assume somebody in the US disabled the interlock on their microwave and got fried, personally I feel they achieved their desired outcome but the regulator obviously felt differently.

The regulations aren’t easy to read, it comes down to this example circuit. Modern microwaves have tweaked it slightly but all follow roughly this pattern. You have three switches, your primary interlock which shuts off power to the system, your secondary or monitor interlock which shorts the unpowered system and a sense switch for the control logic. The combination of these two interlocks means that if either one of them fails or is disabled then the short circuit causes the fuse to blow, as these are small mechanical components this is a common microwave failure point.

There are additional restrictions however, the primary interlock must be designed such that it cannot be deliberately disabled. Specifically a mechanical interlock must be concealed such that it can’t be poked by any body part or straight object, a magnetic interlock can’t be tripped by sticking a magnet against the body of the microwave. Also the primary and monitor interlocks must be mechanically and electrically distinct. The ubiquitous double hook design that every microwave uses makes far more sense with this understanding. A hook is required to meet the concealed requirement and two hooks are required to keep things distinct.

There are opportunities to vary the double hook pattern however. A single hook could be used for the primary interlock with an alternative method used for the other switches. A flexible stick would also meet the criteria if it was guided into a bend. My preference though is for a non-mechanical switch, something more elegant to contrast against the clunky nature of a door. Fortunately there are lots of options. I am leaning towards a magnet despite the restrictions imposed by the standard, I think with a non-magnetic chassis I should be ok as it won’t self-support and there are other ways to skin the cat such as coded magnets.

Durability

The European/International standard is IEC 60335-2-25 ed6.1. I can’t actually find a copy of the document so I might have to buy it. However from the public documentation you can see that it contains the restrictions in the US regulations, with some slight variation, and some additional durability tests. I have found a brief writeup of the durability tests and the news isn’t good. I don’t think passing the tests will be difficult, just need decent hinges. However getting the test house to open and shut the door 100,000 times is going to be expensive. Assuming one second to open the door and one second to close it, that is 56 hours of continuous testing using their 6-DOF robot. The other tests will take another day, this has probably just doubled my testing expenses. I’ll build a basic push/pull robot for my pretesting which could be fun.

Options

Understanding the criteria I now have to design a door.
There are several obvious options, each with their own drawbacks.

I can design a clone of the standard door and make my own. Starting with this one to get it out of the way. The cost of doing this makes it a non-starter. I spoke to the very helpful staff at SK Plastic to understand the costs around injection molding. To build the latch for a microwave door would probably cost roughly $10k-15k for the tool, $1 per part and some other costs for the design and run start etc. At my pricing quantity of 500 units the latch alone would come to roughly $26. The cost of the other larger plastic parts would be higher and the metal screen would either have to be stamped (at least another $10k tooling) or every hold punched individually (several dollars per sheet).

I can buy a door. All the doors are the same, so there is obviously a few companies making these doors. A logical option would be to buy an existing door, either whole or in parts. For example Alibaba has manufacturers offering the door latch, I haven’t enquired as to the price but expect it would be well under $1 per unit. Going half way down this path is difficult, the standard latch means I have to use the matching catches and microswitches with the related durability issues. The latch also dictates the thickness of the door, which pushes again towards plastics as metal would be very heavy. Buying existing outer plastics would result in the microwave having the same appearance as every other microwave, probably looking like the cheap end of the spectrum as that is what is available. Vacuum formed plastic is probably within my price envelope as the setup costs aren’t too bad, I am wary about a heat sensitive plastic in a microwave but apparently PET and HDPE can work.

I can design something new. The big risk here is falling prey to not-invented-here syndrome and a belief that I my design skills are superior to all the major manufacturers combined. However this entire exercise is essentially predicated on that case so I’ll just move on. Doing this will allow me to differentiate the product in a way that is obvious to anyone interacting with it. It will add time and cost to put it all together.

Going forward my plan A is going to be to design from scratch, plan B is to buy in components. Getting half way through a scratch design and then buying in parts where required would probably be a reasonable compromise outcome so blundering forward on my own isn’t a total loss.

Draft design

The modern microwave is almost entirely injection molded plastic and stamped steel, both techniques require mass production I can’t rely on. My manufacturing is primarily orientated around bending sheet metal and for the door, glass.

The preliminary design is for a metal and glass sandwich, in my head it is rather elegant. The layers to the sandwich are a metal inner frame, glass plate, metal RF mesh, glass plate, metal outer frame, some trim. Each glass sheet is 2mm thick, the metal 1mm thick and the RF shield 1mm, so the total thickness is just 7mm compared to my Samsung’s 30mm. Being thin won’t just look awesome, it also helps keep my weight down.

As bonus features I should also be able to get the door to open almost 180 degrees and be able to support left handed doors.

I have envisaged that the sandwich will be assembled and then the two metal sheets spot welded to seal the glass in. Then a trim piece of metal glued on to cover the spot welds and pretty it up.

I am yet to settle on the hinges, latch or interlock mechanisms. At the moment I am thinking of them as accessorising for the door. Realistically some trial and error is going to be required for all three of these areas.

Pencil sketch of the lower right corner of each layer showing their assembly and relative size
Pencil sketch of door sandwich

Pencil sketch of door sandwich

RF Shield

Every microwave I have seen has a solid metal sheet in the front window with circular holes stamped in it. The two microwaves I have measured both have holes roughly 1mm in size. As discussed earlier this is 1/120th of the wavelength and excessively cautious, internal air vent holes are 3mm for example. The pattern is a tradeoff between minimising the metal between the holes, structural strength and ease of cleaning. I think with my door structure the tradeoff isn’t required so I can better optimise the visibility.

A typical guideline for RF shielding is 1/4 of the wavelength allowing holes up to 3cm. Because it is easier to buy I am going to use a square hole, radiation is sneaky and can sneak out on the diagonal so to maintain 1/4 wavelength the square hole must be smaller than 21x21mm.

A wire mesh at 20x20mm is a fairly cheap option and at roughly 75% open area provides better visibility than the existing microwaves. The RF performance will be worse than the existing standard due to the increased hole size and decreased thickness however I think it should be within spec, testing will confirm this before the design is finalised.

Potential suppliers:

If I had sufficient quantity what I really want to do is have a piece of glass manufactured with the metal screen built into the glass. This would significantly reduce complexity by removing the layers and the glass would protect the screen from damage. However doing this would require a special manufacturing rig with associated costs that can only be recovered with large quantities.

Latch

Once closed the door has to stay closed until it is deliberately opened. I have a strong preference for a latch that releases by being pulled on, the push button to open design feels clumsy to me. Again we have options 😃

A hook latch is standard in microwaves. The hook is on the door and hooks into a static hole on the body of the microwave. A spring on the hook keeps it closed until delibrately opened. A slope on the back of the hook allows it to be shut while closed, the hook slides up the latch until it is over then pulls shut. There are two common opening mechanisms, the standard push button works by physically pushing against the hook to raise and released it. The doors you can simply pull open have an oval shaped hook, basically a slope on the inside of the hook allows it to be pulled out much like it is pushed in.

Gravity is an interesting option. By making the door on an angle I can have it naturally sit in the closed position but little force would be required to open it again. This would be cheap but have the downsides of not looking sturdy and not working if the microwave wasn’t flat. Pairing this with a top opening door might work.

Spring loaded hinge is an easy solution. Putting springs into hinge mechanisms is fairly common practice for auto-closing doors, gates or cupboards. The spring hinge can be fitted without much additional work and allows easy operation. I don’t know if an autoclosing door is an advantage or disadvantage.

Magnets are awesome. Magnets are also a possible door latch mechanism, the common stainless steel isn’t magnetic so I would do this by putting a magnet in both the door and body of the microwave. The magnet would help close the door if it was almost closed and keep it closed until tugged open. Best of all I should be able to hide them so it just happens magically.

Closed detection

Both my victim microwaves have three microswitches that get hit by the latch when the door is closed. Two of these are used to implement the standards required interlock system, the third is a low voltage signal to the control circuitry.

The standards require that there be at least two independent detection devices, one of which must be tamper resistant.

Again, there are multiple options.

A hook latch paired with microswitches like every other microwave. Rather boring though.

Directly pushing a microswitch stuck on the surface, probably hiding under a plastic film for cleaning. This is simple, nothing is required on the door and contact is measure directly. It doesn’t meet the tamper resistant requirements but is suitable for a secondary switch.

Magnetic proximity detection works by mounting a permanent magnet on the door and then looking for it. For this to be tamper resistant it can’t be triggered by placing a magnet on the microwave, I think this is free because a stainless steel body shouldn’t be magnetic. This couples nicely with a magnetic closing mechanism.

Light gate detection much like a shop uses a light beam and mirror I can do the same. Requiring a mirror to be mounted on the door fulfills the primary switch requirements. I can probably use polished steel which would be reflective enough to achieve this and with a tiny hole on the body it would be sufficiently magic to be awesome. The downside is that any food or grime that block the mirror would prevent the switch from closing. And being fairly magic like it wouldn’t be obvious which bit of grime was the problem.

A rotation sensor positioned in the hinge would also work. This would complicate the hinge area a bit but would meet all the requirements for the primary switch. One could be placed on the top and bottom to get two independent controls. This would require a microchip for each sensor (ATTiny – yay!) to read the value and control a high voltage relay but we are still in the few dollars price range.

Fifteen Twenty

I am publishing my first WordPress theme, Fifteen Twenty. Born out of frustration at the WordPress theme structure when attempting to update the theme of this blog it demonstrates an alternative. This theme is designed as a technical demonstration of structuring a WordPress theme with a single core layout file. As this is an inversion of the standard structure of the default theme Twenty Fifteen I have dubbed it Fifteen Twenty. The appearance, styling and generated html is the same as the original.

WordPress is an open source blogging platform, it is the most popular blogging platform with over 60 million websites using it. To enable all of these websites WordPress has a theme system which allows the user to radically change the appearance of their blog with just a few clicks. Most of these themes are contributed by users but the WordPress team does release a theme every year, this is the default theme and acts as a best practices template for theme designers. The default themes are named after the year, the current one is Twenty Fifteen.

WordPress themes consist of a collection of php template files. WordPress chooses a template based on the type of content being requested, this allows a different template to be used for search results or an audio attachment. The decision is made using the template hierarchy depicted below. WordPress proceeds from left to right until it finds a file which matches the desired pattern, on the far right index.php acts as a catch all for any file types not specially handled.

The advantage of this structure is that it allows for a huge degree of flexibility in the styling. Any content can have a complete different set of styling provided to it and the hierarchy allows for very specific speciality pages to be created.

The disadvantage is that every template requires a duplication of the site structure. Changes such as reordering the HTML structure require the reworking of every single template file, this was exactly the problem I faced when working on this blog’s template Piano Black.

In practice I feel the theme hierarchy structure is a poor design choice as you want to retain the same look a feel across the entire site. This means that the layout is consistent and the variations are typically isolated to the central content pane. Theme authors attempt to reduce the amount of duplication by using a header and footer file which is pulled into each template, this helps to reduce work for minor changes but makes structural alterations even harder.

The alternative technique is to have a single template file which sets the structure of the website. This file then pulls in partial templates based on the content being requested. The partial templates provide a reduced level of flexibility compared to the full template model but are simpler as they do not need to include as much of the site’s structure. The Twenty Fifteen theme actually uses both full and partial templates, the partial templates are used within the full templates to customise different categories of posts.

I do not mean this as an attack or criticism of the WordPress team, the choice was a trade off and they chose the more flexible approach leading to a product far more successful than any I have ever produced. This choice was also made for the initial release in 2003, a different online environment with alternative aesthetic (MySpace) and less use of javascript. They have made a fantastic product and the flexibility built through it allows for novel uses, like mine.

By removing all the custom template files WordPress will always use index.php as a template. As the template is a full php file it can examine the requested content type and pull in the required partial template. This technique uses the WordPress partial include function which enables sub-themes to customise specific partials.

To demonstrate this layout technique I chose to rework the Twenty Fifteen theme as it is designed as a basis for theme authors to work from, which is also my goal. I took each of the template files and pushed the common elements up to index.php converting them into a partial. The files designed to reduce duplication such as header.php, footer.php and sidebar.php were also pushed into index.php. I then set up a demo site using the wptest.io test data and used wget –mirror, HTML tidy, a tiny bit of sed and diff to beat the last bugs out and ensure that the final result was unchanged from the initial Twenty Fifteen design.

In the future I’ll be releasing my updated version of Piano Black, this blog’s theme, with mobile support (responsive layout) and other modernising updates under the hood. I may also make an AngularJS powered demonstration version of Fifteen Twenty for fun.