Programs within programs...
Sounds a bit like scripting to me!
Well, it may do and if you mention scripting on the forums you'll run into a number of suggestions for scripting engines. But what if you don't need the full on complexity of a scripting engine? What if you just want simple things?
As an example, consider this... I was asked by a former employer if I could re-engineer one of his products. This particular product was a card vendor and it was beginning to suffer the effects of parts obsolescence caused by legislation such as RoHS. So I took one of these units, took it apart and reverse engineered the schematics from the PCB and then set about updating it to use modern variants of the components it had been using.
One thing that struck me was that if you consider a simple device such as a card vendor, there can actually be quite a lot of conditions that you may want to feedback to the user. For example:- Cards low, cards empty, card jam, feed jam, initializing, unrecoverable error, waiting for card to be taken, ready, vending. The units had a single LED opening in the case which was injection moulded so I had no option to add more LEDs, plus adding more LEDs would have required me to increase the component count and thus increase costs.
So, I decided I would use a two colour light emitting diode. Put the power on one way and get a green light, power on the other, get a red light, and if you're brave switch them back and forth and get a vague representation of yellow or orange.
That's four states... off, green, red, muddy yellow/orange.
OK I thought to myself, I can work with that, I'll just flash the light at different speeds.... solid green means it's OK, green flashing slowly means it's vending... you get the picture. I sat down with the C compiler I use for PIC development and wrote some code that would do this and to my horror when it was compiled it used something like 300 words of program memory.
If you're not familiar with PIC micro-controllers, they are tiny beasts, the one I was using had, if memory serves, something like 8 thousand program words available and my first crack at providing more feedback to the users had consumed nearly 4% of the available program space. I wracked my brain trying to come up with a solution to this problem and despite my best efforts after several days of thinking I was just not able to improve upon my appalling solution.
vBulletin Message