Skip to content

Instantly share code, notes, and snippets.

Avatar

Rafal Woloszyn rwoloszyn

View GitHub Profile
View gist:e928a619b3f0e4fe26f11872e8586653
GPIO_InitTypeDef GPIO_I2CInitStructure;
/*Workaround p26 errata STM32F103*/
__HAL_I2C_DISABLE(&hi2c1);
//OD HIGHG
GPIO_I2CInitStructure.Pin = I2C_SCL_PIN | I2C_SDA_PIN;
GPIO_I2CInitStructure.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_I2CInitStructure.Pull = GPIO_PULLUP;
HAL_GPIO_Init(I2C_PORT, &GPIO_I2CInitStructure);
HAL_GPIO_WritePin(I2C_PORT, I2C_SCL_PIN, GPIO_PIN_SET);
HAL_GPIO_WritePin(I2C_PORT, I2C_SDA_PIN, GPIO_PIN_SET);
@rwoloszyn
rwoloszyn / SettingsTest.java
Created Oct 3, 2016
Reset singleton field during JUnit tests, roboelectric junit tests
View SettingsTest.java
@After
public void teaddown() {
setting.clear();
resetSingleton(ErgoSettings.class, "sInstance");
}
public static void resetSingleton(Class clazz, String fieldName) {
Field instance;
try {
@rwoloszyn
rwoloszyn / gist:8543d76561d522a45554a8d8a451149b
Created Mar 16, 2020
STM32F446 TIMER2 Ooutput COmpare PA3 1MHz square wave
View gist:8543d76561d522a45554a8d8a451149b
void HAL_AFE_Init1MHZ_Clock(void){
//RCC_AHB1PeriphClockCmd(HAL_DS_AFE_CLK1MHZ_PORT_GPIO_AHB_BIT, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_Init(HAL_DS_AFE_CLK1MHZ_PORT, (GPIO_InitTypeDef *) &HAL_DS_1MHz_CLK_GpioConfiguration);
GPIO_PinAFConfig(HAL_DS_AFE_CLK1MHZ_PORT, HAL_DS_AFE_CLK1MHZ_AF_PINSOURCE ,GPIO_AF_TIM2);
TIM_TimeBaseInitTypeDef TIM2_TimeBaseStructure;
TIM2_TimeBaseStructure.TIM_Period = 21;
@rwoloszyn
rwoloszyn / element_template.py
Created Aug 9, 2018
Django get element from m2m relation in django template
View element_template.py
{% with object.group_set.all|first as group %}
<li class="breadcrumb-item"><a href="{% url 'group_detail' group_id=view.kwargs.group_id %}">{{ group.name }}</a></li>
{% endwith %}
@rwoloszyn
rwoloszyn / forms.py
Created Jun 20, 2018
Custom label for ModelChoicesField in django framework
View forms.py
class SimpleProjectModelChoicesField(ModelChoiceField):
def label_from_instance(self, obj):
return '{name}'.format(name=obj.name)
class CourseForm(ModelForm):
project = SimpleProjectModelChoicesField(queryset=Project.objects.filter(is_active=True))
def __init__(self, *args, **kwargs):
self.request = kwargs.pop("request")
@rwoloszyn
rwoloszyn / daysleft.js
Created Jun 19, 2018
Calculate days left in js (React native)
View daysleft.js
_getLeftActivationDays = (finishDate) => {
var endDate = new Date(finishDate);
var today = new Date();
var oneDay = 24 * 60 * 60 * 1000;
return Math.round(Math.abs((today.getTime() - endDate.getTime())/ oneDay));
}
@rwoloszyn
rwoloszyn / serialloop.sh
Last active Jun 9, 2018
Bash serial (tty) looper
View serialloop.sh
#!/bin/bash
DEVICE=/dev/ttyUSB0
BAUDRATE=230400
echo "=======SETTINGS========="
echo "port: $DEVICE"
echo "spped: $BAUDRATE"
echo "========================"
@rwoloszyn
rwoloszyn / pylooper.py
Created Jun 9, 2018
Python serial sending character in loop
View pylooper.py
import serial
import time
def main():
ser = serial.Serial('/dev/ttyUSB0', 230400, timeout=1)
print(ser.name)
count = 0
while True:
@rwoloszyn
rwoloszyn / gist:8a6abcb121ad3049b84ea8bb3236a50b
Created Sep 22, 2017
Is this some kind of C struct alocation, Why not malloc ?
View gist:8a6abcb121ad3049b84ea8bb3236a50b
*ptr = '\n';
ptr++;
*ptr = '\n';
ptr++;
base = (PacketHdrBase*)ptr;
@rwoloszyn
rwoloszyn / controllers.js
Created Jun 27, 2016
Add checkbox as control in leaflet map
View controllers.js
// create the control
var autoZoomCheckbox = L.control({position: 'topleft'});
autoZoomCheckbox.onAdd = function (map) {
var div = L.DomUtil.create('div', 'command');
div.innerHTML = '<form><input id="command" type="checkbox"/>Automatic fit to bounds</form>';
return div;
};
autoZoomCheckbox.addTo(map);