Skip to content

Commit

Permalink
Merge pull request #36 from manexim/develop
Browse files Browse the repository at this point in the history
Release version 0.5.0
  • Loading branch information
meisenzahl authored Nov 3, 2019
2 parents 547ed28 + 7c19eea commit 7ae51cf
Show file tree
Hide file tree
Showing 23 changed files with 531 additions and 121 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: CI

on: [push, pull_request]

jobs:
lint:

runs-on: ubuntu-latest

container:
image: valalang/lint

steps:
- uses: actions/checkout@v1
- name: Lint
run: io.elementary.vala-lint -d .
24 changes: 24 additions & 0 deletions data/com.github.manexim.home.appdata.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,30 @@
<binary>com.github.manexim.home</binary>
</provides>
​<releases>
<release date="2019-11-03" version="0.5.0">
<description>
<p>New:</p>
<ul>
<li>Use color picker to set color of smart bulbs</li>
</ul>
<p>Improved:</p>
<ul>
<li>Show an error page if network is not available</li>
</ul>
<p>Fixed:</p>
<ul>
</ul>
<p>Translations:</p>
<ul>
<li>Russian (by camellan)</li>
<li>French (by NathanBnm)</li>
<li>German (by meisenzahl)</li>
<li>Japanese (by ryonakano)</li>
<li>Portuguese (by aimproxy)</li>
<li>Polish (by oskarkunik)</li>
</ul>
</description>
</release>
<release date="2019-08-07" version="0.4.2">
<description>
<p>New:</p>
Expand Down
17 changes: 17 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
com.github.manexim.home (0.5.0) bionic; urgency=medium

[NEW]
* Use color picker to set color of smart bulbs
[IMPROVED]
* Show an error page if network is not available
[FIXED]
[TRANSLATIONS]
* Russian (by camellan)
* French (by NathanBnm)
* German (by meisenzahl)
* Japanese (by ryonakano)
* Portuguese (by aimproxy)
* Polish (by oskarkunik)

-- Marius Meisenzahl <[email protected]> Sun, 03 Nov 2019 14:24:03 +0100

com.github.manexim.home (0.4.2) bionic; urgency=medium

[NEW]
Expand Down
4 changes: 3 additions & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public class Application : Granite.Application {

var css_provider = new Gtk.CssProvider ();
css_provider.load_from_resource ("com/github/manexim/home/styles/application.css");
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
Gtk.StyleContext.add_provider_for_screen (
Gdk.Screen.get_default (), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
);
}

