1#!/bin/sh
2#
3# SPDX-License-Identifier: Apache-2.0
4#
5# Copyright (C) 2015, ARM Limited and contributors.
6#
7# Licensed under the Apache License, Version 2.0 (the "License"); you may
8# not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19
20SYSFS_BASE="/sys/devices/12c60000.i2c/i2c-4/i2c-dev/i2c-4/device/"
21SYSFS_ARM=$SYSFS_BASE"/4-0040"
22SYSFS_KFC=$SYSFS_BASE"/4-0045"
23
24if [ $# -lt 2 ]; then
25    echo "Usage: $0 samples period_s [arm|kfc]"
26    exit 1
27fi
28
29SAMPLES=$1
30PERIOD=$2
31DEVICE=${3:-"arm"}
32
33case $DEVICE in
34"arm")
35    SYSFS_ENABLE=$SYSFS_ARM"/enable"
36    SYSFS_W=$SYSFS_ARM"/sensor_W"
37    ;;
38"kfc")
39    SYSFS_ENABLE=$SYSFS_KFC"/enable"
40    SYSFS_W=$SYSFS_KFC"/sensor_W"
41    ;;
42esac
43
44echo "Samping $SAMPLES time, every $PERIOD [s]:"
45echo "   $SYSFS_W"
46
47rm samples_w.txt 2>/dev/null
48echo 1 > $SYSFS_ENABLE
49sleep 1
50
51while [ 1 ]; do
52    sleep $PERIOD
53    cat $SYSFS_W >> samples_w.txt
54    SAMPLES=$((SAMPLES-1))
55    [ $SAMPLES -eq 0 ] && break
56done
57
58echo 0 > $SYSFS_ENABLE
59