mirror of https://github.com/OpenIPC/composer.git
Add DBell project
parent
621ebf2c26
commit
7f451d469e
t31_dbell
br-ext-chip-ingenic
general
overlay/etc
package/dbell-ina219
|
@ -0,0 +1,14 @@
|
|||
source "$BR2_EXTERNAL_INGENIC_PATH/linux/Config.ext.in"
|
||||
source "$BR2_EXTERNAL_INGENIC_PATH/package/dbell-ina219/Config.in"
|
||||
source "$BR2_EXTERNAL_INGENIC_PATH/package/dbell-param/Config.in"
|
||||
source "$BR2_EXTERNAL_INGENIC_PATH/package/dbell-web/Config.in"
|
||||
source "$BR2_EXTERNAL_INGENIC_PATH/package/dbell-x4/Config.in"
|
||||
source "$BR2_EXTERNAL_INGENIC_PATH/package/dropbear-openipc/Config.in"
|
||||
source "$BR2_EXTERNAL_INGENIC_PATH/package/fwprintenv-openipc/Config.in"
|
||||
source "$BR2_EXTERNAL_INGENIC_PATH/package/ingenic-osdrv-t31/Config.in"
|
||||
source "$BR2_EXTERNAL_INGENIC_PATH/package/ingenic_patcher/Config.in"
|
||||
source "$BR2_EXTERNAL_INGENIC_PATH/package/ipctool/Config.in"
|
||||
source "$BR2_EXTERNAL_INGENIC_PATH/package/libcurl-openipc/Config.in"
|
||||
source "$BR2_EXTERNAL_INGENIC_PATH/package/linux-firmware-openipc/Config.in"
|
||||
source "$BR2_EXTERNAL_INGENIC_PATH/package/mbedtls-openipc/Config.in"
|
||||
source "$BR2_EXTERNAL_INGENIC_PATH/package/vtund-openipc/Config.in"
|
|
@ -0,0 +1,110 @@
|
|||
# Architecture
|
||||
BR2_mipsel=y
|
||||
BR2_mips_xburst=y
|
||||
# BR2_MIPS_SOFT_FLOAT is not set
|
||||
BR2_MIPS_FP32_MODE_32=y
|
||||
# BR2_MIPS_FP32_MODE_XX is not set
|
||||
BR2_MIPS_NAN_LEGACY=y
|
||||
BR2_MIPS_OABI32=y
|
||||
BR2_KERNEL_HEADERS_VERSION=y
|
||||
BR2_DEFAULT_KERNEL_VERSION="3.10.14"
|
||||
BR2_PACKAGE_HOST_LINUX_HEADERS_CUSTOM_3_10=y
|
||||
|
||||
# Toolchain
|
||||
BR2_PER_PACKAGE_DIRECTORIES=y
|
||||
BR2_GCC_VERSION_8_X=y
|
||||
BR2_EXTRA_GCC_CONFIG_OPTIONS="--with-float=hard"
|
||||
BR2_TOOLCHAIN_USES_UCLIBC=y
|
||||
BR2_TOOLCHAIN_BUILDROOT_UCLIBC=y
|
||||
BR2_TOOLCHAIN_BUILDROOT_LIBC="uclibc"
|
||||
# BR2_TOOLCHAIN_USES_MUSL is not set
|
||||
# BR2_TOOLCHAIN_BUILDROOT_MUSL is not set
|
||||
# BR2_TOOLCHAIN_BUILDROOT_LIBC="musl"
|
||||
BR2_TOOLCHAIN_BUILDROOT_CXX=y
|
||||
BR2_TOOLCHAIN_BUILDROOT_LOCALE=y
|
||||
BR2_TOOLCHAIN_BUILDROOT_USE_SSP=y
|
||||
|
||||
# Kernel
|
||||
BR2_LINUX_KERNEL=y
|
||||
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
|
||||
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="3.10.14"
|
||||
BR2_LINUX_KERNEL_USE_CUSTOM_CONFIG=y
|
||||
BR2_LINUX_KERNEL_CUSTOM_CONFIG_FILE="$(BR2_EXTERNAL_INGENIC_PATH)/board/t31/kernel/t31.generic.config"
|
||||
BR2_LINUX_KERNEL_UIMAGE=y
|
||||
BR2_LINUX_KERNEL_LZMA=y
|
||||
BR2_LINUX_KERNEL_EXT_INGENIC_PATCHER=y
|
||||
BR2_LINUX_KERNEL_EXT_INGENIC_PATCHER_LIST="$(BR2_EXTERNAL_INGENIC_PATH)/board/t31/kernel/patches/ $(BR2_EXTERNAL_INGENIC_PATH)/board/t31/kernel/overlay"
|
||||
|
||||
# Filesystem
|
||||
# BR2_TARGET_TZ_INFO is not set
|
||||
BR2_TARGET_ROOTFS_CPIO=y
|
||||
BR2_TARGET_ROOTFS_SQUASHFS=y
|
||||
BR2_TARGET_ROOTFS_SQUASHFS4_XZ=y
|
||||
BR2_ROOTFS_OVERLAY="$(TOPDIR)/../general/overlay"
|
||||
BR2_ROOTFS_POST_BUILD_SCRIPT="$(TOPDIR)/../scripts/executing_commands_for_$(BR2_TOOLCHAIN_BUILDROOT_LIBC).sh"
|
||||
|
||||
# OpenIPC configuration
|
||||
BR2_TOOLCHAIN_BUILDROOT_VENDOR="dbell"
|
||||
BR2_TARGET_GENERIC_ISSUE="Welcome to DBell x4"
|
||||
BR2_TARGET_GENERIC_HOSTNAME="dbell-t31a"
|
||||
BR2_GLOBAL_PATCH_DIR="$(TOPDIR)/../general/package/all-patches"
|
||||
|
||||
# OpenIPC packages
|
||||
BR2_PACKAGE_BUSYBOX_CONFIG="$(TOPDIR)/../general/package/busybox/busybox.config"
|
||||
BR2_PACKAGE_DROPBEAR_OPENIPC=y
|
||||
# BR2_PACKAGE_FDK_AAC_OPENIPC is not set
|
||||
BR2_PACKAGE_FWPRINTENV_OPENIPC=y
|
||||
BR2_PACKAGE_INGENIC_OSDRV_T31=y
|
||||
BR2_PACKAGE_HASERL=y
|
||||
# BR2_PACKAGE_HISI_GPIO is not set
|
||||
BR2_PACKAGE_IPCTOOL=y
|
||||
# BR2_PACKAGE_JSON_C is not set
|
||||
# BR2_PACKAGE_LAME_OPENIPC is not set
|
||||
BR2_PACKAGE_LIBCURL_OPENIPC=y
|
||||
BR2_PACKAGE_LIBCURL_OPENIPC_CURL=y
|
||||
# BR2_PACKAGE_LIBCURL_OPENIPC_VERBOSE is not set
|
||||
# BR2_PACKAGE_LIBCURL_OPENIPC_PROXY_SUPPORT is not set
|
||||
# BR2_PACKAGE_LIBCURL_OPENIPC_COOKIES_SUPPORT is not set
|
||||
# BR2_PACKAGE_LIBCURL_OPENIPC_EXTRA_PROTOCOLS_FEATURES is not set
|
||||
BR2_PACKAGE_LIBCURL_OPENIPC_MBEDTLS=y
|
||||
# BR2_PACKAGE_LIBEVENT_OPENIPC is not set
|
||||
# BR2_PACKAGE_LIBEVENT_OPENIPC_REMOVE_PYSCRIPT is not set
|
||||
# BR2_PACKAGE_LIBOGG_OPENIPC is not set
|
||||
# BR2_PACKAGE_LIBWEBSOCKETS_OPENIPC is not set
|
||||
# BR2_PACKAGE_LIBYAML is not set
|
||||
# BR2_PACKAGE_MAJESTIC_FONTS is not set
|
||||
# BR2_PACKAGE_MAJESTIC is not set
|
||||
BR2_PACKAGE_MBEDTLS_OPENIPC=y
|
||||
# BR2_PACKAGE_MBEDTLS_OPENIPC_PROGRAMS is not set
|
||||
# BR2_PACKAGE_MBEDTLS_OPENIPC_COMPRESSION is not set
|
||||
# BR2_PACKAGE_MICROBE_WEB is not set
|
||||
# BR2_PACKAGE_MINI_SNMPD is not set
|
||||
# BR2_PACKAGE_MOTORS is not set
|
||||
# BR2_PACKAGE_OPUS_OPENIPC is not set
|
||||
# BR2_PACKAGE_OPUS_OPENIPC_FIXED_POINT is not set
|
||||
# BR2_PACKAGE_SSHPASS is not set
|
||||
# BR2_PACKAGE_UACME_OPENIPC is not set
|
||||
BR2_PACKAGE_VTUND_OPENIPC=y
|
||||
# BR2_PACKAGE_YAML_CLI is not set
|
||||
|
||||
# WiFi
|
||||
BR2_PACKAGE_WIRELESS_TOOLS=y
|
||||
BR2_PACKAGE_WPA_SUPPLICANT=y
|
||||
BR2_PACKAGE_WPA_SUPPLICANT_CLI=y
|
||||
BR2_PACKAGE_WPA_SUPPLICANT_NL80211=y
|
||||
BR2_PACKAGE_WPA_SUPPLICANT_PASSPHRASE=y
|
||||
BR2_PACKAGE_LINUX_FIRMWARE_OPENIPC=y
|
||||
BR2_PACKAGE_LINUX_FIRMWARE_OPENIPC_MT7601U=y
|
||||
# BR2_PACKAGE_RTL8188EU is not set
|
||||
|
||||
# WIREGUARD
|
||||
# BR2_PACKAGE_WIREGUARD_LINUX_COMPAT is not set
|
||||
# BR2_PACKAGE_WIREGUARD_TOOLS is not set
|
||||
|
||||
# DEBUG
|
||||
BR2_PACKAGE_HOST_GDB=y
|
||||
BR2_PACKAGE_GDB=y
|
||||
|
||||
# DBell
|
||||
BR2_PACKAGE_DBELL_INA219=y
|
||||
BR2_PACKAGE_DBELL_WEB=y
|
|
@ -0,0 +1,14 @@
|
|||
include $(BR2_EXTERNAL_INGENIC_PATH)/linux/linux-ext-ingenic_patcher.mk
|
||||
include $(BR2_EXTERNAL_INGENIC_PATH)/package/dbell-ina219/dbell-ina219.mk
|
||||
include $(BR2_EXTERNAL_INGENIC_PATH)/package/dbell-param/dbell-param.mk
|
||||
include $(BR2_EXTERNAL_INGENIC_PATH)/package/dbell-web/dbell-web.mk
|
||||
include $(BR2_EXTERNAL_INGENIC_PATH)/package/dbell-x4/dbell-x4.mk
|
||||
include $(BR2_EXTERNAL_INGENIC_PATH)/package/dropbear-openipc/dropbear-openipc.mk
|
||||
include $(BR2_EXTERNAL_INGENIC_PATH)/package/fwprintenv-openipc/fwprintenv-openipc.mk
|
||||
include $(BR2_EXTERNAL_INGENIC_PATH)/package/ingenic-osdrv-t31/ingenic-osdrv-t31.mk
|
||||
include $(BR2_EXTERNAL_INGENIC_PATH)/package/ingenic_patcher/ingenic_patcher.mk
|
||||
include $(BR2_EXTERNAL_INGENIC_PATH)/package/ipctool/ipctool.mk
|
||||
include $(BR2_EXTERNAL_INGENIC_PATH)/package/libcurl-openipc/libcurl-openipc.mk
|
||||
include $(BR2_EXTERNAL_INGENIC_PATH)/package/linux-firmware-openipc/linux-firmware-openipc.mk
|
||||
include $(BR2_EXTERNAL_INGENIC_PATH)/package/mbedtls-openipc/mbedtls-openipc.mk
|
||||
include $(BR2_EXTERNAL_INGENIC_PATH)/package/vtund-openipc/vtund-openipc.mk
|
|
@ -0,0 +1 @@
|
|||
../../general/package/dbell-ina219
|
|
@ -0,0 +1 @@
|
|||
/dev/mtd0 0x3c000 0x4000
|
|
@ -0,0 +1,7 @@
|
|||
config BR2_PACKAGE_DBELL_INA219
|
||||
bool "dbell-ina219"
|
||||
default n
|
||||
help
|
||||
Simple I2C telemetry system
|
||||
|
||||
https://dbell.ca
|
|
@ -0,0 +1,22 @@
|
|||
################################################################################
|
||||
#
|
||||
# dbell-ina219 | updated 2022.08.26
|
||||
#
|
||||
################################################################################
|
||||
|
||||
DBELL_INA219_LICENSE = MIT
|
||||
DBELL_INA219_LICENSE_FILES = LICENSE
|
||||
|
||||
define DBELL_INA219_EXTRACT_CMDS
|
||||
cp -av ../general/package/dbell-ina219/src/* $(@D)/
|
||||
endef
|
||||
|
||||
define DBELL_INA219_BUILD_CMDS
|
||||
(cd $(@D); $(TARGET_CC) -s ina219.c -o ina219)
|
||||
endef
|
||||
|
||||
define DBELL_INA219_INSTALL_TARGET_CMDS
|
||||
install -m 0755 -D $(@D)/ina219 $(TARGET_DIR)/usr/sbin/ina219
|
||||
endef
|
||||
|
||||
$(eval $(generic-package))
|
|
@ -0,0 +1,400 @@
|
|||
/*
|
||||
* INA219 util - part of PowerCape by AndiceLabs
|
||||
*
|
||||
* Copyright (C) 2014 AndiceLabs admin@andicelabs.com http://andicelabs.com
|
||||
* Copyright (C) 2014 Zig Fisher flyrouter@gmail.com http://zftlab.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* Example run and output:
|
||||
*
|
||||
* OpenWRT:~# ina219 -b 0 -i 60
|
||||
*
|
||||
* 22:49 12168mV 134.2mA
|
||||
* 22:50 12168mV 239.9mA
|
||||
* 22:51 12168mV 134.7mA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <endian.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/i2c-dev.h>
|
||||
|
||||
#define CONFIG_REG 0
|
||||
#define SHUNT_REG 1
|
||||
#define BUS_REG 2
|
||||
#define POWER_REG 3
|
||||
#define CURRENT_REG 4
|
||||
#define CALIBRATION_REG 5
|
||||
|
||||
#define AVR_ADDRESS 0x21
|
||||
#define INA_ADDRESS 0x40
|
||||
|
||||
typedef enum {
|
||||
OP_DUMP,
|
||||
OP_VOLTAGE,
|
||||
OP_CURRENT,
|
||||
OP_MONITOR,
|
||||
OP_NONE
|
||||
} op_type;
|
||||
|
||||
op_type operation = OP_DUMP;
|
||||
|
||||
int interval = 60;
|
||||
int i2c_bus = 0;
|
||||
int i2c_address = INA_ADDRESS;
|
||||
int handle;
|
||||
int whole_numbers = 0;
|
||||
|
||||
|
||||
void msleep( int msecs )
|
||||
{
|
||||
usleep( msecs * 1000 );
|
||||
}
|
||||
|
||||
|
||||
int i2c_read( void *buf, int len )
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if ( read( handle, buf, len ) != len )
|
||||
{
|
||||
printf( "I2C read failed: %s\n", strerror( errno ) );
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
int i2c_write( void *buf, int len )
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
if ( write( handle, buf, len ) != len )
|
||||
{
|
||||
printf( "I2C write failed: %s\n", strerror( errno ) );
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
int register_read( unsigned char reg, unsigned short *data )
|
||||
{
|
||||
int rc = -1;
|
||||
unsigned char bite[ 4 ];
|
||||
|
||||
bite[ 0 ] = reg;
|
||||
if ( i2c_write( bite, 1 ) == 0 )
|
||||
{
|
||||
if ( i2c_read( bite, 2 ) == 0 )
|
||||
{
|
||||
*data = ( bite[ 0 ] << 8 ) | bite[ 1 ];
|
||||
rc = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
int register_write( unsigned char reg, unsigned short data )
|
||||
{
|
||||
int rc = -1;
|
||||
unsigned char bite[ 4 ];
|
||||
|
||||
bite[ 0 ] = reg;
|
||||
bite[ 1 ] = ( data >> 8 ) & 0xFF;
|
||||
bite[ 2 ] = ( data & 0xFF );
|
||||
|
||||
if ( i2c_write( bite, 3 ) == 0 )
|
||||
{
|
||||
rc = 0;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
void show_usage( char *progname )
|
||||
{
|
||||
fprintf( stderr, "Usage: %s <mode> \n", progname );
|
||||
fprintf( stderr, " Mode (required):\n" );
|
||||
fprintf( stderr, " -h --help Show usage.\n" );
|
||||
fprintf( stderr, " -i --interval Set interval for monitor mode.\n" );
|
||||
fprintf( stderr, " -w --whole Show whole numbers only. Useful for scripts.\n" );
|
||||
fprintf( stderr, " -v --voltage Show battery voltage in mV.\n" );
|
||||
fprintf( stderr, " -c --current Show battery current in mA.\n" );
|
||||
fprintf( stderr, " -a --address <addr> Override I2C address of INA219 from default of 0x%02X.\n", i2c_address );
|
||||
fprintf( stderr, " -b --bus <i2c bus> Override I2C bus from default of %d.\n", i2c_bus );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
|
||||
void parse( int argc, char *argv[] )
|
||||
{
|
||||
while( 1 )
|
||||
{
|
||||
static const struct option lopts[] =
|
||||
{
|
||||
{ "address", 0, 0, 'a' },
|
||||
{ "bus", 0, 0, 'b' },
|
||||
{ "current", 0, 0, 'c' },
|
||||
{ "help", 0, 0, 'h' },
|
||||
{ "interval", 0, 0, 'i' },
|
||||
{ "voltage", 0, 0, 'v' },
|
||||
{ "whole", 0, 0, 'w' },
|
||||
{ NULL, 0, 0, 0 },
|
||||
};
|
||||
int c;
|
||||
|
||||
c = getopt_long( argc, argv, "a:b:chi:vw", lopts, NULL );
|
||||
|
||||
if( c == -1 )
|
||||
break;
|
||||
|
||||
switch( c )
|
||||
{
|
||||
case 'a':
|
||||
{
|
||||
errno = 0;
|
||||
i2c_address = (int)strtol( optarg, NULL, 0 );
|
||||
if ( errno != 0 )
|
||||
{
|
||||
fprintf( stderr, "Unknown address parameter %s.\n", optarg );
|
||||
exit( 1 );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'b':
|
||||
{
|
||||
errno = 0;
|
||||
i2c_bus = (int)strtol( optarg, NULL, 0 );
|
||||
if ( errno != 0 )
|
||||
{
|
||||
fprintf( stderr, "Unknown bus parameter %s.\n", optarg );
|
||||
exit( 1 );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'c':
|
||||
{
|
||||
operation = OP_CURRENT;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
case 'h':
|
||||
{
|
||||
operation = OP_NONE;
|
||||
show_usage( argv[ 0 ] );
|
||||
break;
|
||||
}
|
||||
|
||||
case 'i':
|
||||
{
|
||||
operation = OP_MONITOR;
|
||||
interval = atoi( optarg );
|
||||
if ( ( interval == 0 ) && ( errno != 0 ) )
|
||||
{
|
||||
fprintf( stderr, "Invalid interval value\n" );
|
||||
exit( 1 );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'v':
|
||||
{
|
||||
operation = OP_VOLTAGE;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'w':
|
||||
{
|
||||
whole_numbers = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int get_voltage( float *mv )
|
||||
{
|
||||
short bus;
|
||||
|
||||
if ( register_read( BUS_REG, (unsigned short*)&bus ) != 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
*mv = ( float )( ( bus & 0xFFF8 ) >> 1 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int get_current( float *ma )
|
||||
{
|
||||
short shunt;
|
||||
|
||||
if ( register_read( SHUNT_REG, &shunt ) != 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
*ma = (float)shunt / 10;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void show_current( void )
|
||||
{
|
||||
float ma;
|
||||
|
||||
if ( get_current( &ma ) )
|
||||
{
|
||||
fprintf( stderr, "Error reading current\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( whole_numbers )
|
||||
{
|
||||
printf( "%4.0f\n", ma );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "%04.1f\n", ma );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void show_voltage( void )
|
||||
{
|
||||
float mv;
|
||||
|
||||
if ( get_voltage( &mv ) )
|
||||
{
|
||||
fprintf( stderr, "Error reading voltage\n" );
|
||||
return;
|
||||
}
|
||||
printf( "%4.0f\n", mv );
|
||||
}
|
||||
|
||||
|
||||
void show_voltage_current( void )
|
||||
{
|
||||
float mv, ma;
|
||||
|
||||
if ( get_current( &ma ) || get_voltage( &mv ) )
|
||||
{
|
||||
fprintf( stderr, "Error reading voltage/current\n" );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( whole_numbers )
|
||||
{
|
||||
printf( "%04.0fmV %4.0fmA\n", mv, ma );
|
||||
}
|
||||
else
|
||||
{
|
||||
printf( "%04.0fmV %04.1fmA\n", mv, ma );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void monitor( void )
|
||||
{
|
||||
struct tm *tmptr;
|
||||
time_t seconds;
|
||||
|
||||
while ( 1 )
|
||||
{
|
||||
seconds = time( NULL );
|
||||
tmptr = localtime( &seconds );
|
||||
printf( "%02d:%02d ", tmptr->tm_hour, tmptr->tm_min );
|
||||
show_voltage_current();
|
||||
sleep( interval );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
char filename[ 20 ];
|
||||
|
||||
parse( argc, argv );
|
||||
|
||||
snprintf( filename, 19, "/dev/i2c-%d", i2c_bus );
|
||||
handle = open( filename, O_RDWR );
|
||||
if ( handle < 0 )
|
||||
{
|
||||
fprintf( stderr, "Error opening bus %d: %s\n", i2c_bus, strerror( errno ) );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
if ( ioctl( handle, I2C_SLAVE, i2c_address ) < 0 )
|
||||
{
|
||||
fprintf( stderr, "Error setting address %02X: %s\n", i2c_address, strerror( errno ) );
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
switch ( operation )
|
||||
{
|
||||
case OP_DUMP:
|
||||
{
|
||||
show_voltage_current();
|
||||
break;
|
||||
}
|
||||
|
||||
case OP_VOLTAGE:
|
||||
{
|
||||
show_voltage();
|
||||
break;
|
||||
}
|
||||
|
||||
case OP_CURRENT:
|
||||
{
|
||||
show_current();
|
||||
break;
|
||||
}
|
||||
|
||||
case OP_MONITOR:
|
||||
{
|
||||
monitor();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
case OP_NONE:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
close( handle );
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue