Skip to content

Commit

Permalink
Merge pull request #48 from kaulketh/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
kaulketh authored Feb 13, 2019
2 parents 2525bd6 + a18b789 commit 2ac65ed
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 38 deletions.
2 changes: 1 addition & 1 deletion bot/conf/greenhouse_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
language settings
import required lib
set index in global library
"""
"""
if language_index == 0:
import conf.lib_english as lib
elif language_index == 1:
Expand Down
1 change: 1 addition & 0 deletions bot/conf/lib_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
file_log_greenhouse = '/greenhouse.log'
file_log_debug = '/greenhouse_console.log'
file_log_update = '/update_bot.log'
latest_release = '/greenhouseLatestRelease.id'
commit_id = '/greenhouseRepoCommit.id'
cloned_branch = '/greenhouseRepoBranch.name'
bot_dir = '/home/pi/scripts/TelegramBot/'
Expand Down
25 changes: 8 additions & 17 deletions bot/greenhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __start(bot, update):
return SELECTION


""" set the target, member of group or group """
# set the target, member of group or group
def __selection(bot, update):
global target
target = update.message.text
Expand Down Expand Up @@ -140,7 +140,7 @@ def __selection(bot, update):
return DURATION


""" set water duration """
# set water duration
def __duration(bot, update):
global water_time
global g_duration_update
Expand Down Expand Up @@ -236,7 +236,7 @@ def __duration(bot, update):
return SELECTION


""" watering targets """
# watering targets
def __all_off():
logging.info('Switch all off.')
for channel in all_groups:
Expand Down Expand Up @@ -308,9 +308,7 @@ def __water_group(bot, update, group):
return


"""
get humidity and temperature values
"""
# get humidity and temperature values
def __message_values(update):
""" to avoid refresh intervals shorter than 3 seconds """
time.sleep(3)
Expand Down Expand Up @@ -345,10 +343,8 @@ def __stop(bot, update):
display.show_standby()
return ConversationHandler.END


"""
[#39] Implement emergency stop
"""

# [#39] Implement emergency stop
@run_async
def __emergency_stop_handler(bot, update, chat_data):
emergency = update.message.text
Expand All @@ -366,10 +362,7 @@ def __start_emergency_stop(bot, update):
return


"""
[#30] implement standby
init after given time without user activity
"""
# [#30] implement standby init after given time without user activity
def __start_standby_timer(bot, update):
global timer_job
timer_job = jq.run_once(__job_stop_and_restart, conf.standby_timeout, context=update)
Expand All @@ -383,9 +376,7 @@ def __stop_standby_timer(bot, upadate):
return


"""
job to stop and restart application
"""
# job to stop and restart application
def __job_stop_and_restart(bot, job):
logging.warning("Job: Stop and restart called!")
stop_and_restart.stop_and_restart(job.context)
Expand Down
5 changes: 2 additions & 3 deletions bot/peripherals/four_digit/four_digits.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import logger.logger as log
logger = log.get_logger()

