Skip to content

Commit

Permalink
ya se edita la configuracion de los leds con un apaño temporal
Browse files Browse the repository at this point in the history
se arreglan cosas de la pagina
se arreglan consas de los esquemas
  • Loading branch information
duxman committed Dec 28, 2018
1 parent 4f3f8f4 commit f4eb8a8
Show file tree
Hide file tree
Showing 16 changed files with 226 additions and 38 deletions.
5 changes: 4 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class programacion:
Estado = ""
Programa = ""
Repeticiones = -1
WaitTime = 10
data = ""

Secuencia = []
Expand All @@ -22,8 +23,10 @@ def __init__(self):
self.HoraDesde = self.data["StartTime"]
self.HoraHasta = self.data["EndTime"]
self.Estado = self.data["State"]
programas = self.data["Programs"]
self.Repeticiones = self.data["Repeats"]
self.WaitTime = int(self.data["WaitTime"])

programas = self.data["Programs"]
vprogramas = programas.split(",")

for p in vprogramas:
Expand Down
7 changes: 6 additions & 1 deletion config/configuracion.json
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
{"GeneralPins":"1,2,3,4,5,6,7,8,9,10,11,12,13,14,15","MusicPath":"./music","FfmpegPath":"./bin","WebServerPort":"8000"}
{
"FfmpegPath": "./bin",
"GeneralPins": "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15",
"MusicPath": "./music",
"WebServerPort": "8000"
}
9 changes: 9 additions & 0 deletions config/led1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Interval": "1",
"Music": "1",
"Name": "led1.json",
"Pins": "1",
"Repeat": "1",
"Secuence": "1",
"Type": "MUSIC"
}
9 changes: 9 additions & 0 deletions config/led2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Interval": "2",
"Music": "2",
"Name": "led2.json",
"Pins": "2",
"Repeat": "2",
"Secuence": "2",
"Type": "MUSIC"
}
9 changes: 9 additions & 0 deletions config/led3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Interval": "3",
"Music": "3",
"Name": "led3.json",
"Pins": "3",
"Repeat": "3",
"Secuence": "3",
"Type": "MUSIC"
}
29 changes: 29 additions & 0 deletions config/ledsConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[
{
"Interval": "1",
"Music": "1",
"Name": "1",
"Pins": "1",
"Repeat": "1",
"Secuence": "1",
"Type": "MUSIC"
},
{
"Interval": "2",
"Music": "2",
"Name": "2",
"Pins": "2",
"Repeat": "2",
"Secuence": "2",
"Type": "MUSIC"
},
{
"Interval": "3",
"Music": "3",
"Name": "3",
"Pins": "3",
"Repeat": "3",
"Secuence": "3",
"Type": "MUSIC"
}
]
9 changes: 8 additions & 1 deletion config/programacion.json
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
{"StartTime":"00:00","EndTime":"23:59","State":"ON","Programs":"led_example.json","Repeats":"3"}
{
"EndTime": "23:59",
"Programs": "led_example.json",
"Repeats": "3",
"StartTime": "00:00",
"State": "ON",
"WaitTime": "10"
}
15 changes: 12 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@ <h1>Configurador DuxmanLigths</h1>
<div class="tab" width="60%">
<button class="tablinks" onclick="openTab(event, 'TabProgramacion')">Programacion Actual</button>
<button class="tablinks" onclick="openTab(event, 'TabConfigGeneral')">Configuracion General</button>
<button class="tablinks" onclick="openTab(event, 'TabPrograms')">Configuracion Programas</button>
</div>


<div id="TabProgramacion" class="tabcontent">
<button id='submitProgramacion'>Guardar Programacion</button>
</div>
<div id="TabConfigGeneral" class="tabcontent">
<button id='submitGeneral' >Guardar Configuracion General</button>
</div>
<div id="TabPrograms" class="tabcontent">
<button id='submitPrograms' >Guardar Configuracion Programas</button>
</div>



