Soletta™ Framework
Framework for making IoT devices

Full online documentation | C API Index
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
/src/samples/flow/tilt-angle/arctan-node.c
/*
* This file is part of the Soletta (TM) Project
*
* Copyright (C) 2016 Intel Corporation. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <errno.h>
#include <stdio.h>
#include <math.h>
#include <sol-log.h>
#include <sol-mainloop.h>
#include <sol-flow.h>
static int
logic_process(struct sol_flow_node *node, void *data, uint16_t port,
uint16_t conn_id, const struct sol_flow_packet *packet);
/* This file is generated using sol-flow-node-type-gen.py, see above */
#include "arctan-spec-gen.c"
static int
logic_process(struct sol_flow_node *node, void *data, uint16_t port,
uint16_t conn_id, const struct sol_flow_packet *packet)
{
int r;
struct sol_drange d_value;
double arctan = 0;
r = sol_flow_packet_get_drange(packet, &d_value);
SOL_INT_CHECK(r, < 0, r);
/*
* atan() is a fuction in math.h library to calculate the
* value of arctangent in radian
*/
if (isfinite(d_value.val)) {
arctan = atan(d_value.val) * 180 / M_PI;
} else {
arctan = 90;
}
SOL_FLOW_NODE_TYPE_ARCTANGENT_LOGIC__OUT__OUT,
arctan);
SOL_INT_CHECK(r, < 0, r);
return 0;
}