mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-10-10 16:43:35 +02:00
2017-05-23 Fred Gleason <fredg@paravelsystems.com>
* Added an 'RDMatrix::KernelGpio' element to the 'RDMatrix::Type enum. * Implemented a Kernel GPIO switcher driver in 'ripcd/kernelgpio.cpp' and 'ripcd/kernelgpio.h'.
This commit is contained in:
@@ -50,6 +50,7 @@ dist_ripcd_SOURCES = acu1p.cpp acu1p.h\
|
||||
btsrc16.cpp btsrc16.h\
|
||||
btsrc8iii.cpp btsrc8iii.h\
|
||||
harlond.cpp harlond.h\
|
||||
kernelgpio.cpp kernelgpio.h\
|
||||
livewire_lwrpaudio.cpp livewire_lwrpaudio.h\
|
||||
livewire_lwrpgpio.cpp livewire_lwrpgpio.h\
|
||||
livewire_mcastgpio.cpp livewire_mcastgpio.h\
|
||||
@@ -96,6 +97,7 @@ nodist_ripcd_SOURCES = moc_am16.cpp\
|
||||
moc_btss44.cpp\
|
||||
moc_btss82.cpp\
|
||||
moc_harlond.cpp\
|
||||
moc_kernelgpio.cpp\
|
||||
moc_livewire_lwrpaudio.cpp\
|
||||
moc_livewire_lwrpgpio.cpp\
|
||||
moc_livewire_mcastgpio.cpp\
|
||||
|
211
ripcd/kernelgpio.cpp
Normal file
211
ripcd/kernelgpio.cpp
Normal file
@@ -0,0 +1,211 @@
|
||||
// kernelgpio.cpp
|
||||
//
|
||||
// A Rivendell switcher driver for the Kernel GPIO interface.
|
||||
//
|
||||
// (C) Copyright 2017 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program 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 this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <globals.h>
|
||||
|
||||
#include "kernelgpio.h"
|
||||
|
||||
KernelGpio::KernelGpio(RDMatrix *matrix,QObject *parent)
|
||||
: Switcher(matrix,parent)
|
||||
{
|
||||
printf("HERE\n");
|
||||
//
|
||||
// Get Matrix Parameters
|
||||
//
|
||||
gpio_matrix=matrix->matrix();
|
||||
gpio_gpis=matrix->gpis();
|
||||
gpio_gpos=matrix->gpos();
|
||||
|
||||
//
|
||||
// Initialize the interface
|
||||
//
|
||||
gpio_reset_mapper=new QSignalMapper(this);
|
||||
connect(gpio_reset_mapper,SIGNAL(mapped(int)),this,SLOT(gpoResetData(int)));
|
||||
gpio_gpio=new RDKernelGpio(this);
|
||||
connect(gpio_gpio,SIGNAL(valueChanged(int,bool)),
|
||||
this,SLOT(gpiChangedData(int,bool)));
|
||||
for(int i=0;i<gpio_gpis;i++) {
|
||||
gpio_gpio->addGpio(i);
|
||||
gpio_gpio->setDirection(i,RDKernelGpio::In);
|
||||
gpio_gpi_mask.push_back(false);
|
||||
}
|
||||
for(int i=0;i<gpio_gpos;i++) {
|
||||
gpio_gpio->addGpio(gpio_gpis+i);
|
||||
gpio_gpio->setDirection(gpio_gpis+i,RDKernelGpio::Out);
|
||||
gpio_gpi_mask.push_back(false);
|
||||
gpio_reset_states.push_back(false);
|
||||
gpio_reset_timers.push_back(new QTimer(this));
|
||||
connect(gpio_reset_timers.back(),SIGNAL(timeout()),
|
||||
gpio_reset_mapper,SLOT(map()));
|
||||
gpio_reset_mapper->setMapping(gpio_reset_timers.back(),i);
|
||||
}
|
||||
|
||||
//
|
||||
// Interval OneShot
|
||||
//
|
||||
gpio_gpi_oneshot=new RDOneShot(this);
|
||||
connect(gpio_gpi_oneshot,SIGNAL(timeout(int)),this,SLOT(gpiOneshotData(int)));
|
||||
}
|
||||
|
||||
|
||||
KernelGpio::~KernelGpio()
|
||||
{
|
||||
for(unsigned i=0;i<gpio_reset_timers.size();i++) {
|
||||
delete gpio_reset_timers[i];
|
||||
}
|
||||
delete gpio_reset_mapper;
|
||||
delete gpio_gpio;
|
||||
delete gpio_gpi_oneshot;
|
||||
}
|
||||
|
||||
|
||||
RDMatrix::Type KernelGpio::type()
|
||||
{
|
||||
return RDMatrix::KernelGpio;
|
||||
}
|
||||
|
||||
|
||||
unsigned KernelGpio::gpiQuantity()
|
||||
{
|
||||
return gpio_gpis;
|
||||
}
|
||||
|
||||
|
||||
unsigned KernelGpio::gpoQuantity()
|
||||
{
|
||||
return gpio_gpos;
|
||||
}
|
||||
|
||||
|
||||
bool KernelGpio::primaryTtyActive()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool KernelGpio::secondaryTtyActive()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void KernelGpio::processCommand(RDMacro *cmd)
|
||||
{
|
||||
switch(cmd->command()) {
|
||||
case RDMacro::GO:
|
||||
if((cmd->argQuantity()!=5)||
|
||||
((cmd->arg(1).toString().lower()!="i")&&
|
||||
(cmd->arg(1).toString().lower()!="o"))||
|
||||
(cmd->arg(2).toInt()<1)||(cmd->arg(2).toInt()>gpio_gpos)||
|
||||
((cmd->arg(3).toInt()!=1)&&(cmd->arg(3).toInt()!=0)&&
|
||||
(cmd->arg(3).toInt()!=-1))||(cmd->arg(4).toInt()<0)) {
|
||||
cmd->acknowledge(false);
|
||||
emit rmlEcho(cmd);
|
||||
return;
|
||||
}
|
||||
if(cmd->arg(1).toString().lower()=="i") {
|
||||
if(cmd->arg(3).toInt()==0) {
|
||||
emit gpiChanged(gpio_matrix,cmd->arg(2).toInt()-1,false);
|
||||
gpio_gpi_mask[cmd->arg(2).toInt()-1]=true;
|
||||
if(cmd->arg(4).toInt()>0) {
|
||||
gpio_gpi_oneshot->
|
||||
start(cmd->arg(2).toInt()-1,cmd->arg(4).toInt());
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(cmd->arg(3).toInt()==1) {
|
||||
emit gpiChanged(gpio_matrix,cmd->arg(2).toInt()-1,true);
|
||||
gpio_gpi_mask[cmd->arg(2).toInt()-1]=true;
|
||||
if(cmd->arg(4).toInt()>0) {
|
||||
gpio_gpi_oneshot->
|
||||
start(cmd->arg(2).toInt()-1,cmd->arg(4).toInt());
|
||||
}
|
||||
}
|
||||
else {
|
||||
gpiOneshotData(cmd->arg(2).toInt()-1);
|
||||
}
|
||||
}
|
||||
cmd->acknowledge(true);
|
||||
emit rmlEcho(cmd);
|
||||
return;
|
||||
}
|
||||
if(cmd->arg(1).toString().lower()=="o") {
|
||||
if(cmd->arg(3).toInt()==0) {
|
||||
gpio_gpio->setValue(gpio_gpis+cmd->arg(2).toInt()-1,false);
|
||||
if(cmd->arg(4).toInt()>0) {
|
||||
gpio_reset_states[cmd->arg(2).toInt()-1]=true;
|
||||
gpio_reset_timers[cmd->arg(2).toInt()-1]->
|
||||
start(cmd->arg(4).toInt(),true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(cmd->arg(3).toInt()==1) {
|
||||
gpio_gpio->setValue(gpio_gpis+cmd->arg(2).toInt()-1,true);
|
||||
if(cmd->arg(4).toInt()>0) {
|
||||
gpio_reset_states[cmd->arg(2).toInt()-1]=false;
|
||||
gpio_reset_timers[cmd->arg(2).toInt()-1]->
|
||||
start(cmd->arg(4).toInt(),true);
|
||||
}
|
||||
}
|
||||
else {
|
||||
cmd->acknowledge(false);
|
||||
emit rmlEcho(cmd);
|
||||
return;
|
||||
}
|
||||
}
|
||||
cmd->acknowledge(true);
|
||||
emit rmlEcho(cmd);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
cmd->acknowledge(false);
|
||||
emit rmlEcho(cmd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void KernelGpio::gpiChangedData(int line,bool state)
|
||||
{
|
||||
if(line<gpio_gpis) {
|
||||
emit gpiChanged(gpio_matrix,line,state);
|
||||
}
|
||||
else {
|
||||
emit gpoChanged(gpio_matrix,line-gpio_gpis,state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void KernelGpio::gpiOneshotData(int value)
|
||||
{
|
||||
gpio_gpi_mask[value]=false;
|
||||
gpiChangedData(value,gpio_gpio->value(value));
|
||||
}
|
||||
|
||||
|
||||
void KernelGpio::gpoResetData(int line)
|
||||
{
|
||||
gpio_gpio->setValue(gpio_gpis+line,gpio_reset_states[line]);
|
||||
emit gpoChanged(gpio_matrix,line,gpio_reset_states[line]);
|
||||
}
|
69
ripcd/kernelgpio.h
Normal file
69
ripcd/kernelgpio.h
Normal file
@@ -0,0 +1,69 @@
|
||||
// kernelgpio.h
|
||||
//
|
||||
// A Rivendell switcher driver for the Kernel GPIO interface.
|
||||
//
|
||||
// (C) Copyright 2017 Fred Gleason <fredg@paravelsystems.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2 as
|
||||
// published by the Free Software Foundation.
|
||||
//
|
||||
// This program 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 this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#ifndef KERNELGPIO_H
|
||||
#define KERNELGPIO_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <qsignalmapper.h>
|
||||
|
||||
#include <rdkernelgpio.h>
|
||||
#include <rd.h>
|
||||
#include <rdmatrix.h>
|
||||
#include <rdmacro.h>
|
||||
#include <rdoneshot.h>
|
||||
|
||||
#include <switcher.h>
|
||||
|
||||
class KernelGpio : public Switcher
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
KernelGpio(RDMatrix *matrix,QObject *parent=0);
|
||||
~KernelGpio();
|
||||
RDMatrix::Type type();
|
||||
unsigned gpiQuantity();
|
||||
unsigned gpoQuantity();
|
||||
bool primaryTtyActive();
|
||||
bool secondaryTtyActive();
|
||||
void processCommand(RDMacro *cmd);
|
||||
|
||||
private slots:
|
||||
void gpiChangedData(int line,bool state);
|
||||
// void gpoChangedData(int line,bool state);
|
||||
void gpiOneshotData(int value);
|
||||
void gpoResetData(int line);
|
||||
|
||||
private:
|
||||
RDKernelGpio *gpio_gpio;
|
||||
RDOneShot *gpio_gpi_oneshot;
|
||||
int gpio_matrix;
|
||||
int gpio_gpis;
|
||||
int gpio_gpos;
|
||||
bool gpio_open;
|
||||
std::vector<bool> gpio_gpi_mask;
|
||||
QSignalMapper *gpio_reset_mapper;
|
||||
std::vector<QTimer *> gpio_reset_timers;
|
||||
std::vector<int> gpio_reset_states;
|
||||
};
|
||||
|
||||
|
||||
#endif // KERNELGPIO_H
|
@@ -42,6 +42,7 @@
|
||||
#include <btss44.h>
|
||||
#include <btss82.h>
|
||||
#include <harlond.h>
|
||||
#include <kernelgpio.h>
|
||||
#include <livewire_lwrpaudio.h>
|
||||
#include <livewire_lwrpgpio.h>
|
||||
#include <livewire_mcastgpio.h>
|
||||
@@ -142,6 +143,10 @@ bool MainObject::LoadSwitchDriver(int matrix_num)
|
||||
ripcd_switcher[matrix_num]=new Harlond(matrix,this);
|
||||
break;
|
||||
|
||||
case RDMatrix::KernelGpio:
|
||||
ripcd_switcher[matrix_num]=new KernelGpio(matrix,this);
|
||||
break;
|
||||
|
||||
case RDMatrix::LiveWireLwrpAudio:
|
||||
ripcd_switcher[matrix_num]=new LiveWireLwrpAudio(matrix,this);
|
||||
break;
|
||||
|
Reference in New Issue
Block a user