SELKIELogger  1.0.0
AutomationHatLEDTest.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Swansea University
3  *
4  * This file is part of the SELKIELogger suite of tools.
5  *
6  * SELKIELogger is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation, either version 3 of the License, or (at your option)
9  * any later version.
10  *
11  * SELKIELogger is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this SELKIELogger product.
18  * If not, see <http://www.gnu.org/licenses/>.
19 */
20 
21 #include <errno.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 
27 #include "SELKIELoggerI2C.h"
28 
40 int main(void) {
41  int handle = i2c_openConnection("/dev/i2c-1");
42 
43  if (handle < 0) {
44  fprintf(stderr, "Unable to open I2C bus: %s\n", strerror(errno));
45  return EXIT_FAILURE;
46  }
47 
48  i2c_sn3218_state s = {0};
49 
50  s.global_enable = 1;
51  for (int j = 0; j < 18; ++j) {
52  for (int i = 0; i < 18; ++i) {
53  s.led[i] = 0;
54  }
55  s.led[j] = 30;
56  if (!i2c_sn3218_update(handle, &s)) {
57  fprintf(stderr, "Unable to update state (LED %02d)\n", j + 1);
58  return -1;
59  }
60  sleep(1);
61  }
62 
63  s.global_enable = 0;
64  i2c_sn3218_update(handle, &s);
65  i2c_closeConnection(handle);
66  return 0;
67 }
int main(void)
int i2c_openConnection(const char *bus)
Set up a connection to the specified bus.
Definition: I2CConnection.c:34
void i2c_closeConnection(int handle)
Close existing connection.
Definition: I2CConnection.c:46
bool i2c_sn3218_update(const int busHandle, const i2c_sn3218_state *state)
Configure SN3218 chip to match state object.
Definition: I2C-SN3218.c:50
SN3218 State representation.
Definition: I2C-SN3218.h:152
uint8_t led[18]
Individual LED brightnesses.
Definition: I2C-SN3218.h:153
bool global_enable
Global on/off switch.
Definition: I2C-SN3218.h:154