Skip to content
Permalink
Browse files

Sounds! And lithium mode

  • Loading branch information
buzzert committed Nov 18, 2019
1 parent 5e1fc28 commit 4450eab0b8c36de468f2274c4b49e27322bfbdeb
@@ -1,19 +1,35 @@
cmake_minimum_required(VERSION 3.0.2)

list(APPEND CMAKE_MODULE_PATH
${CMAKE_SOURCE_DIR}/cmake
)

include(gresource)

project (chipotherm)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")

find_package(PkgConfig REQUIRED)
find_package(Boost REQUIRED)
find_package(Threads REQUIRED)
pkg_check_modules(GIO REQUIRED gio-2.0)

# libtempered options
set(BUILD_STATIC_LIB ON)

pkg_check_modules(HIDAPI REQUIRED hidapi-hidraw)
include_directories(${HIDAPI_INCLUDE_DIRS})

# Resources
GLIB_COMPILE_RESOURCES(GLIB_RESOURCES
SOURCE resources/chipotherm.gresource.xml
)

add_library(resources ${GLIB_RESOURCES})
target_include_directories(resources PUBLIC ${GIO_INCLUDE_DIRS})
target_link_libraries(resources PUBLIC ${GIO_LIBRARIES})

include_directories(subprojects/TEMPered/libtempered)

add_subdirectory(subprojects/bubbles)
@@ -0,0 +1,67 @@
#
# Copyright (C) 2013 Venom authors and contributors
#
# This file is part of Venom.
#
# Venom is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Venom is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Venom. If not, see <http://www.gnu.org/licenses/>.
#

FIND_PROGRAM(GLIB_COMPILE_RESOURCES_EXECUTABLE NAMES glib-compile-resources)
MARK_AS_ADVANCED(GLIB_COMPILE_RESOURCES_EXECUTABLE)

INCLUDE(CMakeParseArguments)