Expand All @@ -37,12 +42,16 @@ <h1>Configurador DuxmanLigths</h1>
var editorGeneral
$.getJSON('/config/programacion.json', function(data)
{
editorProgramacion = loadEditor( "schPrograma.json", "TabProgramacion",data, true );
});
editorProgramacion = loadEditor( "schPrograma.json", "TabProgramacion",data, false );
}).fail(function() { editorProgramacion = loadEditorDefault( "schPrograma.json", "TabProgramacion",false ); });
$.getJSON('/config/configuracion.json', function(data)
{
editorGeneral = loadEditor( "schConfiguracion.json", "TabConfigGeneral",data,false );
});
}).fail(function() { editorGeneral = loadEditorDefault( "schConfiguracion.json", "TabConfigGeneral",false ); });
$.getJSON('/config/ledsConfig.json', function(data)
{
editorProgramas = loadEditor( "schPrograms.json", "TabPrograms",data,true );
}).fail(function() { editorProgramas = loadEditorDefault( "schPrograms.json", "TabPrograms",true ); });
//Creamos los eventos
CreateEvents()
</script>
Expand Down
41 changes: 41 additions & 0 deletions js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,44 @@

return editor;
}

function loadEditorDefault( fichero, tab, esarray )
{
JSONEditor.defaults.options.theme = 'bootstrap3';
JSONEditor.defaults.options.iconlib = "fontawesome4";
// Initialize the editor
editor = new JSONEditor(document.getElementById(tab),
{

// Enable fetching schemas via ajax
ajax: true,

// The schema for the editor
schema:
{
$ref: "/schemas/"+fichero
},

// Seed the form with a starting value
//startval: starting_value,

// Disable additional properties
no_additional_properties: true,
disable_edit_json : !esarray,
disable_collapse : true,
disable_array_add : !esarray,
disable_array_delete : !esarray,
disable_properties : true,

// Require all properties by default
required_by_default: true,
});

// Listen for changes
editor.on("change", function()
{
// Do something...
});

return editor;
}
18 changes: 18 additions & 0 deletions js/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ function CreateEvents()
// Get the value from the editor
console.log(datos);
});
document.getElementById('submitPrograms').addEventListener('click',function()
{
var datos = editorProgramas.getValue()
$.ajax
(
{
type: "POST",
url: "/cgi/store.py",
data: { type : "PROGRAMS" ,filename: "leds.json" , contenido: JSON.stringify(datos)},
dataType: "text"
}
).done(function( o )
{
alert("OK PROGRAMS SAVED");
});
// Get the value from the editor
console.log(datos);
});
document.getElementById('submitGeneral').addEventListener('click',function()
{
var datos = editorGeneral.getValue()
Expand Down
44 changes: 20 additions & 24 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def musicManager(self, filename = "" ):
producer.start()
self.WorkingQueue.join()
self.ConsumerThread.stop(timeout=0.3)
self.Logger.info("Fin Del Proceso")
self.Logger.info("Borramos fichero : " + filename)
self.Logger.info("End of the process")

def secuenceManager(self, StringSecuencia, time):
vSecuenciatmp = StringSecuencia.split(",")
Expand All @@ -56,7 +55,7 @@ def secuenceManager(self, StringSecuencia, time):

def reloadConfig(self):
## volvemos a cargar la configuracion de la programacion por si se ha cambiado mientras ejecutabamos
self.Logger.info("Recargamos Programacion por si ha cambiado ")
self.Logger.info("Reloads configuration files ")
self.Config.Programacion = None
self.Config.Programacion = config.programacion()

Expand All @@ -72,8 +71,7 @@ def CreateServer(self, DefaultPort):
self.ConfigServer = WebServer(DefaultPort)
self.ConfigServer.StartServer()


def execute(self, Tiempo):
def execute(self):
i = int(self.Config.Programacion.Repeticiones)
## ejecutamos siempre en un bucle infinito
while( True ):
Expand All @@ -83,8 +81,8 @@ def execute(self, Tiempo):

ahora = time.strftime("%H:%M")
## representacion de fecha y hora
self.Logger.info("Fecha y hora " + time.strftime("%c"))
self.Logger.info("Configuracion de " + desde + " hasta " + hasta)
self.Logger.info("Date Time" + time.strftime("%c"))
self.Logger.info("Configuration from " + desde + " to " + hasta)

## si tenemos que ejecutar
if ((ahora >= desde) & (ahora < hasta)):
Expand All @@ -96,17 +94,17 @@ def execute(self, Tiempo):
break

if( i > 0):
self.Logger.info("Repeticiones que faltan = " + str(i))
self.Logger.info("Remaining repeats = " + str(i))
else:
self.Logger.info("Repeticiones infinitas")
self.Logger.info("Infinite loops")

i = i - 1
##Obtenemos la lista de pines a usar
PinListTemp = self.PinList

##Ejecutamos cada uno de los programas
for p in self.Config.Programacion.Secuencia:
self.Logger.info("ejecutamos programa : " + p.nombre)
self.Logger.info("Execute program: " + p.nombre)
self.PinList = p.pines
self.pinManager( PinList = p.pines )

Expand All @@ -118,31 +116,29 @@ def execute(self, Tiempo):

## dormimos el tiempo estipulado
threading._sleep( float(p.intervalo) )
self.Logger.info("fin ejecutamos programa : " + p.nombre)
self.Logger.info("End Execution of : " + p.nombre)

## Establecemos los pines generales
self.Logger.info("Fin de ejecucion")
self.Logger.info("End of execution")
self.PinList = PinListTemp
self.reloadConfig()
else :
self.Logger.info("End of repeats")
else :
##Como no es la hora dormimos 60 seg
i = int(self.Config.Programacion.Repeticiones)
self.Logger.info( "No es la hora" )
self.Logger.info( "Configuracion de " + desde + " hasta " + hasta )
self.Logger.info( "it is not the Time" )
self.Logger.info( "Configured from " + desde + " to " + hasta )

self.reloadConfig()
threading._sleep(Tiempo)





self.Logger.info("Wait " + str( self.Config.Programacion.WaitTime )+ "sec" )
threading._sleep(self.Config.Programacion.WaitTime)

def __init__(self):
cliente = clienteLog()
self.Logger = cliente.InicializaLog()
self.Logger.info("--------------------<< INI >>--------------------")
self.Logger.info("Arrancamos la ejecucion")
self.Logger.info("Start of Program")
DefaultPort = 8000
if os.path.isfile('./config/configuracion.json'):
"""Leemos la configuracion general"""
Expand All @@ -152,18 +148,18 @@ def __init__(self):
self.PinList = self.Config.Pines
self.Logger.info("Configuracion Cargada")

self.Logger.info("Creamos Cola de procesamiento")
self.Logger.info("Create Process Queue")
self.WorkingQueue = Queue.Queue()
DefaultPort = int(self.Config.WebServerPort)

self.CreateServer(DefaultPort)

if( self.Config != None ):
self.execute(10)
self.execute()
self.ConfigServer.StopServer()


if __name__ == "__main__":
mainprogram = DuxmanLights()
mainprogram.Logger.info("Fin Programa")
mainprogram.Logger.info("--------------------<< END >>--------------------")

5 changes: 5 additions & 0 deletions music/ConvertirWav.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off

echo convertir %1 en converted_%1 con %2 db
sox.exe %1 -b 8 --norm=%2 -e unsigned-integer converted_%1 channels 1 rate 8k

Binary file added music/converted_sample2.wav
Binary file not shown.
7 changes: 7 additions & 0 deletions schemas/schPrograma.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@
"type" : "string",
"enum": [ -1,1,2,3,4,5,10,20,30,40,50,100 ],
"description" : "Numero de repeticiones de la secuencia, -1 infinito"
},
"WaitTime" :
{
"type" : "string",
"enum": [ 10,20,30,40,50,60],
"description" : "Wait time on the execution loop"
}

}
}
19 changes: 19 additions & 0 deletions schemas/schPrograms.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"type": "array",
"format": "table",
"title": "Programs Configuration",
"items" :
{
"title": "Program",
"type": "object",
"properties": {
"Pins" : { "type" : "string", "description" : "Pin List" },
"Music" : { "type" : "string", "description" : "Music Files" },
"Secuence" : { "type" : "string", "description" : "Secuence Program" },
"Interval" : { "type" : "string", "description" : "Wait Time" },
"Repeat" : { "type" : "string", "description" : "Repeats" },
"Type" : { "type" : "string", "description" : "Execution Type", "enum": [ "SEC","MUSIC" ], "default" : "MUSIC" },
"Name" : { "type" : "string", "description" : "Program name", "readonly" : true }
}
}
}
Loading

0 comments on commit f4eb8a8

Please sign in to comment.