""" http://www.uize.com/examples/seven-segment-display.html """
# http://www.uize.com/examples/seven-segment-display.html
# 0 1 2 3 4 5 6 7 8 9
hex_digits = [0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f,
# A b C d E F G H h I
Expand All @@ -39,8 +39,7 @@


class TM1637:
logger.info('Init pin settings for 4-digit-display!')
global IO
logger.info('Init pin settings four digits display!')
IO = utils.set_pins()
__double_point = False
__clk_pin = 0
Expand Down
48 changes: 33 additions & 15 deletions bot/peripherals/oled/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,20 @@
author: Thomas Kaulke, [email protected]
"""

# TODO: improve and fix imports, load vars from global lib!!!
# from __future__ import absolute_import
# import conf.lib_global as lib
import subprocess
from time import sleep
from PIL import Image, ImageFont, ImageDraw
from lib_oled96 import Ssd1306
from smbus import SMBus
from ...conf.lib_global import commit_id, cloned_branch, bot_dir
from lib_oled96 import Ssd1306


latest_release = '/greenhouseLatestRelease.id'
commit_id = '/greenhouseRepoCommit.id'
cloned_branch = '/greenhouseRepoBranch.name'
bot_dir = '/home/pi/scripts/TelegramBot/'


# Display setup, methods and members
Expand All @@ -24,10 +32,20 @@
switch_time = 15


def get_last_commit():
commit = None
branch = None
def __get_release():
try:
release = open(str(latest_release)).read()
if release is None:
release = '-----'
else:
release = release
except Exception:
release = '-----'
return release
return release


def __get_last_commit():
try:
commit = open(str(commit_id)).read()
if commit is None:
Expand All @@ -47,7 +65,7 @@ def get_last_commit():
return build


def get_core_temp():
def __get_core_temp():
temp = int(open('/sys/class/thermal/thermal_zone0/temp').read())
one = str(temp).__getitem__(0)
two = str(temp).__getitem__(1)
Expand All @@ -60,23 +78,23 @@ def get_core_temp():
font2 = ImageFont.truetype(str(bot_dir) + 'peripherals/oled/fonts/FreeSans.ttf', 12)


def animate(time):
def __animate(time):
# Display clear
oled.cls()
oled.display()
# header
draw.text((18, top), "GREENHOUSE", font=font, fill=1)
draw.text((left, top), "GREENHOUSE v" + __get_release(), font=font, fill=1)
# build
draw.text((left, top + 18), "Build: " + get_last_commit(), font=font2, fill=1)
draw.text((left, top + 18), "Build: " + __get_last_commit(), font=font2, fill=1)
# line
draw.line((left, top + 35, oled.width - left + 128, top + 35), fill=1)
# core temp
draw.text((left, top + 45), "Core Temperature: " + get_core_temp(), font=font2, fill=1)
draw.text((left, top + 45), "Core Temperature: " + __get_core_temp(), font=font2, fill=1)
oled.display()
sleep(time)


def show_pi(time):
def __show_pi(time):
oled.cls()
# image inverted
draw.rectangle((32, top - 3, 95, 63), outline=1, fill=1)
Expand All @@ -85,7 +103,7 @@ def show_pi(time):
sleep(time)


def show_state(time):
def __show_state(time):
oled.cls()
oled.display()
"""
Expand Down Expand Up @@ -116,9 +134,9 @@ def show_state(time):
while True:

try:
animate(switch_time)
show_pi(3)
show_state(switch_time)
__animate(switch_time)
__show_pi(3)
__show_state(switch_time)

except KeyboardInterrupt:
print('Oled interrupted.')
Expand Down
3 changes: 1 addition & 2 deletions bot/peripherals/oled/lib_oled96.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
minor adaptions: Thomas Kaulke, [email protected]
"""

from __future__ import absolute_import
from PIL import Image, ImageDraw


Expand Down Expand Up @@ -103,7 +102,7 @@ def display(self):
buf.append(byte)
i -= 1

self._data(buf) # push out the whole lot
self._data(buf) # push out the whole lot

def cls(self):
self.canvas.rectangle((0, 0, self.width-1, self.height-1), outline=0, fill=0)
Expand Down
4 changes: 4 additions & 0 deletions bot/update_bot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ log='/update_bot.log'
commit_id='/greenhouseRepoCommit.id'
cloned_branch='/greenhouseRepoBranch.name'
bot_dir='/home/pi/scripts/TelegramBot/'
latest_release='/greenhouseLatestRelease.id'
wait=3

# function display usage
Expand Down Expand Up @@ -47,6 +48,9 @@ fi
commit=$(curl -s https://api.github.com/repos/${owner}/${project}/commits/${branch} --insecure | grep -Po '(?<="sha":)(.*?)(?=,)' -m 1 | sed "s/\"//g" | sed -e 's/^[[:space:]]*//' | sed -e 's/[.]*$//')
# get saved commit
last_commit=$(cat ${commit_id})
#get latest release
release=$(curl -s https://api.github.com/repos/${owner}/${project}/releases/latest --insecure| grep -Po '"tag_name": "\K.*?(?=")')
echo ${release} > ${latest_release}


# all output to log file
Expand Down

0 comments on commit 2ac65ed

Please sign in to comment.