FUNCTION(GLIB_COMPILE_RESOURCES output)
CMAKE_PARSE_ARGUMENTS(ARGS "" "SOURCE" "" ${ARGN})
SET(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
SET(out_files "")

FOREACH(src ${ARGS_SOURCE} ${ARGS_UNPARSED_ARGUMENTS})
SET(in_file "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
GET_FILENAME_COMPONENT(WORKING_DIR ${in_file} PATH)
STRING(REPLACE ".xml" ".c" src ${src})
SET(out_file "${DIRECTORY}/${src}")
GET_FILENAME_COMPONENT(OUPUT_DIR ${out_file} PATH)
FILE(MAKE_DIRECTORY ${OUPUT_DIR})
LIST(APPEND out_files "${DIRECTORY}/${src}")

#FIXME implicit depends currently not working
EXECUTE_PROCESS(
COMMAND
${GLIB_COMPILE_RESOURCES_EXECUTABLE}
"--generate-dependencies"
${in_file}
WORKING_DIRECTORY ${WORKING_DIR}
OUTPUT_VARIABLE in_file_dep
)
STRING(REGEX REPLACE "(\r?\n)" ";" in_file_dep "${in_file_dep}")
SET(in_file_dep_path "")
FOREACH(dep ${in_file_dep})
LIST(APPEND in_file_dep_path "${WORKING_DIR}/${dep}")
ENDFOREACH(dep ${in_file_dep})
ADD_CUSTOM_COMMAND(
OUTPUT ${out_file}
WORKING_DIRECTORY ${WORKING_DIR}
COMMAND
${GLIB_COMPILE_RESOURCES_EXECUTABLE}
ARGS
"--generate-source"
"--target=${out_file}"
${in_file}
DEPENDS
${in_file};${in_file_dep_path}
)
ENDFOREACH(src ${ARGS_SOURCES} ${ARGS_UNPARSED_ARGUMENTS})
SET(${output} ${out_files} PARENT_SCOPE)
ENDFUNCTION(GLIB_COMPILE_RESOURCES)
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/net/buzzert/chipotherm/">
<file>sounds/enable.wav</file>
<file>sounds/disable.wav</file>
<file>sounds/modify.wav</file>
<file>sounds/lithium_on.wav</file>
<file>sounds/lithium_off.wav</file>
</gresource>
</gresources>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,11 +1,12 @@
pkg_check_modules(SOUP REQUIRED libsoup-2.4)
pkg_check_modules(PANGO REQUIRED pangocairo)
pkg_check_modules(HIDAPI REQUIRED hidapi-hidraw)
pkg_check_modules(GLIB2 REQUIRED glib-2.0)
pkg_check_modules(CANBERRA REQUIRED libcanberra)

# Statically link
# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static" CACHE STRING "Set C++ Compiler Flags" FORCE)

add_executable(chipotherm
add_executable(chipotherm
button_actor.cpp
clock_actor.cpp
graph_actor.cpp
@@ -18,21 +19,27 @@ add_executable(chipotherm
remote.cpp
rounded_title_actor.cpp
runloop.cpp
sounds.cpp
utilities.cpp
)

target_include_directories(chipotherm PUBLIC
${SOUP_INCLUDE_DIRS}
${HIDAPI_INCLUDE_DIRS}
${PANGO_INCLUDE_DIRS}
${GLIB2_INCLUDE_DIRS}
${CANBERRA_INCLUDE_DIRS}
bubbles
)

target_link_libraries(chipotherm
${SOUP_LIBRARIES}
${PANGO_LIBRARIES}
${HIDAPI_LIBRARIES}
${GLIB2_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${CANBERRA_LIBRARIES}
resources
bubbles
tempered-static
)
@@ -41,6 +41,12 @@ void ButtonActor::set_label_text(const std::string &str)
_needs_layout = true;
}

void ButtonActor::set_label_font_prop(const std::string &font_prop)
{
_label->set_font_prop(font_prop);
_needs_layout = true;
}

void ButtonActor::layout_actors()
{
Actor::layout_actors();
@@ -20,6 +20,7 @@ class ButtonActor : public Actor
ButtonActor(Rect r);

void set_label_text(const std::string &str);
void set_label_font_prop(const std::string &font_prop);
void set_foreground_color(Color c) { _foreground_color = c; };
void set_highlighted(bool highlighted);
void set_filled(bool filled);
@@ -40,8 +40,36 @@ ActorGridPtr PrimaryScene::initialize_statistics_grid()
grid->set_padding(10.0);

// Clock
auto clock_actor = std::make_shared<ClockActor>(Rect());
grid->stack_actor(clock_actor, 0, 50.0);
//auto clock_actor = std::make_shared<ClockActor>(Rect());
//grid->stack_actor(clock_actor, 0, 50.0);

// Lithium Mode
{
auto lithium_mode_stack = std::make_shared<ActorGrid>(RECT_ZERO, 1);
lithium_mode_stack->set_orientation(ActorGrid::Orientation::HORIZONTAL);
grid->stack_actor(lithium_mode_stack, 0, 50.0);

auto lithium_mode_label = std::make_shared<LabelActor>(RECT_ZERO, " Lithium Mode");
lithium_mode_label->set_font_prop("Karla 10");
lithium_mode_label->set_alignment(PangoAlignment::PANGO_ALIGN_CENTER);
lithium_mode_label->set_foreground_color(Palette::foreground);
lithium_mode_stack->stack_actor(lithium_mode_label, 0);

_lithium_mode_button = std::make_shared<ButtonActor>(RECT_ZERO);
_lithium_mode_button->clicked.connect([this] {
lithium_enabled = !lithium_enabled;
if (lithium_enabled) {
_sounds.play_sound(SoundEngine::Sound::LithiumOn);
} else {
_sounds.play_sound(SoundEngine::Sound::LithiumOff);
}
update_ui_state();
});

_lithium_mode_button->set_foreground_color(Color(0x00, 0xFF, 0x00, 0xFF));
_lithium_mode_button->set_label_font_prop("Karla 12");
lithium_mode_stack->stack_actor(_lithium_mode_button, 0);
}

// Temperatures
{
@@ -86,7 +114,7 @@ ActorGridPtr PrimaryScene::initialize_controls_grid()
_heat_button->set_foreground_color(Color(0xFF, 0x00, 0x00, 0xFF));
_heat_button->clicked.connect([this]() {
bool enabled = _monitor.get_monitoring_enabled();
_monitor.set_monitoring_enabled(!enabled);
user_set_monitoring_enabled(!enabled);
});
grid->stack_actor(_heat_button, 0, 160);
}
@@ -103,6 +131,8 @@ ActorGridPtr PrimaryScene::initialize_controls_grid()
_monitor.set_target_temperature(_monitor.get_target_temperature() - 1);
_target_temp_indicator->flash();
update_ui_state();

_sounds.play_sound(SoundEngine::Sound::Modify);
});
subgrid->stack_actor(minus_button, 0);

@@ -113,6 +143,8 @@ ActorGridPtr PrimaryScene::initialize_controls_grid()
_monitor.set_target_temperature(_monitor.get_target_temperature() + 1);
_target_temp_indicator->flash();
update_ui_state();

_sounds.play_sound(SoundEngine::Sound::Modify);
});
subgrid->stack_actor(plus_button, 0);

@@ -159,7 +191,7 @@ PrimaryScene::PrimaryScene(Rect canvas_rect, bool windowed, double scale, std::s

// Connect signals for remote control
_remote.set_enabled.connect([this](bool enabled) {
_monitor.set_monitoring_enabled(enabled);
user_set_monitoring_enabled(enabled);
});

_remote.set_temperature.connect([this](float temp) {
@@ -183,6 +215,18 @@ PrimaryScene::PrimaryScene(Rect canvas_rect, bool windowed, double scale, std::s
update_ui_state();
}

void PrimaryScene::user_set_monitoring_enabled(bool enabled)
{
_monitor.set_monitoring_enabled(enabled);

// Play sound
if (enabled) {
_sounds.play_sound(SoundEngine::Sound::Enable);
} else {
_sounds.play_sound(SoundEngine::Sound::Disable);
}
}

void PrimaryScene::update()
{
MainScene::update();
@@ -258,4 +302,11 @@ void PrimaryScene::update_ui_state()
_heat_button->set_label_text("ENABLE");
_heat_button->set_filled(false);
}

// Lithium mode
if (lithium_enabled) {
_lithium_mode_button->set_label_text("ON");
} else {
_lithium_mode_button->set_label_text("OFF");
}
}
@@ -15,6 +15,7 @@
#include "remote.h"
#include "rounded_title_actor.h"
#include "qube_actor.h"
#include "sounds.h"

using namespace Bubbles;

@@ -30,6 +31,7 @@ class PrimaryScene : public MainScene
ActorGridPtr initialize_status_grid();
ActorGridPtr initialize_statistics_grid();
ActorGridPtr initialize_controls_grid();
void user_set_monitoring_enabled(bool enabled);

LabelActorPtr _online_label;

@@ -40,6 +42,7 @@ class PrimaryScene : public MainScene
QubeActorPtr _qube;

ButtonActorPtr _heat_button;
ButtonActorPtr _lithium_mode_button;

Remote _remote;

@@ -49,5 +52,9 @@ class PrimaryScene : public MainScene
std::chrono::time_point<Clock> _last_sample_time;
std::chrono::time_point<Clock> _last_graph_update_time;
Monitor _monitor;

SoundEngine _sounds;

bool lithium_enabled;
};

0 comments on commit 4450eab

Please sign in to comment.
You can’t perform that action at this time.