forked from ClemensElflein/OpenMower
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,478 additions
and
606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Created by Elmar Elflein on 18/05/23. | ||
// Copyright (c) 2022 Elmar Elflein. All rights reserved. | ||
// | ||
// This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. | ||
// | ||
// Feel free to use the design in your private/educational projects, but don't try to sell the design or products based on it without getting my consent first. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
// | ||
// | ||
#ifndef _FLOATING_AVERAGE_H_ | ||
#define _FLOATING_AVERAGE_H_ | ||
|
||
#include <Arduino.h> | ||
|
||
|
||
class FloatingAverage | ||
{ | ||
|
||
public: | ||
FloatingAverage(); | ||
|
||
void begin(uint32_t nrvalues); | ||
|
||
void AddToFloatAvg(float value); | ||
|
||
float GetFloatAvg(); | ||
|
||
|
||
private: | ||
|
||
uint32_t numberfloatingvalues; | ||
float* valuearray; | ||
uint32_t IndexNextvalue; | ||
|
||
|
||
}; | ||
|
||
|
||
#endif // _FLOATING_AVERAGE_H_ HEADER_FILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// Created by Elmar Elflein on 3/07/22. | ||
// Copyright (c) 2022 Elmar Elflein. All rights reserved. | ||
// | ||
// This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. | ||
// | ||
// Feel free to use the design in your private/educational projects, but don't try to sell the design or products based on it without getting my consent first. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
// | ||
// | ||
#ifndef _UI_DATATYPES_H_ | ||
#define _UI_DATATYPES_H_ | ||
|
||
#include <stdint.h> | ||
#include <cmath> | ||
// Protocol Header Info | ||
enum TYPE | ||
{ | ||
Get_Version = 0xB0, | ||
Set_Buzzer = 0xB1, | ||
Set_LEDs = 0xB2, | ||
Get_Button = 0xB3 | ||
}; | ||
|
||
|
||
// Function definiton for the 18 LEDS | ||
enum LED_id | ||
{ | ||
LED_CHARGING = 0, | ||
LED_BATTERY_LOW = 1, | ||
LED_POOR_GPS = 2, | ||
LED_MOWER_LIFTED = 3, | ||
LED5 = 4, | ||
LED6 = 5, | ||
LED7 = 6, | ||
LED8 = 7, | ||
LED9 = 8, | ||
LED10 = 9, | ||
LED11 = 10, | ||
LED_LOCK = 11, | ||
LED_S2 = 12, | ||
LED_S1 = 13, | ||
LED15 = 14, | ||
LED16 = 15, | ||
LED17 = 16, | ||
LED18 = 17 | ||
}; | ||
|
||
enum LED_state { | ||
LED_off = 0b000, | ||
LED_blink_slow = 0b101, | ||
LED_blink_fast = 0b110, | ||
LED_on = 0b111 | ||
}; | ||
|
||
#pragma pack(push, 1) | ||
struct msg_get_version | ||
{ | ||
uint8_t type; // command type | ||
uint8_t reserved; // padding | ||
uint16_t version; | ||
uint16_t crc; // CRC 16 | ||
} __attribute__((packed)); | ||
#pragma pack(pop) | ||
|
||
|
||
#pragma pack(push, 1) | ||
struct msg_set_buzzer | ||
{ | ||
uint8_t type; // command type | ||
uint8_t repeat; // Repeat X times | ||
uint8_t on_time; // Signal on time | ||
uint8_t off_time; // Signal off time | ||
uint16_t crc; // CRC 16 | ||
} __attribute__((packed)); | ||
#pragma pack(pop) | ||
|
||
|
||
/** | ||
* @brief Use this to update the LED matrix | ||
* Each LED gets three bits with the following meaning: | ||
* 0b000 = Off | ||
* 0b001 = reserved for future use | ||
* 0b010 = reserved for future use | ||
* 0b011 = reserved for future use | ||
* 0b100 = reserved for future use | ||
* 0b101 = On slow blink | ||
* 0b110 = On fast blink | ||
* 0b111 = On | ||
*/ | ||
#pragma pack(push, 1) | ||
struct msg_set_leds | ||
{ | ||
uint8_t type; // command type | ||
uint8_t reserved; // padding | ||
uint64_t leds; | ||
uint16_t crc; // CRC 16 | ||
} __attribute__((packed)); | ||
#pragma pack(pop) | ||
|
||
#pragma pack(push, 1) | ||
struct msg_event_button | ||
{ | ||
uint8_t type; // command type | ||
uint16_t button_id; | ||
uint8_t press_duration; | ||
uint16_t crc; // CRC 16 | ||
} __attribute__((packed)); | ||
#pragma pack(pop) | ||
|
||
|
||
void setLed(struct msg_set_leds &msg, int led, uint8_t state); | ||
|
||
void setBars7(struct msg_set_leds &msg, double value); | ||
|
||
void setBars4(struct msg_set_leds &msg, double value); | ||
|
||
|
||
#endif // _BttnCtl_HEADER_FILE_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
#include "JY901.h" | ||
#include "string.h" | ||
|
||
CJY901 ::CJY901 (HardwareI2C *wire) | ||
{ | ||
ucDevAddr =0x50; | ||
this->wire = wire; | ||
} | ||
void CJY901::StartIIC() | ||
{ | ||
ucDevAddr = 0x50; | ||
wire->begin(); | ||
} | ||
void CJY901::StartIIC(unsigned char ucAddr) | ||
{ | ||
ucDevAddr = ucAddr; | ||
wire->begin(); | ||
} | ||
void CJY901 ::CopeSerialData(unsigned char ucData) | ||
{ | ||
static unsigned char ucRxBuffer[250]; | ||
static unsigned char ucRxCnt = 0; | ||
|
||
ucRxBuffer[ucRxCnt++]=ucData; | ||
if (ucRxBuffer[0]!=0x55) | ||
{ | ||
ucRxCnt=0; | ||
return; | ||
} | ||
if (ucRxCnt<11) {return;} | ||
else | ||
{ | ||
switch(ucRxBuffer[1]) | ||
{ | ||
case 0x50: memcpy(&stcTime,&ucRxBuffer[2],8);break; | ||
case 0x51: memcpy(&stcAcc,&ucRxBuffer[2],8);break; | ||
case 0x52: memcpy(&stcGyro,&ucRxBuffer[2],8);break; | ||
case 0x53: memcpy(&stcAngle,&ucRxBuffer[2],8);break; | ||
case 0x54: memcpy(&stcMag,&ucRxBuffer[2],8);break; | ||
case 0x55: memcpy(&stcDStatus,&ucRxBuffer[2],8);break; | ||
case 0x56: memcpy(&stcPress,&ucRxBuffer[2],8);break; | ||
case 0x57: memcpy(&stcLonLat,&ucRxBuffer[2],8);break; | ||
case 0x58: memcpy(&stcGPSV,&ucRxBuffer[2],8);break; | ||
case 0x59: memcpy(&stcQuater,&ucRxBuffer[2],8);break; | ||
case 0x5a: memcpy(&stcSN,&ucRxBuffer[2],8);break; | ||
} | ||
ucRxCnt=0; | ||
} | ||
} | ||
void CJY901::readRegisters(unsigned char deviceAddr,unsigned char addressToRead, unsigned char bytesToRead, char * dest) | ||
{ | ||
wire->beginTransmission(deviceAddr); | ||
wire->write(addressToRead); | ||
wire->endTransmission(false); //endTransmission but keep the connection active | ||
|
||
wire->requestFrom(deviceAddr, bytesToRead); //Ask for bytes, once done, bus is released by default | ||
|
||
while(wire->available() < bytesToRead); //Hang out until we get the # of bytes we expect | ||
|
||
for(int x = 0 ; x < bytesToRead ; x++) | ||
dest[x] = wire->read(); | ||
} | ||
void CJY901::writeRegister(unsigned char deviceAddr,unsigned char addressToWrite,unsigned char bytesToRead, char *dataToWrite) | ||
{ | ||
wire->beginTransmission(deviceAddr); | ||
wire->write(addressToWrite); | ||
for(int i = 0 ; i < bytesToRead ; i++) | ||
wire->write(dataToWrite[i]); | ||
wire->endTransmission(); //Stop transmitting | ||
} | ||
|
||
short CJY901::ReadWord(unsigned char ucAddr) | ||
{ | ||
short sResult; | ||
readRegisters(ucDevAddr, ucAddr, 2, (char *)&sResult); | ||
return sResult; | ||
} | ||
void CJY901::WriteWord(unsigned char ucAddr,short sData) | ||
{ | ||
writeRegister(ucDevAddr, ucAddr, 2, (char *)&sData); | ||
} | ||
void CJY901::ReadData(unsigned char ucAddr,unsigned char ucLength,char chrData[]) | ||
{ | ||
readRegisters(ucDevAddr, ucAddr, ucLength, chrData); | ||
} | ||
|
||
void CJY901::GetTime() | ||
{ | ||
readRegisters(ucDevAddr, 0x30, 8, (char*)&stcTime); | ||
} | ||
void CJY901::GetAcc() | ||
{ | ||
readRegisters(ucDevAddr, AX, 6, (char *)&stcAcc); | ||
} | ||
void CJY901::GetGyro() | ||
{ | ||
readRegisters(ucDevAddr, GX, 6, (char *)&stcGyro); | ||
} | ||
|
||
void CJY901::GetAngle() | ||
{ | ||
readRegisters(ucDevAddr, Roll, 6, (char *)&stcAngle); | ||
} | ||
void CJY901::GetMag() | ||
{ | ||
readRegisters(ucDevAddr, HX, 6, (char *)&stcMag); | ||
} | ||
void CJY901::GetPress() | ||
{ | ||
readRegisters(ucDevAddr, PressureL, 8, (char *)&stcPress); | ||
} | ||
void CJY901::GetDStatus() | ||
{ | ||
readRegisters(ucDevAddr, D0Status, 8, (char *)&stcDStatus); | ||
} | ||
void CJY901::GetLonLat() | ||
{ | ||
readRegisters(ucDevAddr, LonL, 8, (char *)&stcLonLat); | ||
} | ||
void CJY901::GetGPSV() | ||
{ | ||
readRegisters(ucDevAddr, GPSHeight, 8, (char *)&stcGPSV); | ||
} |
Oops, something went wrong.