Many IF statements alternative

Go To Last Post
64 posts / 0 new

Pages

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You know,  In the day where an "analyst" handed a flow-chart off to a "coder" for actual implementation, the multi-way choice might have been shown something like:

 

leaving it up to the coder to figure out whether they should use multiple "if/else" statements, "case" statements, whether they needed string comparisons, "approximate comparisons", and many other decisions.  Hopefully that would result in an efficient and maintainable implementation of the original flowchart.  And it could be a source of many errors.

 

That "maintainable" part is pretty important.   It's pretty common that you'd give up "maximum speed" to have a nice table where you can tell what's happening at a glance:

 

const command_ptr_t commands[] = {
  { 'a', a_function },
  { 'b', b_function },
  { '1', number_function },
  { '0', number_function },
     :
  { RUBOUT, delet_function },
  { '\r', newline_function }
};

Looping through that array and calling functions via the pointers isn't that much slower than a string of if/else statements, and it's a lot easier to understand.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:
I envisioned the old unit as having an interrupt driven U.I. Hit the Add 30 Seconds button and the countdown timer is instantly updated. The new UI plods along, slow as can be, eventually reading the keyboard and processing the command.

I disagree.  You probably cannot press the button and get a response faster than say 10x/second.  Give you the benefit of the doubt and say you are aiming at 25x?  That still gives you 40ms for debounce of each press and be able to "keep up".  (well, 20ms press; 20ms release)  3x of 5ms should work fine.

 

If you really want to do keypressing interrupt-driven, then if you have no debouncing you are going to get multiple hits.  The simplest is to space out the "hit actions.  So how far are you going to space them out, and how?  The naive hard delay in the interrupt routine has many more drawbacks IMO/IME than the few microseconds for fetch/debounce every few milliseconds.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was thinking "interrupt driven" more in a generic sense, with the difficulty of drawing an "exact" flow chart when you have interrupts occurring.

(Personally, I just draw it as a separate ISR flowchart.)

 

I totally agree edge or level driven interrupts for a keypad are doable, but more problematic than a simple CTC interrupt every X mSec and reading the status.

 

On my new microwave, who knows how the code is actually written.

I just know that I use to be able to press it twice for 1 min, or 3 times for 1.5 mins, and be done with it.

Now I have to wait what seems like forever before it will read a sequential press.

Well past, IMHO, debounce time.

 

Oh well.

There are clearly bigger issues in the world today, but the preceding comments reminded me of my irritation with the device.

 

JC

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:
Well past, IMHO, debounce time.

Exactly.  The gurus doing your problem firmware used interrupt-driven press processing 'cause the pointy-haired bosses were told that it would be a "good thing" to have INSTANT response to a press.  Now, when the competent developers pointed out that that wouldn't be a good idea, they were told in no uncertain terms to implement that way. Protests about bouncing were pushed aside; the "solution" was to put a long delay in the ISR to "cure" the bouncing.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

On my new microwave, who knows how the code is actually written.

I would recommend my microwave to you (except it is unlikely sold in the US) as it has an encoder wheel but one that also has a central "click" and each click is +30s. HOWEVER if, as you click (which of all the buttons and knobs ends up being about the only thing we ever do) you inadvertently rotate the encoder wheel just one detent anti-clockwise the timing switches to an instant maximum of 90 minutes.

 

Now I do kind of wonder if anyone, anywhere on planet earth has ever run any microwave for an hour and a half?!?! You have to wonder how the programmer of the thing made it so easy to make such a (potentially dangerous) mistake on the part of the user? I think a bit like bath taps where you have to depress a button to get from "normal" heat range to "scalding hot" there should be some kind of safety guard on something like a microwave that makes it very difficult to set it for any duration above about (say) 20 minutes.

Last Edited: Mon. Aug 6, 2018 - 06:12 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This thread seems to have migrated to "How electronics should work" from the original topic. So...

 

My old microwave had an increment by 30sec button (and a decrement by 10sec button) which made it easy for quickly adding a few seconds to the heat cycle. The new model just has an increment by 1minute button. It also has a "DEC" button that actually resets the time to zero?

 

To change the power level on the old unit, yo pressed the power button and then one of the number buttons 1-9 to set the level. So "Power", "5" was 50%.

The new model requires you to press the "Power" button 6 times to get 50% power! First press says "Hey we're gonna change power, set it for 100%." Each subsequent press decrements the level by 10%.

 

Did the guys building this ever use it?

 

And don't get my wife started on the idiotic controls of the washing machine...

 

 

 

David (aka frog_jr)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

My samsung fridge has a demo mode that a guest, leaning on the control panel, managed to trigger. It took me quite a while to figure out WTH had happened to it. Now I'm tempted to got to peoples houses and do it as a prank...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

OK, so can I vent about another user interface on a home appliance?

 

We have a dish washer in the kitchen that is located under a counter, near the sink.

 

It has 12-15 push buttons across the front panel, (a single horizontal row across the front of the device).

 

What they are is written in a small font, and the front of the appliance is vertically oriented, not tilted up to read it.

 

Every time I want to turn it on I have to bend over and read the small fonts to push the wash mode and then the start button.

 

I'd put a big colorful mark on them, but I'm afraid my wife wouldn't like that option.

 

JC

 

Edit:

OK, so I'll admit, bending over to read the controls is a small price to pay so as not to have to wash and dry all of the dishes myself...

 

But really, how hard would it have been to have the control panel tilted upwards?

 

JC

Last Edited: Mon. Aug 6, 2018 - 09:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ok you probably don't microwave for 90 min (my timer has max of 95 minutes ) but if you use it as a oven it could be needed.  

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Our answering machine (from the old "big name"  in US phones) is annoying...you can only delete a message while its playing...once it ends you cannot.  Except it is hard to know when the message is over..so it suddenly ends & then you can't delete it.

Before you can replay the messages (to delete them), you must also first listen to it tell you (again) that "you have 1 new message and 5 old messages".

 

 

When in the dark remember-the future looks brighter than ever.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Whenever my compilier runs out of "if"s I grab a big paper bag and go down to the local university.  The students are all budding narcissists and seem to have an endless supply of 'I's.  I have a little machine that scrapes all the 'f's from the beginning of all "f-words" that the young people throw around with complete abandon. 

 

  I put all the 'I's and 'f's in the bag and shake them up.  About half of them come out as usable 'if's.  The 'fi's I graciously donate to anyone who (for any reason) can't count above four.  At least now they can count up to 'fi', which is a great help in today's complex world.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

sparrow2 wrote:
but if you use it as a oven it could be needed.
Except our one isn't a "combi". It's just a straight microwave - no "oven" functionality.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:
I put all the 'I's and 'f's in the bag and shake them up.  About half of them come out as usable 'if's.  The 'fi's I graciously donate to anyone who (for any reason) can't count above four.  At least now they can count up to 'fi', which is a great help in today's complex world
Sell the fi's to shell scripters.  They use them to terminate if's. 

"SCSI is NOT magic. There are *fundamental technical
reasons* why it is necessary to sacrifice a young
goat to your SCSI chain now and then." -- John Woods

Pages