-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting to add No2 display protocol WIP
- Loading branch information
1 parent
631be29
commit 268199f
Showing
4 changed files
with
274 additions
and
12 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
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,112 @@ | ||
/* | ||
Library for King-Meter displays | ||
Copyright © 2015 Michael Fabry (Michael@Fabry.de) | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
#ifndef KINGMETER_H | ||
#define KINGMETER_H | ||
|
||
|
||
// Includes | ||
#include "config.h" | ||
#include "stdint.h" | ||
|
||
#if (DISPLAY_TYPE & DISPLAY_TYPE_NO2) | ||
|
||
|
||
typedef struct | ||
{ | ||
// Parameters received from display in setting mode: | ||
uint16_t WheelSize_mm; // Unit: 1mm | ||
uint8_t PAS_RUN_Direction; // KM_PASDIR_FORWARD / KM_PASDIR_BACKWARD | ||
uint8_t PAS_SCN_Tolerance; // Number of PAS signals to start the motor | ||
uint8_t PAS_N_Ratio; // 0..255 PAS ratio | ||
uint8_t HND_HL_ThrParam; // KM_HND_HL_NO / KM_HND_HL_YES | ||
uint8_t HND_HF_ThrParam; // KM_HND_HF_NO / KM_HND_HF_YES | ||
uint8_t SYS_SSP_SlowStart; // 1..4 Level of soft ramping at start | ||
uint8_t SPS_SpdMagnets; // Number of magnets of speedsensor | ||
uint16_t VOL_1_UnderVolt_x10; // Unit: 0.1V | ||
|
||
}RX_SETTINGS_t; | ||
|
||
typedef struct | ||
{ | ||
// Parameters received from display in operation mode: | ||
uint8_t AssistLevel; // 0..255 Power Assist Level | ||
uint8_t Headlight; // KM_HEADLIGHT_OFF / KM_HEADLIGHT_ON / KM_HEADLIGHT_LOW / KM_HEADLIGHT_HIGH | ||
uint8_t Battery; // KM_BATTERY_NORMAL / KM_BATTERY_LOW | ||
uint8_t PushAssist; // KM_PUSHASSIST_OFF / KM_PUSHASSIST_ON | ||
uint8_t PowerAssist; // KM_POWERASSIST_OFF / KM_POWERASSIST_ON | ||
uint8_t Throttle; // KM_THROTTLE_OFF / KM_THROTTLE_ON | ||
uint8_t CruiseControl; // KM_CRUISE_OFF / KM_CRUISE_ON | ||
uint8_t OverSpeed; // KM_OVERSPEED_OFF / KM_OVERSPEED_ON | ||
uint16_t SPEEDMAX_Limit; // Unit: km/h | ||
uint16_t CUR_Limit_mA; // Unit: mA | ||
|
||
}RX_PARAM_t; | ||
|
||
|
||
|
||
|
||
|
||
typedef struct | ||
{ | ||
// Parameters to be send to display in operation mode: | ||
uint8_t Battery; // KM_BATTERY_NORMAL / KM_BATTERY_LOW | ||
uint16_t Wheeltime_ms; // Unit:1ms | ||
uint8_t Error; // KM_ERROR_NONE, .. | ||
uint16_t Current_x10; // Unit: 0.1A | ||
|
||
}TX_PARAM_t; | ||
|
||
|
||
#define KM_MAX_RXBUFF 64 | ||
|
||
|
||
typedef struct | ||
{ | ||
uint8_t RxState; | ||
int8_t DirectSetpoint; | ||
|
||
uint8_t RxBuff[KM_MAX_RXBUFF]; | ||
uint8_t RxCnt; | ||
|
||
RX_SETTINGS_t Settings; | ||
RX_PARAM_t Rx; | ||
TX_PARAM_t Tx; | ||
|
||
}No2_t; | ||
|
||
|
||
|
||
|
||
// Public function prototypes | ||
|
||
|
||
|
||
|
||
void No2_Service(No2_t* No2_ctx); | ||
|
||
void No2_Init(No2_t* No2_ctx); | ||
|
||
|
||
#endif // Display Type Kingmeter | ||
|
||
#endif // KINGMETER_H | ||
|
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,139 @@ | ||
/* | ||
Library for King-Meter displays | ||
Copyright � 2015 Michael Fabry (Michael@Fabry.de) | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
|
||
// Includes | ||
|
||
#include "config.h" | ||
#include "main.h" | ||
#include "display_No_2.h" | ||
#include "stm32f1xx_hal.h" | ||
#include "print.h" | ||
|
||
#if (DISPLAY_TYPE_NO2) | ||
|
||
UART_HandleTypeDef huart1; | ||
|
||
void No2_Service(No2_t* No2_ctx); | ||
int calculate_checksum(unsigned char* frame_buf, uint8_t length); | ||
|
||
uint8_t lowByte(uint16_t word); | ||
uint8_t highByte(uint16_t word); | ||
|
||
uint8_t pas_tolerance = 0; | ||
uint8_t wheel_magnets = 1; | ||
uint8_t vcutoff = 30; | ||
uint8_t spd_max1 = 25; | ||
uint8_t ui8_RxLength=1; | ||
|
||
|
||
/* Public functions (Prototypes declared by display_kingmeter.h) */ | ||
|
||
/**************************************************************************************************** | ||
* KingMeter_Init() - Initializes the display object | ||
* | ||
****************************************************************************************************/ | ||
|
||
void No2_Init (No2_t* No2_ctx){ | ||
//Start UART with DMA | ||
if (HAL_UART_Receive_DMA(&huart1, (uint8_t *)No2_ctx->RxBuff, 64) != HAL_OK) | ||
{ | ||
Error_Handler(); | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
/**************************************************************************************************** | ||
* KM_901U_Service() - Communication protocol of 901U firmware | ||
* | ||
***************************************************************************************************/ | ||
void No2_Service(No2_t* No2_ctx) | ||
{ | ||
static uint8_t TxBuffer[14] = {0x2,0x0E,0x1,0x0,0x80,0x0,0x0,0x2C,0x0,0xF9,0x0,0x0,0xFF,0xA}; | ||
static uint8_t last_pointer_position; | ||
static uint8_t recent_pointer_position; | ||
static uint8_t Rx_message_length; | ||
static uint8_t No2_Message[32]; | ||
|
||
recent_pointer_position = 64-DMA1_Channel5->CNDTR; | ||
|
||
if(recent_pointer_position>last_pointer_position){ | ||
Rx_message_length=recent_pointer_position-last_pointer_position; | ||
//printf_("groesser %d, %d, %d \n ",recent_pointer_position,last_pointer_position, Rx_message_length); | ||
//HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET); | ||
memcpy(No2_Message,No2_ctx->RxBuff+last_pointer_position,Rx_message_length); | ||
//HAL_UART_Transmit(&huart3, (uint8_t *)&No2_Message, Rx_message_length,50); | ||
} | ||
else { | ||
Rx_message_length=recent_pointer_position+64-last_pointer_position; | ||
memcpy(No2_Message,No2_ctx->RxBuff+last_pointer_position,64-last_pointer_position); | ||
memcpy(No2_Message+64-last_pointer_position,No2_ctx->RxBuff,recent_pointer_position); | ||
// HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET); | ||
|
||
|
||
} | ||
last_pointer_position=recent_pointer_position; | ||
//HAL_UART_Transmit(&huart3, (uint8_t *)&No2_Message, Rx_message_length,50); | ||
|
||
if(No2_Message[19]==calculate_checksum(No2_Message, 20)){ | ||
//to do | ||
|
||
TxBuffer[13]=calculate_checksum(TxBuffer, 14); | ||
HAL_UART_Transmit(&huart1, (uint8_t *)&TxBuffer,14,50); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
|
||
|
||
|
||
#endif | ||
|
||
uint8_t lowByte(uint16_t word){ | ||
return word & 0xFF; | ||
} | ||
|
||
uint8_t highByte(uint16_t word){ | ||
return word >>8; | ||
} | ||
|
||
int calculate_checksum(unsigned char* frame_buf, uint8_t length) { | ||
unsigned char xor = 0; | ||
unsigned char *p; | ||
unsigned char tmp; | ||
for (p = frame_buf; p < frame_buf + (length-1); p++) { | ||
tmp = *p; | ||
//printf("%d, %x\r\n ", p,tmp); | ||
xor = xor ^ tmp; | ||
} | ||
return(xor); | ||
} |
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