Loom 4 v4.5
Arduino library for Internet of Things Rapid Prototyping in environmental sensing
Loading...
Searching...
No Matches
Loom_Multiplexer.h
1#pragma once
2
3#include "../../Loom_Manager.h"
4#include "../../Module.h"
5
6#include <vector>
7#include <tuple>
8#include <algorithm>
9#include "Wire.h"
10
11// I2C Sensors Used by Loom
12#include "../../Sensors/I2C/Loom_ADS1115/Loom_ADS1115.h"
13#include "../../Sensors/I2C/Loom_MPU6050/Loom_MPU6050.h"
14#include "../../Sensors/I2C/Loom_MS5803/Loom_MS5803.h"
15#include "../../Sensors/I2C/Loom_SHT31/Loom_SHT31.h"
16#include "../../Sensors/I2C/Loom_TSL2591/Loom_TSL2591.h"
17#include "../../Sensors/I2C/Loom_STEMMA/Loom_STEMMA.h"
18#include "../../Sensors/I2C/Loom_MB1232/Loom_MB1232.h"
19#include "../../Sensors/I2C/Loom_K30/Loom_K30.h"
20#include "../../Sensors/I2C/Loom_MMA8451/Loom_MMA8451.h"
21#include "../../Sensors/I2C/Loom_ZXGesture/Loom_ZXGesture.h"
22
30class Loom_Multiplexer : public Module{
31 public:
32
33 /* Loomified generalized calls*/
34 void initialize() override;
35 void measure() override;
36 void package() override;
37 void power_down() override;
38 void power_up() override;
39
46
47 // Destructor removes all new sensor instances
49
50 private:
51 Manager* manInst; // Instance of the manager
52 byte activeMuxAddr; // The port which we want to try to communicate over
53 const uint8_t numPorts = 8; // Number of ports on the multiplexer
54
55 std::vector<std::tuple<byte, Module*, int>> sensors; // List of sensors
56
57 void selectPin(uint8_t pin); // Select which pin of the multiplexer to transmit to
58 void disableChannels(); // Disables all channels on the Multiplexer
59 bool isDeviceConnected(byte addr); // Check if there is a device at the specified address
60
61 void refreshSensors(); // Checks to see if any new sensors were swapped in allows for hot swapping
62 Module* loadSensor(const byte addr); // Load the correct sensor based on the I2C address
63
64 // Used to optimize searching for sensors:
65 // search addresses in array rather than 0-127
66 const std::array<byte, 21> known_addresses =
67 {
68 0x10,
69 0x11,
70 0x19,
71 0x1C,
72 0x1D,
73 0x29,
74 0x36,
75 0x44,
76 0x45,
77 0x48,
78 0x49,
79 0x68,
80 0x69,
81 0x70,
82 0x76,
83 0x77
84 };
85
89 const std::array<byte, 9> alt_addresses = {
90 0x70,
91 0x71,
92 0x72,
93 0x73,
94 0x74,
95 0x75,
96 0x76,
97 0x77,
98 0x78
99 };
100
101};
Definition: Loom_Multiplexer.h:30
Definition: Loom_Manager.h:18
Definition: Module.h:30