Skip to content

Commit

Permalink
Work on indicators; re: #88, #89
Browse files Browse the repository at this point in the history
  • Loading branch information
emxsys committed Aug 28, 2020
1 parent e757ccf commit 508b300
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion callattendant/hardware/indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,6 @@ class MessageCountIndicator(SevenSegmentDisplay):

def __init__(self, *pins, **kwargs):
if len(pins) > 0:
super().__init__(pins, kwargs)
super().__init__(*pins, **kwargs)
else:
super().__init__(*GPIO_MESSAGE_COUNT_PINS, **GPIO_MESSAGE_COUNT_KWARGS)
15 changes: 11 additions & 4 deletions callattendant/messaging/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# SOFTWARE.

import os
import threading
from pprint import pprint
from datetime import datetime

Expand All @@ -40,7 +41,7 @@ def __init__(self, db, config, message_indicator):
self.db = db
self.config = config
self.message_indicator = message_indicator

self.message_event = threading.Event()
# Create the message table if it does not exist
if self.db:
sql = """
Expand Down Expand Up @@ -85,7 +86,9 @@ def add(self, call_no, filepath):
msg_no = curs.fetchone()[0]
curs.close()

self.reset_message_indicator()
self.message_event.set()
self.message_event.clear()
# ~ self.reset_message_indicator()
return msg_no

def delete(self, msg_no):
Expand Down Expand Up @@ -127,7 +130,9 @@ def delete(self, msg_no):
print("Message entry removed")
pprint(arguments)

self.reset_message_indicator()
self.message_event.set()
self.message_event.clear()
# ~ self.reset_message_indicator()

return success

Expand All @@ -145,7 +150,9 @@ def update_played(self, msg_no, played=1):
pprint(e)
return False

self.reset_message_indicator()
self.message_event.set()
self.message_event.clear()
# ~ self.reset_message_indicator()
return True

def get_unplayed_count(self):
Expand Down
32 changes: 29 additions & 3 deletions callattendant/messaging/voicemail.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
# SOFTWARE.

import os
import threading
from datetime import datetime
from messaging.message import Message
from hardware.indicators import MessageIndicator
from hardware.indicators import MessageIndicator, MessageCountIndicator, \
GPIO_MESSAGE, GPIO_MESSAGE_COUNT_PINS, GPIO_MESSAGE_COUNT_KWARGS

class VoiceMail:

Expand All @@ -40,15 +42,29 @@ def __init__(self, db, config, modem):
self.db = db
self.config = config
self.modem = modem
self.message_indicator = MessageIndicator()
self.message_indicator = MessageIndicator(config.get("GPIO_LED_MESSAGE", GPIO_MESSAGE))

pins = config.get("GPIO_LED_MESSAGE_COUNT_PINS", GPIO_MESSAGE_COUNT_PINS)
kwargs = config.get("GPIO_LED_MESSAGE_COUNT_KWARGS", GPIO_MESSAGE_COUNT_KWARGS)
self.message_count_indicator = MessageCountIndicator(*pins, **kwargs)

self.messages = Message(db, config, self.message_indicator)
self.event_thread = threading.Thread(target=self._event_handler)
self.event_thread.name = "modem_call_handler"
self.event_thread.start()

# Pulse the indicator if an unplayed msg is waiting
self.reset_message_indicator()

if self.config["DEBUG"]:
print("VoiceMail initialized")


def _event_handler(self):
while 1:
if self.messages.message_event.wait():
self.reset_message_indicator()

def voice_messaging_menu(self, call_no, caller):
"""
Play a voice message menu and respond to the choices.
Expand Down Expand Up @@ -122,7 +138,17 @@ def delete_message(self, msg_no):
return self.messages.delete(msg_no)

def reset_message_indicator(self):
if self.messages.get_unplayed_count() > 0:
unplayed_count = self.messages.get_unplayed_count()
if unplayed_count > 0:
self.message_indicator.pulse()
if unplayed_count < 10:
self.message_count_indicator.display(unplayed_count)
self.message_count_indicator.decimal_point = False
else:
self.message_count_indicator.display(9)
self.message_count_indicator.decimal_point = True

else:
self.message_indicator.turn_off()
self.message_count_indicator.display(' ')
self.message_count_indicator.decimal_point = False

0 comments on commit 508b300

Please sign in to comment.