Skip to content

Commit

Permalink
added presets
Browse files Browse the repository at this point in the history
  • Loading branch information
DatNoHand committed Sep 18, 2018
1 parent 86dd87d commit b4cab52
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 40 deletions.
24 changes: 17 additions & 7 deletions server/public/js/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ var lamp_off_color = '#707070'
var tries = 0
var live = false
var drawn = false
var presets;

DrawPage('main')
DrawPage('main');
Start()

function Start() {
Expand All @@ -38,6 +39,11 @@ function Start() {
var msg = JSON.parse(e.data);

switch(msg.type) {
case 'init':
break;
case 'presets':
presets = msg.presets;
break;
case 'status':
lights_on = msg.on
led_color = '#' + msg.color
Expand Down Expand Up @@ -127,7 +133,7 @@ function DrawWall() {

// Button handlers
$('div.b').on('input', '#br', function () {
SendBrightness($(this).val())
SendBrightness($(this).val());
})

$('div.b').on('click', '.button.amount', function () {
Expand All @@ -137,9 +143,13 @@ $('div.b').on('click', '.button.amount', function () {
})

$('div.b').on('click', '.button.preset', function () {
LoadPreset($(this).attr('data-preset'))
})
SendPreset($(this).attr('data-id'));
console.log($(this).attr('data-id'));
});

$('div.b').on('click', '.button.main', () => {
DrawPage('main');
});

// On Wall button click
$('div.b').on('click', 'div.wall', function () {
Expand All @@ -165,7 +175,7 @@ $('div.b').on('click', 'div.wall', function () {
})

// Longpress to show colorpicker
var timer
var timer;
$('div.b').on('mousedown', '.color', function (e) {
timer = setTimeout(() => {
$('.button.colpicker').click();
Expand Down Expand Up @@ -194,7 +204,7 @@ $('div.b').on('click', '#onOff', function () {

$('div.b').on('click', '.button.colpicker', function (e) {
color = $(this).val().slice(1,7)
})
});

function UpdateWalls() {
for (let i = 0; i < wall_data.length; i++) {
Expand All @@ -212,7 +222,7 @@ function UpdateWalls() {
}
}

function preset(id, data) {
function SendPreset(id, data) {
send({type: 'preset', presetId: id, data: data});
}

Expand Down
4 changes: 4 additions & 0 deletions server/public/layout/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ p {
transition: 1s;
}

.button {
cursor: pointer;
}

.slider::-moz-range-thumb {
width: 20px;
height: 20px;
Expand Down
4 changes: 4 additions & 0 deletions server/public/pages/main.tbd
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
<div class="effect amount button set" data-amount='5'><p>Jede 5. LED</p></div>
<div class="effect amount button set" data-amount='10'><p>Jede 10. LED</p></div>
</div>
<div class="colorpicker">
<!-- HACK: -->
<button type="button" name="button" onclick="DrawPage('preset')">Presets</button>
</div>
</div>
<!-- <div class="center">
<div class="colorpicker">
Expand Down
14 changes: 14 additions & 0 deletions server/public/pages/preset.tbd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="center">
<div class="presetHolder"></div>
<div class="main button">Go back</div>
</div>

<script type="text/javascript">
(function() {
'use strict';
let preset;
for (preset of presets) {
$('div.presetHolder').append('<div class="button preset" data-id="'+preset.id+'">' + preset.slug + '</div>');
}
}());
</script>
32 changes: 0 additions & 32 deletions server/public/presets/index.html

This file was deleted.

5 changes: 4 additions & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ presetDBInstance.add(new Preset('rainbow_animated', l_rainbow_factory));
// If the server gets a connection
wss.on('connection', function(ws, req) {

SendToEveryone({type: 'status', on: LedLib.on, max: LedLib.max_brightness, favorites: favorites, color: LedLib.color, wall_data: LedLib.wall_data })
SendToEveryone({type: 'status', on: LedLib.on, max: LedLib.max_brightness, favorites: favorites, color: LedLib.color, wall_data: LedLib.wall_data });
SendToEveryone({type: 'presets', presets: presetDBInstance.presets});

ws.on('message', (msg) => {
try {
Expand Down Expand Up @@ -123,6 +124,8 @@ function PresetDb() {
}

this.run = (id, data) => {
id = parseInt(id);

let p = this.getPresetById(id);
if (p === undefined) return false;
let d = data === undefined ? p.data : data;
Expand Down

0 comments on commit b4cab52

Please sign in to comment.