MVMFirmwareCpp v0.1
Public Member Functions | Private Member Functions | Private Attributes | List of all members
HW_V3 Class Reference

#include <fw_board_razzeto_v3.h>

Inheritance diagram for HW_V3:
Inheritance graph
[legend]
Collaboration diagram for HW_V3:
Collaboration graph
[legend]

Public Member Functions

bool Init ()
 
bool I2CWrite (t_i2cdevices device, uint8_t *wbuffer, int wlength, bool stop)
 
bool I2CRead (t_i2cdevices device, uint8_t *wbuffer, int wlength, uint8_t *rbuffer, int rlength, bool stop)
 
bool I2CRead (t_i2cdevices device, uint8_t *rbuffer, int rlength, bool stop)
 
bool PWMSet (hw_pwm id, float value)
 
bool IOSet (hw_gpio id, bool value)
 
bool IOGet (hw_gpio id, bool *value)
 
void PrintDebugConsole (String s)
 
void PrintLineDebugConsole (String s)
 
void Tick ()
 
bool DataAvailableOnUART0 ()
 
String ReadUART0UntilEOL ()
 
bool WriteUART0 (String s)
 
void GetPowerStatus (bool *batteryPowered, float *charge)
 
float GetPIN ()
 
float GetBoardTemperature ()
 
uint16_t GetSupervisorAlarms ()
 
- Public Member Functions inherited from HW_V4
bool Init ()
 Initialize hardware peripheral in the system. More...
 
bool I2CWrite (t_i2cdevices device, uint8_t *wbuffer, int wlength, bool stop)
 Write buffer to I2C bus. More...
 
bool I2CRead (t_i2cdevices device, uint8_t *wbuffer, int wlength, uint8_t *rbuffer, int rlength, bool stop)
 Write buffer to I2C bus and read data. More...
 
bool I2CRead (t_i2cdevices device, uint8_t *rbuffer, int rlength, bool stop)
 Read I2c data. More...
 
bool PWMSet (hw_pwm id, float value)
 Control PWM device (PV1) More...
 
bool IOSet (hw_gpio id, bool value)
 Set a GPIO Status (IE Control PV6, Alarms, etc) More...
 
bool IOGet (hw_gpio id, bool *value)
 Get GPIO Status. More...
 
void PrintDebugConsole (String s)
 Print a message on console used for Debug. More...
 
void PrintLineDebugConsole (String s)
 Print a message on console used for Debug with a CR+LR at end. More...
 
void Tick ()
 Tick function must be called periodically. More...
 
bool DataAvailableOnUART0 ()
 API to read if on the communication interfaces there are bytes to be read. More...
 
String ReadUART0UntilEOL ()
 Return a
terminated string from communication interface. More...
 
bool WriteUART0 (String s)
 API to write a string to the communication interfaces. More...
 
void GetPowerStatus (bool *batteryPowered, float *charge)
 API to read battery charge and power supply status. More...
 
float GetPIN ()
 API return pressure on input of MVM. More...
 
float GetBoardTemperature ()
 API return temperature of the board. More...
 
uint16_t GetSupervisorAlarms ()
 API return Supervisor managed alarms. More...
 

Private Member Functions

void __service_i2c_detect ()
 
void i2c_MuxSelect (uint8_t i)
 
t_i2cdev GetIICDevice (t_i2cdevices device)
 

Private Attributes

t_i2cdev iic_devs [IIC_COUNT]
 
uint8_t current_muxpos = 10
 

Detailed Description

Definition at line 23 of file fw_board_razzeto_v3.h.

Member Function Documentation

◆ __service_i2c_detect()

void HW_V3::__service_i2c_detect ( )
private

Definition at line 248 of file fw_board_razzeto_v3.cpp.

249 {
250  byte error, address;
251  int nDevices;
252  Serial.println("Scanning... I2C");
253  nDevices = 0;
254  for (address = 1; address < 127; address++) {
255  Wire.beginTransmission(address);
256  error = Wire.endTransmission();
257  if (error == 0) {
258  Serial.print("I2C device found at address 0x");
259  if (address < 16) {
260  Serial.print("0");
261  }
262  Serial.println(address, HEX);
263  nDevices++;
264  }
265  else if (error == 4) {
266  Serial.print("Unknow error at address 0x");
267  if (address < 16) {
268  Serial.print("0");
269  }
270  Serial.println(address, HEX);
271  }
272  }
273  if (nDevices == 0) {
274  Serial.println("No I2C devices found\n");
275  }
276  else {
277  Serial.println("done\n");
278  }
279 }
Here is the call graph for this function:

