/*
 * valf_gt.c
 *
 *  Created on: 07-05-2014
 *      Author: Krzysztof Jakubczyk
 */

#include "tdefs.h"
#include "misc.h"

#include "valf_gt.h"

int valf_gt_initlog(void *arguments, void *logic)
{
	struct valf_gt_args *args = (struct valf_gt_args *)arguments;
	struct valf_gt_logic *log = (struct valf_gt_logic *)logic;

	log->out_ptr = log_manager.nets_data + (args->io.out >> 3);
	log->out_bit_no = args->io.out & 0x07;

	if(log->out_ptr >= (log_manager.nets_data+sizeof(log_manager.nets_data)))
		return -1;

	log->sample_ptr = (float *)(log_manager.nets_data + (args->io.sample_float_in >> 3));
	if((u8*)log->sample_ptr > (log_manager.nets_data+sizeof(log_manager.nets_data)-sizeof(float)))
		return -1;

	return 0;
}

void valf_gt(void *arguments, void *logic)
{
	struct valf_gt_args *args = (struct valf_gt_args *)arguments;
	struct valf_gt_logic *log = (struct valf_gt_logic *)logic;

	if(args->io.out)
	{
		if(*log->sample_ptr > args->params.trig_val)
			*log->out_ptr |= (1<<log->out_bit_no);
		else
			*log->out_ptr &= ~(1<<log->out_bit_no);
	}
}
