<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pl-pl">
<link rel="self" type="application/atom+xml" href="https://forum.atnel.pl/feed.php?f=4&amp;t=5885&amp;mode" />

<title>ATNEL tech-forum</title>
<link href="https://forum.atnel.pl/index.php" />
<updated>2014-02-08T09:50:36+01:00</updated>

<author><name><![CDATA[ATNEL tech-forum]]></name></author>
<id>https://forum.atnel.pl/feed.php?f=4&amp;t=5885&amp;mode</id>
<entry>
<author><name><![CDATA[rolba]]></name></author>
<updated>2014-02-08T09:50:36+01:00</updated>
<published>2014-02-08T09:50:36+01:00</published>
<id>https://forum.atnel.pl/viewtopic.php?t=5885&amp;p=69211#p69211</id>
<link href="https://forum.atnel.pl/viewtopic.php?t=5885&amp;p=69211#p69211"/>
<title type="html"><![CDATA[Obsługa klawisza - przeróbka SuperDebounce.]]></title>

<content type="html" xml:base="https://forum.atnel.pl/viewtopic.php?t=5885&amp;p=69211#p69211"><![CDATA[
Cześć.<br /><br />Przerobiłem funkcję SuperDebounce do swoich potrzeb.<br />[syntax=c]enum {ev_key_noaction, ev_key_pressed};[/syntax]<br />[syntax=c]int keyProcess(volatile uint8_t *keyPin, uint8_t keyMask) {<br />enum keyStates {<br />idle, debounce, pressed, stillPressed<br />};<br /><br />static enum keyStates keyState;<br /><br />static uint8_t lastKey;         // remembered last pressed key to prevent from prssing two keys at one time<br />uint8_t keyPressed; // buffor key state<br /><br />keyPressed = !(*keyPin &amp; keyMask); // get key value<br /><br />if (lastKey &amp;&amp; lastKey != keyMask) {         // if last pressed key is not equal to actually pressed - return<br />return ev_key_noaction;<br />}<br /><br />switch (keyState) {<br />case idle: // idle state, from here state machine will only go if key was pressed<br />if (keyPressed) { // if key was pressed<br />keyTimer = 5; //set debounce time 5 x 10ms<br />keyState = debounce; // change state for doebounce<br />}<br />break;<br />case debounce: // this will be entered till debounce time expires and key is still pressed<br />if (keyPressed &amp;&amp; !keyTimer) { // if debounce time expired and still pressed<br />keyState = pressed; // change state to key-pressed postprocessing<br />lastKey = keyMask; // remember last pressed key<br />}<br />break;<br />case pressed: // key is pressed<br />if (lastKey != keyPressed) {<br />keyState = stillPressed;<br />}<br />break;<br />case stillPressed: // this prevent from repeating events. If key is released than function will go to idle state<br />if (!keyPressed) {<br />lastKey = 0;<br />keyState = idle;<br />return ev_key_pressed;<br />}<br />break;<br />}<br />return ev_key_noaction;<br />}[/syntax]<br /><br />Na koniec rzucam pytanie dla dociekliwych: &quot;Co i w jakich sytuacjach będzie wykonywać się szybciej. Moja funkcja, czy SuperDebounce o takiej samej funkcjonalności?&quot;. Ja swoja opinię mam, ale nie chcę nic sugerować, a bardzo chętnie podejmę dyskusję <img src="https://forum.atnel.pl/images/smilies/icon_e_smile.gif" alt=":)" title="Szczęśliwy" />.<br /><br />Miłej soboty.<br /><br />*Edit.<br />Jak zrobić by komentarze w kodzie publikowanym w znacznikach syntax były tak samo równo jak w eclipse? Ustawić tabulaturę zamiast spacji dla wcięć?<p>Statystyki: Napisane przez <a href="https://forum.atnel.pl/memberlist.php?mode=viewprofile&amp;u=958">rolba</a> — 8 lut 2014, o 09:50</p><hr />
]]></content>
</entry>
</feed>