◆ DataAvailableOnUART0()

bool HW_V3::DataAvailableOnUART0 ( )

Definition at line 222 of file fw_board_razzeto_v3.cpp.

223 {
224  return Serial.available();
225 }

◆ GetBoardTemperature()

float HW_V3::GetBoardTemperature ( )

Definition at line 319 of file fw_board_razzeto_v3.cpp.

320 {
321  return 40;
322 }

◆ GetIICDevice()

t_i2cdev HW_V3::GetIICDevice ( t_i2cdevices  device)
private

Definition at line 299 of file fw_board_razzeto_v3.cpp.

300 {
301  for (int i = 0; i < IIC_COUNT; i++)
302  {
303  if (iic_devs[i].t_device == device)
304  {
305  return iic_devs[i];
306  }
307  }
308 }
Here is the caller graph for this function:

◆ GetPIN()

float HW_V3::GetPIN ( )

Definition at line 315 of file fw_board_razzeto_v3.cpp.

316 {
317  return 3.8;
318 }

◆ GetPowerStatus()

void HW_V3::GetPowerStatus ( bool *  batteryPowered,
float *  charge 
)

Definition at line 310 of file fw_board_razzeto_v3.cpp.

311 {
312  *batteryPowered = false;
313  *charge = 100;
314 }

◆ GetSupervisorAlarms()

uint16_t HW_V3::GetSupervisorAlarms ( )

Definition at line 323 of file fw_board_razzeto_v3.cpp.

324 {
325  return 0;
326 }

◆ i2c_MuxSelect()

void HW_V3::i2c_MuxSelect ( uint8_t  i)
private

Definition at line 282 of file fw_board_razzeto_v3.cpp.

283 {
284  if (i > 7)
285  return;
286 
287  if (i < 0)
288  return;
289 
290  if (current_muxpos == i) return;
291 
292  current_muxpos = i;
293 
294  Wire.beginTransmission(TCAADDR);
295  Wire.write(1 << i);
296  Wire.endTransmission();
297 }
Here is the caller graph for this function:

◆ I2CRead() [1/2]

bool HW_V3::I2CRead ( t_i2cdevices  device,
uint8_t *  rbuffer,
int  rlength,
bool  stop 
)

Definition at line 116 of file fw_board_razzeto_v3.cpp.

117 {
118  uint8_t count;
119  uint8_t address;
120  t_i2cdev dev = GetIICDevice(device);
121  address = dev.address;
122  i2c_MuxSelect(dev.muxport);
123 
124  count = Wire.requestFrom((uint16_t)address, (uint8_t)rlength, stop);
125 
126  if (count < rlength)
127  return false;
128 
129 
130  for (int i = 0;i < rlength; i++)
131  {
132  rbuffer[i] = Wire.read();
133  }
134 
135  return true;
136 }
Here is the call graph for this function:

◆ I2CRead() [2/2]

bool HW_V3::I2CRead ( t_i2cdevices  device,
uint8_t *  wbuffer,
int  wlength,
uint8_t *  rbuffer,
int  rlength,
bool  stop 
)

Definition at line 88 of file fw_board_razzeto_v3.cpp.

89 {
90  uint8_t address;
91  uint8_t count;
92  uint8_t result;
93 
94  t_i2cdev dev = GetIICDevice(device);
95  address = dev.address;
97 
98  Wire.beginTransmission(address);
99  for (int i = 0;i < wlength; i++)
100  Wire.write(wbuffer[i]);
101  result = Wire.endTransmission();
102  if (result != 0)
103  return false;
104  count = Wire.requestFrom((uint16_t)address, (uint8_t) rlength, stop);
105  if (count < rlength)
106  return false;
107 
108  for (int i = 0;i < rlength; i++)
109  {
110  rbuffer[i] = Wire.read();
111  }
112 
113  return true;
114 }
Here is the call graph for this function:

◆ I2CWrite()

bool HW_V3::I2CWrite ( t_i2cdevices  device,
uint8_t *  wbuffer,
int  wlength,
bool  stop 
)

