blob: 83c823ff7a5e0c7dd5173426932b128e0be2839d [file] [log] [blame]
// Copyright 2011 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// smogcheck.c: demonstrate use of lib_smogcheck.c
#include <stdint.h>
#include <stdlib.h>
#include "lib/lib_smogcheck.h"
void ExitOnError(int val) {
if (val < 0) {
exit(EXIT_FAILURE);
}
}
int main() {
int fd = -1;
int ret = -1;
const int kPcaSlaveAddress = 0x27;
const int kI2cBusAddress = 0x2;
const int kInaSlaveAddress = 0x40;
const uint8_t kLedRegister = 0x3;
const uint8_t kVoltageRegister = 0x2;
const uint8_t kTurnOnLedOne = 0xfe;
fd = GetDeviceFile(kI2cBusAddress);
ExitOnError(fd);
// Enable LED 1
ret = SetSlaveAddress(fd, kPcaSlaveAddress);
ExitOnError(ret);
ret = WriteByte(fd, kLedRegister, kTurnOnLedOne);
ExitOnError(ret);
ret = ReadByte(fd, kLedRegister);
ExitOnError(ret);
// Read Backup Power voltage
ret = SetSlaveAddress(fd, kInaSlaveAddress);
ExitOnError(ret);
ret = ReadWord(fd, kVoltageRegister);
ExitOnError(ret);
return EXIT_SUCCESS;
}