Last active
November 18, 2017 10:14
-
-
Save davidhoness/6a53345441de4be31603746b2db8784e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/python3 | |
from sense_hat import * | |
EN_DIRECTION_UP = 'up' | |
EN_DIRECTION_DOWN = 'down' | |
EN_DIRECTION_LEFT = 'left' | |
EN_DIRECTION_RIGHT = 'right' | |
EN_DIRECTION_MIDDLE = 'middle' | |
EN_ACTION_PRESSED = 'pressed' | |
EN_ACTION_RELEASED = 'released' | |
EN_ACTION_HELD = 'held' | |
class SenseStick_en(SenseStick): | |
def __init__(self): | |
SenseStick.__init__(self) | |
def en_wait_for_event(self, en_emptybuffer=False): | |
return self.wait_for_event(en_emptybuffer) | |
SenseStick_en.en_get_events = SenseStick_en.get_events | |
SenseStick_en.en_direction_up = SenseStick_en.direction_up | |
SenseStick_en.en_direction_down = SenseStick_en.direction_down | |
SenseStick_en.en_direction_left = SenseStick_en.direction_left | |
SenseStick_en.en_direction_right = SenseStick_en.direction_right | |
SenseStick_en.en_direction_middle = SenseStick_en.direction_middle | |
SenseStick_en.en_direction_any = SenseStick_en.direction_any | |
class SenseHat_en(SenseHat): | |
def __init__(self): | |
SenseHat.__init__(self) | |
self._stick = SenseStick_en() | |
#### | |
# LED Matrix | |
#### | |
def en_set_rotation(self, en_r=0, en_redraw=True): | |
self.set_rotation(en_r, en_redraw) | |
def en_flip_h(self, en_redraw=True): | |
return self.flip_h(en_redraw) | |
def en_flip_v(self, en_redraw=True): | |
return self.flip_v(en_redraw) | |
def en_set_pixels(self, en_pixel_list): | |
self.set_pixels(en_pixel_list) | |
def en_set_pixel(self, en_x, en_y, *en_args): | |
self.set_pixel(en_x, en_y, *en_args) | |
def en_get_pixel(self, en_x, en_y): | |
return self.get_pixel(en_x, en_y) | |
def en_load_image(self, en_file_path, en_redraw=True): | |
return self.load_image(en_file_path, en_redraw) | |
def en_clear(self, *en_args): | |
self.clear(*en_args) | |
def en_show_message(self, en_text_string, en_scroll_speed=.1, en_text_colour=[255, 255, 255], en_back_colour=[0, 0, 0]): | |
self.show_message(en_text_string, en_scroll_speed, en_text_colour, en_back_colour) | |
def en_show_letter(self, en_s, en_text_colour=[255, 255, 255], en_back_colour=[0, 0, 0]): | |
self.show_letter(en_s, en_text_colour, en_back_colour) | |
#### | |
# IMU Sensor | |
#### | |
def en_set_imu_config(self, en_compass_enabled, en_gyro_enabled, en_accel_enabled): | |
self.set_imu_config(en_compass_enabled, en_gyro_enabled, en_accel_enabled) | |
# Joystick | |
SenseHat_en.en_stick = SenseHat_en.stick | |
# LED matrix | |
SenseHat_en.en_rotation = SenseHat_en.rotation | |
SenseHat_en.en_get_pixels = SenseHat_en.get_pixels | |
SenseHat_en.en_gamma = SenseHat_en.gamma | |
SenseHat_en.en_gamma_reset = SenseHat_en.gamma_reset | |
SenseHat_en.en_low_light = SenseHat_en.low_light | |
# Environmental sensors | |
SenseHat_en.en_get_humidity = SenseHat_en.get_humidity | |
SenseHat_en.en_humidity = SenseHat_en.humidity | |
SenseHat_en.en_get_temperature_from_humidity = SenseHat_en.get_temperature_from_humidity | |
SenseHat_en.en_get_temperature_from_pressure = SenseHat_en.get_temperature_from_pressure | |
SenseHat_en.en_get_temperature = SenseHat_en.get_temperature | |
SenseHat_en.en_temp = SenseHat_en.temp | |
SenseHat_en.en_temperature = SenseHat_en.temperature | |
SenseHat_en.en_get_pressure = SenseHat_en.get_pressure | |
SenseHat_en.en_pressure = SenseHat_en.pressure | |
# IMU sensor | |
SenseHat_en.en_get_orientation_radians = SenseHat_en.get_orientation_radians | |
SenseHat_en.en_orientation_radians = SenseHat_en.orientation_radians | |
SenseHat_en.en_get_orientation_degrees = SenseHat_en.get_orientation_degrees | |
SenseHat_en.en_get_orientation = SenseHat_en.get_orientation | |
SenseHat_en.en_orientation = SenseHat_en.orientation | |
SenseHat_en.en_get_compass = SenseHat_en.get_compass | |
SenseHat_en.en_compass = SenseHat_en.compass | |
SenseHat_en.en_get_compass_raw = SenseHat_en.get_compass_raw | |
SenseHat_en.en_compass_raw = SenseHat_en.compass_raw | |
SenseHat_en.en_get_gyroscope = SenseHat_en.get_gyroscope | |
SenseHat_en.en_gyro = SenseHat_en.gyro | |
SenseHat_en.en_gyroscope = SenseHat_en.gyroscope | |
SenseHat_en.en_get_gyroscope_raw = SenseHat_en.get_gyroscope_raw | |
SenseHat_en.en_gyro_raw = SenseHat_en.gyro_raw | |
SenseHat_en.en_gyroscope_raw = SenseHat_en.gyroscope_raw | |
SenseHat_en.en_get_accelerometer = SenseHat_en.get_accelerometer | |
SenseHat_en.en_accel = SenseHat_en.accel | |
SenseHat_en.en_accelerometer = SenseHat_en.accelerometer | |
SenseHat_en.en_get_accelerometer_raw = SenseHat_en.get_accelerometer_raw | |
SenseHat_en.en_accel_raw = SenseHat_en.accel_raw | |
SenseHat_en.en_accelerometer_raw = SenseHat_en.accelerometer_raw |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An example of how Python class inheritance can be used to translate the method and parameter names of the Sense HAT API for non English speakers. In this example I have just prefixed the original English method and parameter names with
en_
to simulate a translated version of the name. Methods that contain parameters needing translation must be redefined in the parent class, whereas methods with no parameters and properties can be just copied outside of the class definition using the assignment operator.Example consuming code:
Rules to follow for translation:
_en
can be translated, all instances of the name must be changeden_
can be translated, all instances of the name must be changedEN_
can be translateden_
orEN_
should be left alone