Definition at line 70 of file fw_board_razzeto_v3.cpp.

71 {
72  uint8_t address;
73  uint8_t result;
74  t_i2cdev dev = GetIICDevice(device);
75  address = dev.address;
77 
78  Wire.beginTransmission(address);
79  for (int i=0;i< wlength; i++)
80  Wire.write(wbuffer[i]);
81  result = Wire.endTransmission();
82 
83  if (result != 0)
84  return false;
85  else
86  return true;
87 }
Here is the call graph for this function:

◆ Init()

bool HW_V3::Init ( )

Definition at line 18 of file fw_board_razzeto_v3.cpp.

19 {
20  Serial.begin(115200);
21 
22 
23  ledcSetup(0, 10000, 12);
24  ledcAttachPin(VALVE_IN_PIN, 0);
25  ledcWrite(0, 0);
26 
27  digitalWrite(VALVE_OUT_PIN, LOW);
28  digitalWrite(ALARM_LED, LOW);
29  digitalWrite(BUZZER, LOW);
30 
31  pinMode(VALVE_OUT_PIN, OUTPUT);
32  pinMode(ALARM_LED, OUTPUT);
33  pinMode(BUZZER, OUTPUT);
34 
35  Wire.begin();
36 
37  for (int i = 0; i < 8; i++) {
38  //i2c_MuxSelect(i);
39  Serial.println("SCAN I2C BUS: " + String(i));
41  }
42 
44  iic_devs[0].muxport = 4;
45  iic_devs[0].address = 0x76;
46 
48  iic_devs[1].muxport = 4;
49  iic_devs[1].address = 0x77;
50 
52  iic_devs[2].muxport = 5;
53  iic_devs[2].address = 0x76;
54 
56  iic_devs[3].muxport = 2;
57  iic_devs[3].address = 0x2E;
58 
60  iic_devs[4].muxport = -1;
61  iic_devs[4].address = 0x70;
62 
64  iic_devs[5].muxport = 2;
65  iic_devs[5].address = 0x00;
66 
67 
68 }
Here is the call graph for this function:

◆ IOGet()

bool HW_V3::IOGet ( hw_gpio  id,
bool *  value 
)

Definition at line 176 of file fw_board_razzeto_v3.cpp.

177 {
178  switch (id)
179  {
180  case GPIO_PV2:
181  *value = digitalRead(VALVE_OUT_PIN);
182  break;
183  case GPIO_BUZZER:
184  *value = digitalRead(BUZZER);
185  break;
186  case GPIO_LED:
187  *value = digitalRead(ALARM_LED);
188  break;
189  case GPIO_RELEALLARM:
190  *value = 0;
191  //*value = digitalRead(ALARM_LED);
192  break;
193  default:
194  return false;
195  break;
196  }
197  return true;
198 }

◆ IOSet()

bool HW_V3::IOSet ( hw_gpio  id,
bool  value 
)

Definition at line 154 of file fw_board_razzeto_v3.cpp.

155 {
156  switch (id)
157  {
158  case GPIO_PV2:
159  digitalWrite(VALVE_OUT_PIN, value ? HIGH : LOW);
160  break;
161  case GPIO_BUZZER:
162  digitalWrite(BUZZER, value ? HIGH : LOW);
163  break;
164  case GPIO_LED:
165  digitalWrite(ALARM_LED, value ? HIGH : LOW);
166  break;
167  case GPIO_RELEALLARM:
168  //digitalWrite(ALARM_LED, LOW);
169  break;
170  default:
171  return false;
172  break;
173  }
174  return true;
175 }

◆ PrintDebugConsole()

void HW_V3::PrintDebugConsole ( String  s)

Definition at line 205 of file fw_board_razzeto_v3.cpp.

206 {
207  Serial.print(s);
208 }
Here is the call graph for this function:

◆ PrintLineDebugConsole()

void HW_V3::PrintLineDebugConsole ( String  s)

Definition at line 210 of file fw_board_razzeto_v3.cpp.

211 {
212  Serial.println(s);
213 }
Here is the call graph for this function:

◆ PWMSet()

bool HW_V3::PWMSet ( hw_pwm  id,
float  value 
)

Definition at line 137 of file fw_board_razzeto_v3.cpp.

