Skip to content

Commit

Permalink
Made blinking consistently end with starting color.
Browse files Browse the repository at this point in the history
  • Loading branch information
speratus committed Nov 11, 2019
1 parent 6dc78c6 commit 3f1315b
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion blinkter/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from copy import deepcopy
from blinkter import Pixel

import threading
import time

##from .pixel import Pixel


class FlashThread(threading.Thread):

def __init__(self, pixel, length: float):
Expand All @@ -37,9 +41,10 @@ def run(self):
self.pixel.revert_color()
self.pixel.draw()


class BlinkThread(threading.Thread):

def __init__(self, pixel, interval: float, duration: float):
def __init__(self, pixel: Pixel, interval: float, duration: float):
super().__init__()
self.pixel = pixel
self.interval = interval
Expand All @@ -51,6 +56,7 @@ def stop(self):

def run(self):
elapsed_time = 0.0
first_color = deepcopy(self.pixel.orgb)
while self.running:
s_time = time.process_time()

Expand All @@ -70,6 +76,9 @@ def run(self):
self.pixel.revert_color()
break

self.pixel.set_color(first_color[0], first_color[1], first_color[2])


class AdvancedBlinkThread(threading.Thread):
def __init__(self, pixel, on_length: float, off_length: float):
super().__init__()
Expand All @@ -82,6 +91,7 @@ def stop(self):
self.running = False

def run(self):
first_color = deepcopy(self.pixel.orgb)
while self.running:
time.sleep(self.on_time)

Expand All @@ -90,3 +100,5 @@ def run(self):
time.sleep(self.off_time)

self.pixel.revert_color()

self.pixel.set_color(first_color[0], first_color[1], first_color[2])

0 comments on commit 3f1315b

Please sign in to comment.