Skip to content

Commit

Permalink
Merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
MatteoBattilana committed Dec 21, 2021
2 parents 76d9098 + fcdff10 commit c330092
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 25 deletions.
35 changes: 23 additions & 12 deletions peripherals/PersonalActuators/IRSensor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,24 @@
using System.IO;
using Antmicro.Renode.Logging;
using Antmicro.Renode.Peripherals.Miscellaneous;
using System.Collections.Generic;

namespace Antmicro.Renode.Peripherals
{
public class IRSensor : Button, IDisposable
{
private Stream _resource;
private bool _disposed;
private static readonly Random getrandom = new Random();
private bool _disposedValue;
private Queue<KeyValuePair<int, int>> queue;
private Semaphore semaphore;
private bool active;
Thread thread1;
public IRSensor()
{
semaphore = new Semaphore(0, 10);
active = true;
queue = new Queue<KeyValuePair<int, int>>();
thread1 = new Thread(TriggerThread);
thread1.Start();
}
Expand Down Expand Up @@ -44,20 +48,27 @@ protected virtual void Dispose(bool disposing)
}
}

public static int GetRandomNumber(int min, int max)
{
lock(getrandom) // synchronize
{
return getrandom.Next(min, max);
// Triggers random press in times between 700 and 3000 ms
private void TriggerThread(){
while(true){
semaphore.WaitOne();
if(active){
KeyValuePair<int, int> element = queue.Dequeue();
this.Log(LogLevel.Debug, "Run " + element.Key + " triggers every " + element.Value + " ms");
for(int i = 0; i < element.Key; i++){
Thread.Sleep(element.Value);
PressAndRelease();
}
}
}
}

// Triggers random press in times between 700 and 3000 ms
public void TriggerThread(){
while(true){
Thread.Sleep(GetRandomNumber(700, 3000));
if(active)
PressAndRelease();
public void TriggerSensorNTimes(int nTimes, int interval = 450)
{
if(active){
queue.Enqueue(new KeyValuePair<int, int>(nTimes, interval));
this.Log(LogLevel.Debug, "Set " + nTimes + " triggers every " + interval + " ms");
semaphore.Release();
}
}

Expand Down
18 changes: 10 additions & 8 deletions src/i2c_lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,21 @@ void lcd_send_two_string (char *str1, char * str2)
}

void lcd_set_text_downloading(){
lcd_clear();
lcd_go_home();
lcd_send_string("Downloading...");
lcd_go_home();
lcd_send_string("Downloading... ");
lcd_put_cur(1,0);
lcd_send_string(" ");
}

void lcd_set_number_people(int n_people){
char num_char[15];
sprintf(num_char, "%d", n_people);
char num_char[15];
sprintf(num_char, "%d", n_people);

lcd_go_home();
lcd_send_string("Number of people");
lcd_put_cur(1,0);
lcd_send_custom_char(1);
lcd_send_custom_char(1);
lcd_send_string(" ");
lcd_send_string(num_char);
lcd_send_string(num_char);
lcd_send_string(" ");
}
13 changes: 8 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
static void MX_RTC_Init(void);

static int c = 0;

int main(void) {
SystemInit();
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
Expand Down Expand Up @@ -76,12 +78,11 @@ int main(void) {
COMM_Init(&hcomm);
COMM_StartListen();

int i = 0;
while (1) {
lcd_set_number_people(i++);
lcd_set_number_people(c);
// updateNumber(&hrtc, &gTime, &gDate, 11);
// updateNumber(&hrtc, &gTime, &gDate, 12);
HAL_Delay(1000);
HAL_Delay(500);
}
}

Expand Down Expand Up @@ -198,11 +199,13 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
switch (GPIO_Pin) {
case IR_1_PIN:
// TODO: manage counter, increase
turn_on_red_led();
//turn_on_red_led();
c++;
break;
case IR_2_PIN:
// TODO: manage counter, decrease
turn_off_red_led();
// turn_off_red_led();
c--;
break;
}
}
Expand Down

0 comments on commit c330092

Please sign in to comment.