138 {
139 
140  if ((value < 0) || (value > 100.0)) return false;
141 
142  switch (id)
143  {
144  case PWM_PV1:
145  uint32_t v = (uint32_t)value * 4095.0 / 100.0;
146  ledcWrite(0, v);
147  break;
148 
149  }
150 
151 
152  return true;
153 }

◆ ReadUART0UntilEOL()

String HW_V3::ReadUART0UntilEOL ( )

Definition at line 232 of file fw_board_razzeto_v3.cpp.

233 {
234  //PERICOLO. SE IL \n NON VIENE INVIATO TUTTO STALLA!!!!
235  return Serial.readStringUntil('\n');
236 }
Here is the call graph for this function:

◆ Tick()

void HW_V3::Tick ( )

Definition at line 215 of file fw_board_razzeto_v3.cpp.

216 {
217 
218  return;
219 }

◆ WriteUART0()

bool HW_V3::WriteUART0 ( String  s)

Definition at line 227 of file fw_board_razzeto_v3.cpp.

228 {
229  Serial.println(s);
230  return true;
231 }
Here is the call graph for this function:

Member Data Documentation

◆ current_muxpos

uint8_t HW_V3::current_muxpos = 10
private

Definition at line 56 of file fw_board_razzeto_v3.h.

◆ iic_devs

t_i2cdev HW_V3::iic_devs[IIC_COUNT]
private

Definition at line 55 of file fw_board_razzeto_v3.h.


The documentation for this class was generated from the following files:
t_i2cdev::address
uint8_t address
Definition: generic_definitions.h:53
t_i2cdev::muxport
int8_t muxport
Definition: generic_definitions.h:54
HW_V3::GetIICDevice
t_i2cdev GetIICDevice(t_i2cdevices device)
Definition: fw_board_razzeto_v3.cpp:299
ALARM_LED
#define ALARM_LED
Definition: fw_board_razzeto_v3.cpp:13
IIC_PS_2
@ IIC_PS_2
Definition: generic_definitions.h:39
TCAADDR
#define TCAADDR
Definition: fw_board_razzeto_v3.cpp:15
PWM_PV1
@ PWM_PV1
Definition: generic_definitions.h:32
GPIO_RELEALLARM
@ GPIO_RELEALLARM
Definition: generic_definitions.h:33
IIC_FLOW1
@ IIC_FLOW1
Definition: generic_definitions.h:43
t_i2cdev::t_device
t_i2cdevices t_device
Definition: generic_definitions.h:52
IIC_PS_0
@ IIC_PS_0
Definition: generic_definitions.h:37
IIC_COUNT
#define IIC_COUNT
Definition: fw_board_ni_v4.h:14
VALVE_IN_PIN
#define VALVE_IN_PIN
Definition: fw_board_razzeto_v3.cpp:9
VALVE_OUT_PIN
#define VALVE_OUT_PIN
Definition: fw_board_razzeto_v3.cpp:10
IIC_MUX
@ IIC_MUX
Definition: generic_definitions.h:48
HW_V3::iic_devs
t_i2cdev iic_devs[IIC_COUNT]
Definition: fw_board_razzeto_v3.h:55
Serial::println
void println()
GPIO_PV2
@ GPIO_PV2
Definition: generic_definitions.h:33
Serial
Definition: arduino.h:2
BUZZER
#define BUZZER
Definition: fw_board_razzeto_v3.cpp:12
HW_V3::__service_i2c_detect
void __service_i2c_detect()
Definition: fw_board_razzeto_v3.cpp:248
GPIO_LED
@ GPIO_LED
Definition: generic_definitions.h:33
t_i2cdev
Definition: generic_definitions.h:51
Serial::begin
void begin()
GPIO_BUZZER
@ GPIO_BUZZER
Definition: generic_definitions.h:33
HW_V3::current_muxpos
uint8_t current_muxpos
Definition: fw_board_razzeto_v3.h:56
Serial::print
void print()
HW_V3::i2c_MuxSelect
void i2c_MuxSelect(uint8_t i)
Definition: fw_board_razzeto_v3.cpp:282
IIC_GENERAL_CALL_SENSIRION
@ IIC_GENERAL_CALL_SENSIRION
Definition: generic_definitions.h:49
Serial::readStringUntil
int readStringUntil()
IIC_PS_1
@ IIC_PS_1
Definition: generic_definitions.h:38