Add Python & USB API for controlling phone power (#313)

* Added interface for phone power

* Add power function in python

* Fixed struct
master
robbederks 2019-11-04 17:26:37 -08:00 committed by GitHub
parent ba9fb69f65
commit e0762c2e77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 38 additions and 7 deletions

View File

@ -11,6 +11,7 @@ typedef bool (*board_check_ignition)(void);
typedef uint32_t (*board_read_current)(void);
typedef void (*board_set_ir_power)(uint8_t percentage);
typedef void (*board_set_fan_power)(uint8_t percentage);
typedef void (*board_set_phone_power)(bool enabled);
struct board {
const char *board_type;
@ -27,6 +28,7 @@ struct board {
board_read_current read_current;
board_set_ir_power set_ir_power;
board_set_fan_power set_fan_power;
board_set_phone_power set_phone_power;
};
// ******************* Definitions ********************

View File

@ -146,6 +146,10 @@ void black_set_fan_power(uint8_t percentage){
UNUSED(percentage);
}
void black_set_phone_power(bool enabled){
UNUSED(enabled);
}
void black_init(void) {
common_init_gpio();
@ -227,5 +231,6 @@ const board board_black = {
.check_ignition = black_check_ignition,
.read_current = black_read_current,
.set_fan_power = black_set_fan_power,
.set_ir_power = black_set_ir_power
.set_ir_power = black_set_ir_power,
.set_phone_power = black_set_phone_power
};

View File

@ -17,5 +17,6 @@ const board board_grey = {
.check_ignition = white_check_ignition,
.read_current = white_read_current,
.set_fan_power = white_set_fan_power,
.set_ir_power = white_set_ir_power
.set_ir_power = white_set_ir_power,
.set_phone_power = white_set_phone_power
};

View File

@ -73,6 +73,10 @@ void pedal_set_fan_power(uint8_t percentage){
UNUSED(percentage);
}
void pedal_set_phone_power(bool enabled){
UNUSED(enabled);
}
void pedal_init(void) {
common_init_gpio();
@ -108,5 +112,6 @@ const board board_pedal = {
.check_ignition = pedal_check_ignition,
.read_current = pedal_read_current,
.set_fan_power = pedal_set_fan_power,
.set_ir_power = pedal_set_ir_power
.set_ir_power = pedal_set_ir_power,
.set_phone_power = pedal_set_phone_power
};

View File

@ -140,6 +140,10 @@ uint32_t uno_read_current(void){
return 0U;
}
void uno_set_phone_power(bool enabled){
set_gpio_output(GPIOB, 4, enabled);
}
void uno_init(void) {
common_init_gpio();
@ -168,7 +172,7 @@ void uno_init(void) {
uno_set_gps_load_switch(true);
// Turn on phone regulator
set_gpio_output(GPIOB, 4, 1);
uno_set_phone_power(true);
// Initialize IR PWM and set to 0%
set_gpio_alternate(GPIOB, 7, GPIO_AF2_TIM4);
@ -243,5 +247,6 @@ const board board_uno = {
.check_ignition = uno_check_ignition,
.read_current = uno_read_current,
.set_fan_power = uno_set_fan_power,
.set_ir_power = uno_set_ir_power
.set_ir_power = uno_set_ir_power,
.set_phone_power = uno_set_phone_power
};

View File

@ -236,6 +236,10 @@ bool white_check_ignition(void){
return !get_gpio_input(GPIOA, 1);
}
void white_set_phone_power(bool enabled){
UNUSED(enabled);
}
void white_init(void) {
common_init_gpio();
@ -332,5 +336,6 @@ const board board_white = {
.check_ignition = white_check_ignition,
.read_current = white_read_current,
.set_fan_power = white_set_fan_power,
.set_ir_power = white_set_ir_power
.set_ir_power = white_set_ir_power,
.set_phone_power = white_set_phone_power
};

View File

@ -313,6 +313,10 @@ int usb_cb_control_msg(USB_Setup_TypeDef *setup, uint8_t *resp, bool hardwired)
resp[1] = ((fan_rpm & 0xFF00U) >> 8U);
resp_len = 2;
break;
// **** 0xb3: set phone power
case 0xb3:
current_board->set_phone_power(setup->b.wValue.w > 0U);
break;
// **** 0xc0: get CAN debug info
case 0xc0:
puts("can tx: "); puth(can_tx_cnt);

View File

@ -626,4 +626,8 @@ class Panda(object):
def get_fan_rpm(self):
dat = self._handle.controlRead(Panda.REQUEST_IN, 0xb2, 0, 0, 2)
a = struct.unpack("H", dat)
return a[0]
return a[0]
# ****************** Phone *****************
def set_phone_power(self, enabled):
self._handle.controlWrite(Panda.REQUEST_OUT, 0xb3, int(enabled), 0, b'')