public static int main (string[] args) {
Expand Down
70 changes: 69 additions & 1 deletion src/colors/HSB.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,72 @@
* Authored by: Marius Meisenzahl <[email protected]>
*/

public class Colors.HSB {}
public class Colors.HSB {
public uint16 hue;
public uint8 saturation;
public uint8 brightness;

public HSB () {}

public HSB.from_rgb (RGB rgb) {
double min, max, delta;
double h, s, b;

double red = rgb.red / 255.0;
double green = rgb.green / 255.0;
double blue = rgb.blue / 255.0;

min = red;
min = green < min ? green : min;
min = blue < min ? blue : min;

max = red;
max = green > max ? green : max;
max = blue > max ? blue : max;

b = max;
delta = max - min;

if (max != 0) {
s = delta / max;
} else {
s = 0;
h = 0;

hue = (uint16) (h + 0.5);
saturation = (uint8) (s * 100 + 0.5);
brightness = (uint8) (b * 100 + 0.5);

return;
}

if (max == min) {
h = 0;
s = 0;

hue = (uint16) (h + 0.5);
saturation = (uint8) (s * 100 + 0.5);
brightness = (uint8) (b * 100 + 0.5);

return;
}

if (red == max) {
h = (green - blue) / delta;
} else if (green == max) {
h = 2 + (blue - red) / delta;
} else {
h = 4 + (red - green) / delta;
}

h *= 60;

if (h < 0) {
h += 360;
}

hue = (uint16) (h + 0.5);
saturation = (uint8) (s * 100 + 0.5);
brightness = (uint8) (b * 100 + 0.5);
}
}
71 changes: 71 additions & 0 deletions src/colors/RGB.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,75 @@ public class Colors.RGB {
public RGB.from_hex (string hex) {
hex.scanf ("%02x%02x%02x", &red, &green, &blue);
}

public RGB.from_hsb (HSB hsb) {
int i;
double f, p, q, t;
double r, g, b;

double hue, saturation, brightness;
hue = (double) hsb.hue;
saturation = (double) (hsb.saturation / 100.0);
brightness = (double) (hsb.brightness / 100.0);

if (saturation == 0) {
r = brightness;
g = brightness;
b = brightness;

red = (uint8) (r * 255 + 0.5);
green = (uint8) (g * 255 + 0.5);
blue = (uint8) (b * 255 + 0.5);

return;
}

hue /= 60;
i = (int) hue;
f = hue - i;
p = brightness * (1 - saturation);
q = brightness * (1 - saturation * f);
t = brightness * (1 - saturation * (1 - f));

switch (i) {
case 0:
r = brightness;
g = t;
b = p;
break;
case 1:
r = q;
g = brightness;
b = p;
break;
case 2:
r = p;
g = brightness;
b = t;
break;
case 3:
r = p;
g = q;
b = brightness;
break;
case 4:
r = t;
g = p;
b = brightness;
break;
default:
r = brightness;
g = p;
b = q;
break;
}

red = (uint8) (r * 255 + 0.5);
green = (uint8) (g * 255 + 0.5);
blue = (uint8) (b * 255 + 0.5);
}

public string to_hex () {
return "#%02x%02x%02x".printf (red, green, blue);
}
}
2 changes: 1 addition & 1 deletion src/config/Constants.vala
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ namespace Config {
public const string APP_ID = "com.github.manexim.home";
public const string APP_AUTHOR = "Manexim";
public const string APP_NAME = "Home";
public const string APP_VERSION = "0.4.2";
public const string APP_VERSION = "0.5.0";
}
2 changes: 2 additions & 0 deletions src/controllers/DeviceController.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public abstract class Controllers.DeviceController : Object {

public abstract void switch_brightness (uint16 brightness);

public abstract void switch_hsb (uint16 hue, uint16 saturation, uint16 brightness);

public abstract void switch_color_temperature (uint16 color_temperature);

public abstract void switch_power (bool on);
Expand Down
9 changes: 9 additions & 0 deletions src/lifx/Controller.vala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public class Lifx.Controller : Controllers.DeviceController {
lamp.brightness = brightness;
}

public override void switch_hsb (uint16 hue, uint16 saturation, uint16 brightness) {
var lamp = device as Lifx.Lamp;
service.set_color (lamp, hue, saturation, brightness, 0, 0);

lamp.hue = hue;
lamp.saturation = saturation;
lamp.brightness = brightness;
}

public override void switch_color_temperature (uint16 color_temperature) {
var lamp = device as Lifx.Lamp;
service.set_color (lamp, 0, 0, lamp.brightness, color_temperature, 0);
Expand Down
44 changes: 22 additions & 22 deletions src/lifx/Packet.vala
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,26 @@ public class Lifx.Packet {

// payload
payload = new Json.Object ();
const uint8 i = 36;
const uint8 INDEX = 36;

switch (type) {
case 3: // StateService
payload.set_int_member ("service", buffer.read_uint8 (i));
payload.set_int_member ("port", buffer.read_uint32_le (i + 1));
payload.set_int_member ("service", buffer.read_uint8 (INDEX));
payload.set_int_member ("port", buffer.read_uint32_le (INDEX + 1));
break;
case 13: // StateHostInfo
payload.set_double_member ("signal", buffer.read_float_le (i));
payload.set_int_member ("tx", buffer.read_uint32_le (i + 4));
payload.set_int_member ("rx", buffer.read_uint32_le (i + 8));
payload.set_double_member ("signal", buffer.read_float_le (INDEX));
payload.set_int_member ("tx", buffer.read_uint32_le (INDEX + 4));
payload.set_int_member ("rx", buffer.read_uint32_le (INDEX + 8));
break;
case 15: // StateHostFirmware
payload.set_double_member ("signal", buffer.read_float_le (i));
payload.set_int_member ("tx", buffer.read_uint32_le (i + 4));
payload.set_int_member ("rx", buffer.read_uint32_le (i + 8));
payload.set_double_member ("signal", buffer.read_float_le (INDEX));
payload.set_int_member ("tx", buffer.read_uint32_le (INDEX + 4));
payload.set_int_member ("rx", buffer.read_uint32_le (INDEX + 8));
break;
case 22: // StatePower
Types.Power power = Types.Power.UNKNOWN;
uint16 power_t = buffer.read_uint16_le (i);
uint16 power_t = buffer.read_uint16_le (INDEX);
if (power_t > 0) {
power = Types.Power.ON;
} else if (power_t == 0) {
Expand All @@ -102,10 +102,10 @@ public class Lifx.Packet {
payload.set_int_member ("level", power);
break;
case 25: // StateLabel
payload.set_string_member ("label", (string) buffer.slice (i, i + 32).raw);
payload.set_string_member ("label", (string) buffer.slice (INDEX, INDEX + 32).raw);
break;
case 33: // StateVersion
uint32 product = buffer.read_uint32_le (i + 4);
uint32 product = buffer.read_uint32_le (INDEX + 4);
string model = "";
bool supports_color = false;
bool supports_infrared = false;
Expand Down Expand Up @@ -255,26 +255,26 @@ public class Lifx.Packet {
payload.set_boolean_member ("supportsMultizone", supports_multizone);
break;
case 107: // State
payload.set_int_member ("hue", buffer.read_uint16_le (i));
payload.set_int_member ("saturation", buffer.read_uint16_le (i + 2));
payload.set_int_member ("brightness", buffer.read_uint16_le (i + 4));
payload.set_int_member ("kelvin", buffer.read_uint16_le (i + 6));
payload.set_int_member ("hue", buffer.read_uint16_le (INDEX));
payload.set_int_member ("saturation", buffer.read_uint16_le (INDEX + 2));
payload.set_int_member ("brightness", buffer.read_uint16_le (INDEX + 4));
payload.set_int_member ("kelvin", buffer.read_uint16_le (INDEX + 6));

// power
Types.Power power = Types.Power.UNKNOWN;
uint16 power_t = buffer.read_uint16_le (i + 10);
uint16 power_t = buffer.read_uint16_le (INDEX + 10);
if (power_t > 0) {
power = Types.Power.ON;
} else if (power_t == 0) {
power = Types.Power.OFF;
}
payload.set_int_member ("power", power);

payload.set_string_member ("label", (string) buffer.slice (i + 12, i + 44).raw);
payload.set_string_member ("label", (string) buffer.slice (INDEX + 12, INDEX + 44).raw);
break;
case 118: // StatePower
Types.Power power = Types.Power.UNKNOWN;
uint16 power_t = buffer.read_uint16_le (i);
uint16 power_t = buffer.read_uint16_le (INDEX);
if (power_t > 0) {
power = Types.Power.ON;
} else if (power_t == 0) {
Expand All @@ -284,7 +284,7 @@ public class Lifx.Packet {
break;
default:
var a = new Json.Array ();
var raw = buffer.slice (i, (uint8) size).raw;
var raw = buffer.slice (INDEX, (uint8) size).raw;

for (uint8 j = 0; j < raw.length; j++) {
a.add_int_element (raw[j]);
Expand Down Expand Up @@ -326,11 +326,11 @@ public class Lifx.Packet {
// frame address
Buffer buf2 = new Buffer.alloc (16);
for (uint8 i = 0; i < 8; i++) {
buf2.write_uint8(target_parts[i], i);
buf2.write_uint8 (target_parts[i], i);
}

// header
Buffer buf3 = new Buffer.alloc(12);
Buffer buf3 = new Buffer.alloc (12);
buf3.write_uint16_le (type, 8);

uint8 byte14 = (ack_required << 1) | res_required;
Expand Down
8 changes: 5 additions & 3 deletions src/lifx/Service.vala
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public class Lifx.Service {
}
}

public void set_color (Lifx.Lamp lamp, uint16 hue, uint16 saturation, uint16 brightness, uint16 kelvin, uint32 duration=0) {
public void set_color (
Lifx.Lamp lamp, uint16 hue, uint16 saturation, uint16 brightness, uint16 kelvin, uint32 duration=0
) {
var packet = new Lifx.Packet ();
packet.type = 102;
packet.tagged = false;
Expand Down Expand Up @@ -186,9 +188,9 @@ public class Lifx.Service {

#if HAVE_SO_REUSEPORT
int32 enable = 1;
Posix.setsockopt(
Posix.setsockopt (
socket.fd, Platform.Socket.SOL_SOCKET, Platform.Socket.SO_REUSEPORT, &enable,
(Posix.socklen_t) sizeof(int)
(Posix.socklen_t) sizeof (int)
);
#endif

Expand Down
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ sources = [
'views/Overview.vala',
'widgets/Carousel.vala',
'widgets/CarouselItem.vala',
'widgets/ColorPicker.vala',
'widgets/IconPopover.vala',
'widgets/Overlay.vala',
'MainWindow.vala'
Expand Down
Loading

0 comments on commit 7ae51cf

Please sign in to comment.